Merge pull request #6336 from MrPetovan/bug/6334-get-app-namespace

Move mod/register to Module\Register
This commit is contained in:
Michael Vogel 2019-01-23 07:40:58 +01:00 committed by GitHub
commit 48e0b943a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 388 additions and 348 deletions

View File

@ -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
*

View 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' => [

View 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.

View 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';

View 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 = [

View 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;
}

View 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_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 = '';

View 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);

View 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 {

View 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')];

View 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();
}

View 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)) {

View File

@ -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;
}

View 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'])) {

View 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'),

View 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;
}

View File

@ -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' => [

View 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')];
}

View 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()

311
src/Module/Register.php Normal file
View File

@ -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;
}
}

View 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', '');
}
}

View 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' => [

View 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' => [

View 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}}

View 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}}