diff --git a/boot.php b/boot.php
index 1766e801ed..7dc99bbe88 100644
--- a/boot.php
+++ b/boot.php
@@ -97,19 +97,6 @@ define('SSL_POLICY_FULL', 1);
define('SSL_POLICY_SELFSIGN', 2);
/* @}*/
-/**
- * @name Register
- *
- * Registration policies
- * @{
- */
-define('REGISTER_CLOSED', 0);
-define('REGISTER_APPROVE', 1);
-define('REGISTER_OPEN', 2);
-/**
- * @}
-*/
-
/**
* @name CP
*
diff --git a/config/local-sample.config.php b/config/local-sample.config.php
index 996c27a66d..9b977ff53f 100644
--- a/config/local-sample.config.php
+++ b/config/local-sample.config.php
@@ -34,7 +34,7 @@ return [
'config' => [
'admin_email' => '',
'sitename' => 'Friendica Social Network',
- 'register_policy' => REGISTER_OPEN,
+ 'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [
diff --git a/config/settings.config.php b/config/settings.config.php
index 2893b3f201..6e3fa6a894 100644
--- a/config/settings.config.php
+++ b/config/settings.config.php
@@ -16,10 +16,11 @@ return [
'info' => '',
// register_policy (Constant)
- // Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED.
- // Be certain to create your own personal account before setting REGISTER_CLOSED.
- // REGISTER_APPROVE requires you set system.admin_email to the email address of an already registered person who can authorize and/or approve/deny the request.
- 'register_policy' => REGISTER_CLOSED,
+ // Your choices are OPEN, APPROVE, or CLOSED.
+ // Be certain to create your own personal account before setting CLOSED.
+ // APPROVE requires you set system.admin_email to the email address of an
+ // already registered person who can authorize and/or approve/deny the request.
+ 'register_policy' => \Friendica\Module\Register::CLOSED,
// register_text (String)
// Will be displayed prominently on the registration page.
diff --git a/include/api.php b/include/api.php
index 4452ebfb92..052d32b17b 100644
--- a/include/api.php
+++ b/include/api.php
@@ -3557,7 +3557,7 @@ function api_statusnet_config($type)
$server = $a->getHostName();
$logo = System::baseUrl() . '/images/friendica-64.png';
$email = Config::get('config', 'admin_email');
- $closed = intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 'true' : 'false';
+ $closed = intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 'true' : 'false';
$private = Config::get('system', 'block_public') ? 'true' : 'false';
$textlimit = (string) Config::get('config', 'api_import_size', Config::get('config', 'max_import_size', 200000));
$ssl = Config::get('system', 'have_ssl') ? 'true' : 'false';
diff --git a/mod/admin.php b/mod/admin.php
index e5dbf12f29..97d7a8bfd6 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -26,6 +26,7 @@ use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Register;
use Friendica\Model\User;
+use Friendica\Module;
use Friendica\Module\Login;
use Friendica\Module\Tos;
use Friendica\Util\Arrays;
@@ -1509,9 +1510,9 @@ function admin_page_site(App $a)
/* Register policy */
$register_choices = [
- REGISTER_CLOSED => L10n::t("Closed"),
- REGISTER_APPROVE => L10n::t("Requires approval"),
- REGISTER_OPEN => L10n::t("Open")
+ Module\Register::CLOSED => L10n::t("Closed"),
+ Module\Register::APPROVE => L10n::t("Requires approval"),
+ Module\Register::OPEN => L10n::t("Open")
];
$ssl_choices = [
diff --git a/mod/bookmarklet.php b/mod/bookmarklet.php
index be3e1fd336..1c4d191c4f 100644
--- a/mod/bookmarklet.php
+++ b/mod/bookmarklet.php
@@ -20,7 +20,7 @@ function bookmarklet_content(App $a)
{
if (!local_user()) {
$o = '
' . L10n::t('Login') . '
';
- $o .= Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? false : true);
+ $o .= Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? false : true);
return $o;
}
diff --git a/mod/friendica.php b/mod/friendica.php
index 686e2e804b..d10deb2e88 100644
--- a/mod/friendica.php
+++ b/mod/friendica.php
@@ -10,16 +10,22 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\System;
use Friendica\Database\DBA;
+use Friendica\Module\Register;
function friendica_init(App $a)
{
if (!empty($a->argv[1]) && ($a->argv[1] == "json")) {
- $register_policies = ['REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'];
+ $register_policies = [
+ Register::CLOSED => 'REGISTER_CLOSED',
+ Register::APPROVE => 'REGISTER_APPROVE',
+ Register::OPEN => 'REGISTER_OPEN'
+ ];
- $register_policy = $register_policies[intval(Config::get('config', 'register_policy'))];
-
- if ($register_policy == 'REGISTER_OPEN' && Config::get('config', 'invitation_only')) {
+ $register_policy_int = intval(Config::get('config', 'register_policy'));
+ if ($register_policy_int !== Register::CLOSED && Config::get('config', 'invitation_only')) {
$register_policy = 'REGISTER_INVITATION';
+ } else {
+ $register_policy = $register_policies[$register_policy_int];
}
$sql_extra = '';
diff --git a/mod/home.php b/mod/home.php
index 34f6d43683..9f18101202 100644
--- a/mod/home.php
+++ b/mod/home.php
@@ -48,7 +48,7 @@ function home_content(App $a) {
}
}
- $login = Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
+ $login = Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1);
$content = '';
Hook::callAll("home_content",$content);
diff --git a/mod/invite.php b/mod/invite.php
index 3b1667a79a..e8901d0710 100644
--- a/mod/invite.php
+++ b/mod/invite.php
@@ -13,6 +13,7 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Renderer;
use Friendica\Core\System;
+use Friendica\Module\Register;
use Friendica\Protocol\Email;
use Friendica\Util\Strings;
@@ -125,14 +126,14 @@ function invite_content(App $a) {
$dirloc = Config::get('system', 'directory');
if (strlen($dirloc)) {
- if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
+ if (intval(Config::get('config', 'register_policy')) === Register::CLOSED) {
$linktxt = L10n::t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.', $dirloc . '/servers');
} else {
$linktxt = L10n::t('To accept this invitation, please visit and register at %s or any other public Friendica website.', System::baseUrl())
. "\r\n" . "\r\n" . L10n::t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.', $dirloc . '/servers');
}
} else { // there is no global directory URL defined
- if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
+ if (intval(Config::get('config', 'register_policy')) === Register::CLOSED) {
$o = L10n::t('Our apologies. This system is not currently configured to connect with other public sites or invite members.');
return $o;
} else {
diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php
index 5c25b6e551..39f430f92f 100644
--- a/mod/nodeinfo.php
+++ b/mod/nodeinfo.php
@@ -59,7 +59,7 @@ function nodeinfo_init(App $a) {
$nodeinfo['usage'] = [];
- $nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED;
+ $nodeinfo['openRegistrations'] = intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED;
$nodeinfo['metadata'] = ['nodeName' => Config::get('config', 'sitename')];
diff --git a/mod/openid.php b/mod/openid.php
index d20258fa96..7300c686b4 100644
--- a/mod/openid.php
+++ b/mod/openid.php
@@ -63,7 +63,7 @@ function openid_content(App $a) {
// Successful OpenID login - but we can't match it to an existing account.
// New registration?
- if (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED) {
+ if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED) {
notice(L10n::t('Account not found and OpenID registration is not permitted on this site.') . EOL);
$a->internalRedirect();
}
diff --git a/mod/ping.php b/mod/ping.php
index 8b50b78c83..b89cb9246c 100644
--- a/mod/ping.php
+++ b/mod/ping.php
@@ -188,7 +188,7 @@ function ping_init(App $a)
);
$mail_count = count($mails);
- if (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE && is_site_admin()) {
+ if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::APPROVE && is_site_admin()) {
$regs = Friendica\Model\Register::getPending();
if (DBA::isResult($regs)) {
diff --git a/mod/register.php b/mod/register.php
deleted file mode 100644
index e69315a33a..0000000000
--- a/mod/register.php
+++ /dev/null
@@ -1,286 +0,0 @@
- $_POST];
- Hook::callAll('register_post', $arr);
-
- $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
- if ($max_dailies) {
- $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
- if ($r && $r[0]['total'] >= $max_dailies) {
- return;
- }
- }
-
- switch (Config::get('config', 'register_policy')) {
- case REGISTER_OPEN:
- $blocked = 0;
- $verified = 1;
- break;
-
- case REGISTER_APPROVE:
- $blocked = 1;
- $verified = 0;
- break;
-
- default:
- case REGISTER_CLOSED:
- if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
- notice(L10n::t('Permission denied.') . EOL);
- return;
- }
- $blocked = 1;
- $verified = 0;
- break;
- }
-
- $netpublish = !empty($_POST['profile_publish_reg']);
-
- $arr = $_POST;
-
- $arr['blocked'] = $blocked;
- $arr['verified'] = $verified;
- $arr['language'] = L10n::detectLanguage();
-
- try {
- $result = Model\User::create($arr);
- } catch (Exception $e) {
- notice($e->getMessage());
- return;
- }
-
- $user = $result['user'];
-
- if ($netpublish && intval(Config::get('config', 'register_policy')) !== REGISTER_APPROVE) {
- $url = $a->getBaseUrl() . '/profile/' . $user['nickname'];
- Worker::add(PRIORITY_LOW, "Directory", $url);
- }
-
- $using_invites = Config::get('system', 'invitation_only');
- $num_invites = Config::get('system', 'number_invites');
- $invite_id = (!empty($_POST['invite_id']) ? Strings::escapeTags(trim($_POST['invite_id'])) : '');
-
- if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN) {
- if ($using_invites && $invite_id) {
- Model\Register::deleteByHash($invite_id);
- PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
- }
-
- // Only send a password mail when the password wasn't manually provided
- if (empty($_POST['password1']) || empty($_POST['confirm'])) {
- $res = Model\User::sendRegisterOpenEmail(
- $user,
- Config::get('config', 'sitename'),
- $a->getBaseUrl(),
- $result['password']
- );
-
- if ($res) {
- info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
- $a->internalRedirect();
- } else {
- notice(
- L10n::t('Failed to send email message. Here your accout details:
login: %s
password: %s
You can change your password after login.',
- $user['email'],
- $result['password'])
- . EOL
- );
- }
- } else {
- info(L10n::t('Registration successful.') . EOL);
- $a->internalRedirect();
- }
- } elseif (intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE) {
- if (!strlen(Config::get('config', 'admin_email'))) {
- notice(L10n::t('Your registration can not be processed.') . EOL);
- $a->internalRedirect();
- }
-
- Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
-
- // invite system
- if ($using_invites && $invite_id) {
- Model\Register::deleteByHash($invite_id);
- PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
- }
-
- // send email to admins
- $admin_mail_list = "'" . implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email'))))) . "'";
- $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
- $admin_mail_list
- );
-
- // send notification to admins
- foreach ($adminlist as $admin) {
- notification([
- 'type' => NOTIFY_SYSTEM,
- 'event' => 'SYSTEM_REGISTER_REQUEST',
- 'source_name' => $user['username'],
- 'source_mail' => $user['email'],
- 'source_nick' => $user['nickname'],
- 'source_link' => $a->getBaseUrl() . "/admin/users/",
- 'link' => $a->getBaseUrl() . "/admin/users/",
- 'source_photo' => $a->getBaseUrl() . "/photo/avatar/" . $user['uid'] . ".jpg",
- 'to_email' => $admin['email'],
- 'uid' => $admin['uid'],
- 'language' => $admin['language'] ? $admin['language'] : 'en',
- 'show_in_notification_page' => false
- ]);
- }
- // send notification to the user, that the registration is pending
- Model\User::sendRegisterPendingEmail(
- $user,
- Config::get('config', 'sitename'),
- $a->getBaseURL(),
- $result['password']
- );
-
- info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
- $a->internalRedirect();
- }
-
- return;
-}
-
-function register_content(App $a)
-{
- // logged in users can register others (people/pages/groups)
- // even with closed registrations, unless specifically prohibited by site policy.
- // 'block_extended_register' blocks all registrations, period.
- $block = Config::get('system', 'block_extended_register');
-
- if (local_user() && ($block)) {
- notice("Permission denied." . EOL);
- return;
- }
-
- if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED)) {
- notice("Permission denied." . EOL);
- return;
- }
-
- $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
- if ($max_dailies) {
- $r = q("select count(*) as total from user where register_date > UTC_TIMESTAMP - INTERVAL 1 day");
- if ($r && $r[0]['total'] >= $max_dailies) {
- Logger::log('max daily registrations exceeded.');
- notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
- return;
- }
- }
-
- if (!empty($_SESSION['theme'])) {
- unset($_SESSION['theme']);
- }
- if (!empty($_SESSION['mobile-theme'])) {
- unset($_SESSION['mobile-theme']);
- }
-
-
- $username = defaults($_REQUEST, 'username' , '');
- $email = defaults($_REQUEST, 'email' , '');
- $openid_url = defaults($_REQUEST, 'openid_url', '');
- $nickname = defaults($_REQUEST, 'nickname' , '');
- $photo = defaults($_REQUEST, 'photo' , '');
- $invite_id = defaults($_REQUEST, 'invite_id' , '');
-
- $noid = Config::get('system', 'no_openid');
-
- if ($noid) {
- $fillwith = '';
- $fillext = '';
- $oidlabel = '';
- } else {
- $fillwith = L10n::t("You may \x28optionally\x29 fill in this form via OpenID by supplying your OpenID and clicking 'Register'.");
- $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
- $oidlabel = L10n::t("Your OpenID \x28optional\x29: ");
- }
-
- if (Config::get('system', 'publish_all')) {
- $profile_publish = '';
- } else {
- $publish_tpl = Renderer::getMarkupTemplate("profile_publish.tpl");
- $profile_publish = Renderer::replaceMacros($publish_tpl, [
- '$instance' => 'reg',
- '$pubdesc' => L10n::t('Include your profile in member directory?'),
- '$yes_selected' => '',
- '$no_selected' => ' checked="checked"',
- '$str_yes' => L10n::t('Yes'),
- '$str_no' => L10n::t('No'),
- ]);
- }
-
- $r = q("SELECT COUNT(*) AS `contacts` FROM `contact`");
- $passwords = !$r[0]["contacts"];
-
- $tpl = Renderer::getMarkupTemplate("register.tpl");
-
- $arr = ['template' => $tpl];
-
- Hook::callAll('register_form', $arr);
-
- $tpl = $arr['template'];
-
- $tos = new Tos();
-
- $o = Renderer::replaceMacros($tpl, [
- '$invitations' => Config::get('system', 'invitation_only'),
- '$permonly' => intval(Config::get('config', 'register_policy')) === REGISTER_APPROVE,
- '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
- '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
- '$invite_label' => L10n::t('Your invitation code: '),
- '$invite_id' => $invite_id,
- '$regtitle' => L10n::t('Registration'),
- '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
- '$fillwith' => $fillwith,
- '$fillext' => $fillext,
- '$oidlabel' => $oidlabel,
- '$openid' => $openid_url,
- '$namelabel' => L10n::t('Your Full Name ' . "\x28" . 'e.g. Joe Smith, real or real-looking' . "\x29" . ': '),
- '$addrlabel' => L10n::t("Your Email Address: \x28Initial information will be send there, so this has to be an existing address.\x29"),
- '$passwords' => $passwords,
- '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
- '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
- '$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be \'nickname@%s\'.', $a->getHostName()),
- '$nicklabel' => L10n::t('Choose a nickname: '),
- '$photo' => $photo,
- '$publish' => $profile_publish,
- '$regbutt' => L10n::t('Register'),
- '$username' => $username,
- '$email' => $email,
- '$nickname' => $nickname,
- '$sitename' => $a->getHostName(),
- '$importh' => L10n::t('Import'),
- '$importt' => L10n::t('Import your profile to this friendica instance'),
- '$showtoslink' => Config::get('system', 'tosdisplay'),
- '$tostext' => L10n::t('Terms of Service'),
- '$showprivstatement' => Config::get('system', 'tosprivstatement'),
- '$privstatement' => $tos->privacy_complete,
- '$baseurl' => System::baseurl(),
- '$form_security_token' => BaseModule::getFormSecurityToken("register"),
- '$explicit_content' => Config::get('system', 'explicit_content', false),
- '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')
- ]);
- return $o;
-}
diff --git a/mod/regmod.php b/mod/regmod.php
index e03f28e85b..6cf4c8836c 100644
--- a/mod/regmod.php
+++ b/mod/regmod.php
@@ -82,7 +82,7 @@ function regmod_content(App $a)
{
if (!local_user()) {
info(L10n::t('Please login.') . EOL);
- return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
+ return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1);
}
if (!is_site_admin() || !empty($_SESSION['submanage'])) {
diff --git a/mod/statistics_json.php b/mod/statistics_json.php
index 833b2e9a8e..a8d3c8a5f1 100644
--- a/mod/statistics_json.php
+++ b/mod/statistics_json.php
@@ -16,11 +16,15 @@ function statistics_json_init(App $a) {
System::httpExit(404);
}
+ $registration_open =
+ intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED
+ && ! Config::get('config', 'invitation_only');
+
$statistics = [
"name" => Config::get('config', 'sitename'),
"network" => FRIENDICA_PLATFORM,
"version" => FRIENDICA_VERSION . "-" . DB_UPDATE_VERSION,
- "registrations_open" => intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED,
+ "registrations_open" => $registration_open,
"total_users" => Config::get('nodeinfo', 'total_users'),
"active_users_halfyear" => Config::get('nodeinfo', 'active_users_halfyear'),
"active_users_monthly" => Config::get('nodeinfo', 'active_users_monthly'),
diff --git a/mod/uimport.php b/mod/uimport.php
index dfeab8a2f6..22a3161559 100644
--- a/mod/uimport.php
+++ b/mod/uimport.php
@@ -13,7 +13,7 @@ use Friendica\Core\Renderer;
function uimport_post(App $a)
{
- if ((Config::get('config', 'register_policy') != REGISTER_OPEN) && !is_site_admin()) {
+ if ((Config::get('config', 'register_policy') != \Friendica\Module\Register::OPEN) && !is_site_admin()) {
notice(L10n::t('Permission denied.') . EOL);
return;
}
@@ -26,7 +26,7 @@ function uimport_post(App $a)
function uimport_content(App $a)
{
- if ((Config::get('config', 'register_policy') != REGISTER_OPEN) && !is_site_admin()) {
+ if ((Config::get('config', 'register_policy') != \Friendica\Module\Register::OPEN) && !is_site_admin()) {
notice(L10n::t('User imports on closed servers can only be done by an administrator.') . EOL);
return;
}
diff --git a/mods/local.config.vagrant.php b/mods/local.config.vagrant.php
index 099500200d..a9b95d02d7 100644
--- a/mods/local.config.vagrant.php
+++ b/mods/local.config.vagrant.php
@@ -31,7 +31,7 @@ return [
'config' => [
'admin_email' => 'admin@friendica.local',
'sitename' => 'Friendica Social Network',
- 'register_policy' => REGISTER_OPEN,
+ 'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [
diff --git a/src/Content/Nav.php b/src/Content/Nav.php
index b72f4dc043..1eae2a3e3b 100644
--- a/src/Content/Nav.php
+++ b/src/Content/Nav.php
@@ -180,7 +180,7 @@ class Nav
$nav['home'] = [$homelink, L10n::t('Home'), '', L10n::t('Home Page')];
}
- if (intval(Config::get('config', 'register_policy')) === REGISTER_OPEN && !local_user() && !remote_user()) {
+ if (intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::OPEN && !local_user() && !remote_user()) {
$nav['register'] = ['register', L10n::t('Register'), '', L10n::t('Create an account')];
}
diff --git a/src/Module/Login.php b/src/Module/Login.php
index 96b0c428fa..b0897f2d76 100644
--- a/src/Module/Login.php
+++ b/src/Module/Login.php
@@ -43,7 +43,7 @@ class Login extends BaseModule
$a->internalRedirect();
}
- return self::form(defaults($_SESSION, 'return_path', null), intval(Config::get('config', 'register_policy')) !== REGISTER_CLOSED);
+ return self::form(defaults($_SESSION, 'return_path', null), intval(Config::get('config', 'register_policy')) !== \Friendica\Module\Register::CLOSED);
}
public static function post()
diff --git a/src/Module/Register.php b/src/Module/Register.php
new file mode 100644
index 0000000000..6744a0a5f3
--- /dev/null
+++ b/src/Module/Register.php
@@ -0,0 +1,311 @@
+
+ */
+abstract class Register extends BaseModule
+{
+ const CLOSED = 0;
+ const APPROVE = 1;
+ const OPEN = 2;
+
+ /**
+ * @brief Module GET method to display any content
+ *
+ * Extend this method if the module is supposed to return any display
+ * through a GET request. It can be an HTML page through templating or a
+ * XML feed or a JSON output.
+ *
+ * @return string
+ */
+ public static function content()
+ {
+ // logged in users can register others (people/pages/groups)
+ // even with closed registrations, unless specifically prohibited by site policy.
+ // 'block_extended_register' blocks all registrations, period.
+ $block = Config::get('system', 'block_extended_register');
+
+ if (local_user() && ($block)) {
+ notice('Permission denied.' . EOL);
+ return '';
+ }
+
+ if ((!local_user()) && (intval(Config::get('config', 'register_policy')) === self::CLOSED)) {
+ notice('Permission denied.' . EOL);
+ return '';
+ }
+
+ $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
+ if ($max_dailies) {
+ $count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']);
+ if ($count >= $max_dailies) {
+ Logger::log('max daily registrations exceeded.');
+ notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.') . EOL);
+ return '';
+ }
+ }
+
+ if (!empty($_SESSION['theme'])) {
+ unset($_SESSION['theme']);
+ }
+ if (!empty($_SESSION['mobile-theme'])) {
+ unset($_SESSION['mobile-theme']);
+ }
+
+ $username = defaults($_REQUEST, 'username' , '');
+ $email = defaults($_REQUEST, 'email' , '');
+ $openid_url = defaults($_REQUEST, 'openid_url', '');
+ $nickname = defaults($_REQUEST, 'nickname' , '');
+ $photo = defaults($_REQUEST, 'photo' , '');
+ $invite_id = defaults($_REQUEST, 'invite_id' , '');
+
+ if (Config::get('system', 'no_openid')) {
+ $fillwith = '';
+ $fillext = '';
+ $oidlabel = '';
+ } else {
+ $fillwith = L10n::t('You may (optionally) fill in this form via OpenID by supplying your OpenID and clicking "Register".');
+ $fillext = L10n::t('If you are not familiar with OpenID, please leave that field blank and fill in the rest of the items.');
+ $oidlabel = L10n::t('Your OpenID (optional): ');
+ }
+
+ if (Config::get('system', 'publish_all')) {
+ $profile_publish = '';
+ } else {
+ $publish_tpl = Renderer::getMarkupTemplate('profile_publish.tpl');
+ $profile_publish = Renderer::replaceMacros($publish_tpl, [
+ '$instance' => 'reg',
+ '$pubdesc' => L10n::t('Include your profile in member directory?'),
+ '$yes_selected' => '',
+ '$no_selected' => ' checked="checked"',
+ '$str_yes' => L10n::t('Yes'),
+ '$str_no' => L10n::t('No'),
+ ]);
+ }
+
+ $ask_password = ! DBA::count('contact');
+
+ $tpl = Renderer::getMarkupTemplate('register.tpl');
+
+ $arr = ['template' => $tpl];
+
+ Hook::callAll('register_form', $arr);
+
+ $tpl = $arr['template'];
+
+ $tos = new Tos();
+
+ $o = Renderer::replaceMacros($tpl, [
+ '$invitations' => Config::get('system', 'invitation_only'),
+ '$permonly' => intval(Config::get('config', 'register_policy')) === self::APPROVE,
+ '$permonlybox' => ['permonlybox', L10n::t('Note for the admin'), '', L10n::t('Leave a message for the admin, why you want to join this node')],
+ '$invite_desc' => L10n::t('Membership on this site is by invitation only.'),
+ '$invite_label' => L10n::t('Your invitation code: '),
+ '$invite_id' => $invite_id,
+ '$regtitle' => L10n::t('Registration'),
+ '$registertext' => BBCode::convert(Config::get('config', 'register_text', '')),
+ '$fillwith' => $fillwith,
+ '$fillext' => $fillext,
+ '$oidlabel' => $oidlabel,
+ '$openid' => $openid_url,
+ '$namelabel' => L10n::t('Your Full Name (e.g. Joe Smith, real or real-looking): '),
+ '$addrlabel' => L10n::t('Your Email Address: (Initial information will be send there, so this has to be an existing address.)'),
+ '$ask_password' => $ask_password,
+ '$password1' => ['password1', L10n::t('New Password:'), '', L10n::t('Leave empty for an auto generated password.')],
+ '$password2' => ['confirm', L10n::t('Confirm:'), '', ''],
+ '$nickdesc' => L10n::t('Choose a profile nickname. This must begin with a text character. Your profile address on this site will then be "nickname@%s".', self::getApp()->getHostName()),
+ '$nicklabel' => L10n::t('Choose a nickname: '),
+ '$photo' => $photo,
+ '$publish' => $profile_publish,
+ '$regbutt' => L10n::t('Register'),
+ '$username' => $username,
+ '$email' => $email,
+ '$nickname' => $nickname,
+ '$sitename' => self::getApp()->getHostName(),
+ '$importh' => L10n::t('Import'),
+ '$importt' => L10n::t('Import your profile to this friendica instance'),
+ '$showtoslink' => Config::get('system', 'tosdisplay'),
+ '$tostext' => L10n::t('Terms of Service'),
+ '$showprivstatement' => Config::get('system', 'tosprivstatement'),
+ '$privstatement'=> $tos->privacy_complete,
+ '$baseurl' => System::baseurl(),
+ '$form_security_token' => BaseModule::getFormSecurityToken('register'),
+ '$explicit_content' => Config::get('system', 'explicit_content', false),
+ '$explicit_content_note' => L10n::t('Note: This node explicitly contains adult content')
+ ]);
+
+ return $o;
+ }
+
+ /**
+ * @brief Module POST method to process submitted data
+ *
+ * Extend this method if the module is supposed to process POST requests.
+ * Doesn't display any content
+ */
+ public static function post()
+ {
+ BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
+
+ $a = self::getApp();
+
+ $arr = ['post' => $_POST];
+ Hook::callAll('register_post', $arr);
+
+ $max_dailies = intval(Config::get('system', 'max_daily_registrations'));
+ if ($max_dailies) {
+ $count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']);
+ if ($count >= $max_dailies) {
+ return;
+ }
+ }
+
+ switch (Config::get('config', 'register_policy')) {
+ case self::OPEN:
+ $blocked = 0;
+ $verified = 1;
+ break;
+
+ case self::APPROVE:
+ $blocked = 1;
+ $verified = 0;
+ break;
+
+ case self::CLOSED:
+ default:
+ if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
+ \notice(L10n::t('Permission denied.') . EOL);
+ return;
+ }
+ $blocked = 1;
+ $verified = 0;
+ break;
+ }
+
+ $netpublish = !empty($_POST['profile_publish_reg']);
+
+ $arr = $_POST;
+
+ $arr['blocked'] = $blocked;
+ $arr['verified'] = $verified;
+ $arr['language'] = L10n::detectLanguage();
+
+ try {
+ $result = Model\User::create($arr);
+ } catch (\Exception $e) {
+ \notice($e->getMessage());
+ return;
+ }
+
+ $user = $result['user'];
+
+ if ($netpublish && intval(Config::get('config', 'register_policy')) !== self::APPROVE) {
+ $url = $a->getBaseUrl() . '/profile/' . $user['nickname'];
+ Worker::add(PRIORITY_LOW, 'Directory', $url);
+ }
+
+ $using_invites = Config::get('system', 'invitation_only');
+ $num_invites = Config::get('system', 'number_invites');
+ $invite_id = (!empty($_POST['invite_id']) ? Strings::escapeTags(trim($_POST['invite_id'])) : '');
+
+ if (intval(Config::get('config', 'register_policy')) === self::OPEN) {
+ if ($using_invites && $invite_id) {
+ Model\Register::deleteByHash($invite_id);
+ PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
+ }
+
+ // Only send a password mail when the password wasn't manually provided
+ if (empty($_POST['password1']) || empty($_POST['confirm'])) {
+ $res = Model\User::sendRegisterOpenEmail(
+ $user,
+ Config::get('config', 'sitename'),
+ $a->getBaseUrl(),
+ $result['password']
+ );
+
+ if ($res) {
+ \info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL);
+ $a->internalRedirect();
+ } else {
+ \notice(
+ L10n::t('Failed to send email message. Here your accout details:
login: %s
password: %s
You can change your password after login.',
+ $user['email'],
+ $result['password'])
+ . EOL
+ );
+ }
+ } else {
+ \info(L10n::t('Registration successful.') . EOL);
+ $a->internalRedirect();
+ }
+ } elseif (intval(Config::get('config', 'register_policy')) === self::APPROVE) {
+ if (!strlen(Config::get('config', 'admin_email'))) {
+ \notice(L10n::t('Your registration can not be processed.') . EOL);
+ $a->internalRedirect();
+ }
+
+ Model\Register::createForApproval($user['uid'], Config::get('system', 'language'), $_POST['permonlybox']);
+
+ // invite system
+ if ($using_invites && $invite_id) {
+ Model\Register::deleteByHash($invite_id);
+ PConfig::set($user['uid'], 'system', 'invites_remaining', $num_invites);
+ }
+
+ // send email to admins
+ $admins_stmt = DBA::select(
+ 'user',
+ ['uid', 'language', 'email'],
+ ['email' => explode(',', str_replace(' ', '', Config::get('config', 'admin_email')))]
+ );
+
+ // send notification to admins
+ while ($admin = DBA::fetch($admins_stmt)) {
+ \notification([
+ 'type' => NOTIFY_SYSTEM,
+ 'event' => 'SYSTEM_REGISTER_REQUEST',
+ 'source_name' => $user['username'],
+ 'source_mail' => $user['email'],
+ 'source_nick' => $user['nickname'],
+ 'source_link' => $a->getBaseUrl() . '/admin/users/',
+ 'link' => $a->getBaseUrl() . '/admin/users/',
+ 'source_photo' => $a->getBaseUrl() . '/photo/avatar/' . $user['uid'] . '.jpg',
+ 'to_email' => $admin['email'],
+ 'uid' => $admin['uid'],
+ 'language' => defaults($admin, 'language', 'en'),
+ 'show_in_notification_page' => false
+ ]);
+ }
+ DBA::close($admins_stmt);
+
+ // send notification to the user, that the registration is pending
+ Model\User::sendRegisterPendingEmail(
+ $user,
+ Config::get('config', 'sitename'),
+ $a->getBaseURL(),
+ $result['password']
+ );
+
+ \info(L10n::t('Your registration is pending approval by the site owner.') . EOL);
+ $a->internalRedirect();
+ }
+
+ return;
+ }
+}
diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php
index 4b8b6fff63..0bc17d3dce 100644
--- a/src/Protocol/PortableContact.php
+++ b/src/Protocol/PortableContact.php
@@ -20,6 +20,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\Model\GContact;
use Friendica\Model\Profile;
+use Friendica\Module\Register;
use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
@@ -705,10 +706,10 @@ class PortableContact
$server = [];
- $server['register_policy'] = REGISTER_CLOSED;
+ $server['register_policy'] = Register::CLOSED;
if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
- $server['register_policy'] = REGISTER_OPEN;
+ $server['register_policy'] = Register::OPEN;
}
if (is_array($nodeinfo['software'])) {
@@ -789,10 +790,10 @@ class PortableContact
$server = [];
- $server['register_policy'] = REGISTER_CLOSED;
+ $server['register_policy'] = Register::CLOSED;
if (is_bool($nodeinfo['openRegistrations']) && $nodeinfo['openRegistrations']) {
- $server['register_policy'] = REGISTER_OPEN;
+ $server['register_policy'] = Register::OPEN;
}
if (is_array($nodeinfo['software'])) {
@@ -1192,16 +1193,16 @@ class PortableContact
if (!empty($data['register_policy'])) {
switch ($data['register_policy']) {
case "REGISTER_OPEN":
- $register_policy = REGISTER_OPEN;
+ $register_policy = Register::OPEN;
break;
case "REGISTER_APPROVE":
- $register_policy = REGISTER_APPROVE;
+ $register_policy = Register::APPROVE;
break;
case "REGISTER_CLOSED":
default:
- $register_policy = REGISTER_CLOSED;
+ $register_policy = Register::CLOSED;
break;
}
}
@@ -1267,11 +1268,11 @@ class PortableContact
}
if (!$closed && !$private and $inviteonly) {
- $register_policy = REGISTER_APPROVE;
+ $register_policy = Register::APPROVE;
} elseif (!$closed && !$private) {
- $register_policy = REGISTER_OPEN;
+ $register_policy = Register::OPEN;
} else {
- $register_policy = REGISTER_CLOSED;
+ $register_policy = Register::CLOSED;
}
}
}
@@ -1305,9 +1306,9 @@ class PortableContact
}
if (!empty($data['registrations_open']) && $data['registrations_open']) {
- $register_policy = REGISTER_OPEN;
+ $register_policy = Register::OPEN;
} else {
- $register_policy = REGISTER_CLOSED;
+ $register_policy = Register::CLOSED;
}
}
}
@@ -1367,13 +1368,27 @@ class PortableContact
}
$info = defaults($data, 'info', '');
- $register_policy = defaults($data, 'register_policy', REGISTER_CLOSED);
- if (in_array($register_policy, ['REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN'])) {
- $register_policy = constant($register_policy);
- } else {
- Logger::log("Register policy '$register_policy' from $server_url is invalid.");
- $register_policy = REGISTER_CLOSED; // set a default value
+
+ $register_policy = defaults($data, 'register_policy', 'REGISTER_CLOSED');
+ switch ($register_policy) {
+ case 'REGISTER_OPEN':
+ $register_policy = Register::OPEN;
+ break;
+
+ case 'REGISTER_APPROVE':
+ $register_policy = Register::APPROVE;
+ break;
+
+ default:
+ Logger::log("Register policy '$register_policy' from $server_url is invalid.");
+ // Defaulting to closed
+
+ case 'REGISTER_CLOSED':
+ case 'REGISTER_INVITATION':
+ $register_policy = Register::CLOSED;
+ break;
}
+
$platform = defaults($data, 'platform', '');
}
}
diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php
index 813277ebbd..361608d375 100644
--- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php
+++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php
@@ -209,7 +209,7 @@ return [
'config' => [
'admin_email' => '',
'sitename' => 'Friendica Social Network',
- 'register_policy' => REGISTER_OPEN,
+ 'register_policy' => \Friendica\Module\Register::OPEN,
'register_text' => '',
],
'system' => [
diff --git a/view/templates/local.config.tpl b/view/templates/local.config.tpl
index 54ff279f3c..c4c4afba4d 100644
--- a/view/templates/local.config.tpl
+++ b/view/templates/local.config.tpl
@@ -24,7 +24,7 @@ return [
'php_path' => '{{$phpath}}',
'admin_email' => '{{$adminmail}}',
'sitename' => 'Friendica Social Network',
- 'register_policy' => REGISTER_OPEN,
+ 'register_policy' => \Friendica\Module\Register::OPEN,
'max_import_size' => 200000,
],
'system' => [
diff --git a/view/templates/register.tpl b/view/templates/register.tpl
index 4da865d4cf..456fadaab8 100644
--- a/view/templates/register.tpl
+++ b/view/templates/register.tpl
@@ -41,7 +41,7 @@
-{{if $passwords}}
+{{if $ask_password}}
{{include file="field_password.tpl" field=$password1}}
{{include file="field_password.tpl" field=$password2}}
{{/if}}
diff --git a/view/theme/frio/templates/register.tpl b/view/theme/frio/templates/register.tpl
index feb8035fa3..4819c5ee81 100644
--- a/view/theme/frio/templates/register.tpl
+++ b/view/theme/frio/templates/register.tpl
@@ -42,7 +42,7 @@
- {{if $passwords}}
+ {{if $ask_password}}
{{include file="field_password.tpl" field=$password1}}
{{include file="field_password.tpl" field=$password2}}
{{/if}}