]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #6336 from MrPetovan/bug/6334-get-app-namespace
authorMichael Vogel <icarus@dabo.de>
Wed, 23 Jan 2019 06:40:58 +0000 (07:40 +0100)
committerGitHub <noreply@github.com>
Wed, 23 Jan 2019 06:40:58 +0000 (07:40 +0100)
Move mod/register to Module\Register

25 files changed:
boot.php
config/local-sample.config.php
config/settings.config.php
include/api.php
mod/admin.php
mod/bookmarklet.php
mod/friendica.php
mod/home.php
mod/invite.php
mod/nodeinfo.php
mod/openid.php
mod/ping.php
mod/register.php [deleted file]
mod/regmod.php
mod/statistics_json.php
mod/uimport.php
mods/local.config.vagrant.php
src/Content/Nav.php
src/Module/Login.php
src/Module/Register.php [new file with mode: 0644]
src/Protocol/PortableContact.php
tests/src/Core/Console/AutomaticInstallationConsoleTest.php
view/templates/local.config.tpl
view/templates/register.tpl
view/theme/frio/templates/register.tpl

index 1766e801edfcf8640baab7a72ea1d204aca7eff1..7dc99bbe88c3621e72babf21a08823088ad08694 100644 (file)
--- 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
  *
index 996c27a66d1558e417d17c8dae93a7b5df904f9f..9b977ff53f4a49b721d9b77f36fb5578b12910be 100644 (file)
@@ -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' => [
index 2893b3f2016ca06a0dab188eb5e976706458dc67..6e3fa6a894ce4fdd93b343d6bef5a4382e2ab571 100644 (file)
@@ -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.
index 4452ebfb92eddfacc58e28a738d300785bc7668a..052d32b17b1f8d788db0d7c65559febeb6cd3aa1 100644 (file)
@@ -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';
index e5dbf12f2915bd6e24e63ad6b580d0acc544b68b..97d7a8bfd6a6ed79cc8745c67a2e2a8ac5dd0a2c 100644 (file)
@@ -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 = [
index be3e1fd33670e1a5638b3f42a55a6fe9fd9ea2c8..1c4d191c4f8d1fa21b89e4d6194cb915be585dc9 100644 (file)
@@ -20,7 +20,7 @@ function bookmarklet_content(App $a)
 {
        if (!local_user()) {
                $o = '<h2>' . L10n::t('Login') . '</h2>';
-               $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;
        }
 
index 686e2e804bdcda816002e96043b4de4c5a0c828b..d10deb2e88452ce94cbdf4704b35f98053a789ea 100644 (file)
@@ -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_policy = $register_policies[intval(Config::get('config', 'register_policy'))];
+               $register_policies = [
+                       Register::CLOSED  => 'REGISTER_CLOSED',
+                       Register::APPROVE => 'REGISTER_APPROVE',
+                       Register::OPEN    => 'REGISTER_OPEN'
+               ];
 
-               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 = '';
index 34f6d436834eac34b5071b64c121e7be25309293..9f1810120258254661e2bf4045cb7ed54c2ac585 100644 (file)
@@ -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);
index 3b1667a79aeb9e898dd80f9222ab136fdc7ac2ad..e8901d0710907bc7ff57ad1f8b711254d7dc2bec 100644 (file)
@@ -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 {
index 5c25b6e5511d225e758643950b6ed344c9f02978..39f430f92f2e249ea37d092c32b34a02b26ba550 100644 (file)
@@ -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')];
 
index d20258fa96986ff829bd20f6ea8e4b6ec05cb2fb..7300c686b4b209695cb719cad00847894e536267 100644 (file)
@@ -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();
                        }
index 8b50b78c8312a5f9f664a7896d424b7b2699cd2c..b89cb9246c29b45c5fe9656c0c569ee4b140d924 100644 (file)
@@ -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 (file)
index e69315a..0000000
+++ /dev/null
@@ -1,286 +0,0 @@
-<?php
-/**
- * @file mod/register.php
- */
-
-use Friendica\App;
-use Friendica\BaseModule;
-use Friendica\Content\Text\BBCode;
-use Friendica\Core\Config;
-use Friendica\Core\Hook;
-use Friendica\Core\L10n;
-use Friendica\Core\Logger;
-use Friendica\Core\PConfig;
-use Friendica\Core\Renderer;
-use Friendica\Core\System;
-use Friendica\Core\Worker;
-use Friendica\Model;
-use Friendica\Module\Tos;
-use Friendica\Util\Strings;
-
-function register_post(App $a)
-{
-       BaseModule::checkFormSecurityTokenRedirectOnError('/register', 'register');
-
-       $arr = ['post' => $_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:<br> login: %s<br> password: %s<br><br>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 = '<input type="hidden" name="profile_publish_reg" value="1" />';
-       } 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 \'<strong>nickname@%s</strong>\'.', $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;
-}
index e03f28e85b098175dd65bea15ef4712f27b1326e..6cf4c8836c8de48a5c2b617ff625b3253f58ce20 100644 (file)
@@ -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'])) {
index 833b2e9a8e8b1d005135c6424c814c13d56641c9..a8d3c8a5f1f7d96bab0153c0f340a7170e02eb27 100644 (file)
@@ -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'),
index dfeab8a2f6e4d45988b567ab86c8ea8056d3e9d3..22a3161559d46d48cf29149a906a49e6a1de9c2f 100644 (file)
@@ -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;
        }
index 099500200d8256ade2727fc180e6e7e15e6cdaac..a9b95d02d7f61ba2e9e537eefab1acf6618b320b 100644 (file)
@@ -31,7 +31,7 @@ return [
        'config' => [\r
                'admin_email' => 'admin@friendica.local',\r
                'sitename' => 'Friendica Social Network',\r
-               'register_policy' => REGISTER_OPEN,\r
+               'register_policy' => \Friendica\Module\Register::OPEN,\r
                'register_text' => '',\r
        ],\r
        'system' => [\r
index b72f4dc043217e5961e82b2edc9ff0a9995b9aa3..1eae2a3e3b4ba98651bfe15e04b38e3c81831111 100644 (file)
@@ -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')];
                }
 
index 96b0c428fa4947756153f7a63a1f929ae86f8f07..b0897f2d76b841166fc5b328f4d17254b6276916 100644 (file)
@@ -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 (file)
index 0000000..6744a0a
--- /dev/null
@@ -0,0 +1,311 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\Config;
+use Friendica\Core\Hook;
+use Friendica\Core\L10n;
+use Friendica\Core\Logger;
+use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\Core\System;
+use Friendica\Core\Worker;
+use Friendica\Database\DBA;
+use Friendica\Model;
+use Friendica\Util\Strings;
+
+/**
+ * @author Hypolite Petovan <hypolite@mrpetovan.com>
+ */
+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 = '<input type="hidden" name="profile_publish_reg" value="1" />';
+               } 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 "<strong>nickname@%s</strong>".', 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:<br> login: %s<br> password: %s<br><br>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;
+       }
+}
index 4b8b6fff63f1446bb12cd818e9c53b07dddbc4bd..0bc17d3dce17000b33dbf5e799ca84a6f60292f0 100644 (file)
@@ -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', '');
                                }
                        }
index 813277ebbd730322c57734184613dad42c5fb81c..361608d375f3f06f0b1564c4e402768de6cc3afe 100644 (file)
@@ -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' => [
index 54ff279f3cbb966b96e28e75cc7e584c83230165..c4c4afba4db8e9376025660facd8791d32fac2e3 100644 (file)
@@ -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' => [
index 4da865d4cf1e259502bac1a263573853d8e93797..456fadaab841825fac65ad83dc858603d2cf518f 100644 (file)
@@ -41,7 +41,7 @@
        </div>
        <div id="register-email-end" ></div>
 
-{{if $passwords}}
+{{if $ask_password}}
        {{include file="field_password.tpl" field=$password1}}
        {{include file="field_password.tpl" field=$password2}}
 {{/if}}
index feb8035fa379a46f64b367a3c1560392e89067d1..4819c5ee817964a2801c20fb0db73a69777ed90b 100644 (file)
@@ -42,7 +42,7 @@
                </div>
                <div id="register-email-end" ></div>
 
-               {{if $passwords}}
+               {{if $ask_password}}
                {{include file="field_password.tpl" field=$password1}}
                {{include file="field_password.tpl" field=$password2}}
                {{/if}}