Improved notices

This commit is contained in:
Michael 2020-01-17 07:29:22 +00:00
parent 7ee7bd72fd
commit 5c0f0c9c19

View file

@ -44,20 +44,20 @@ class Register extends BaseModule
$block = Config::get('system', 'block_extended_register'); $block = Config::get('system', 'block_extended_register');
if (local_user() && $block) { if (local_user() && $block) {
notice('Permission denied.' . EOL); notice(L10n::t('Permission denied.'));
return ''; return '';
} }
if (local_user()) { if (local_user()) {
$user = DBA::selectFirst('user', ['parent-uid'], ['uid' => local_user()]); $user = DBA::selectFirst('user', ['parent-uid'], ['uid' => local_user()]);
if (!empty($user['parent-uid'])) { if (!empty($user['parent-uid'])) {
notice('Only parent users can create additional profiles.'); notice(L10n::t('Only parent users can create additional profiles.'));
return ''; return '';
} }
} }
if (!local_user() && (intval(Config::get('config', 'register_policy')) === self::CLOSED)) { if (!local_user() && (intval(Config::get('config', 'register_policy')) === self::CLOSED)) {
notice('Permission denied.' . EOL); notice(L10n::t('Permission denied.'));
return ''; return '';
} }
@ -66,7 +66,7 @@ class Register extends BaseModule
$count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']); $count = DBA::count('user', ['`register_date` > UTC_TIMESTAMP - INTERVAL 1 day']);
if ($count >= $max_dailies) { if ($count >= $max_dailies) {
Logger::log('max daily registrations exceeded.'); 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); notice(L10n::t('This site has exceeded the number of allowed daily account registrations. Please try again tomorrow.'));
return ''; return '';
} }
} }
@ -177,19 +177,19 @@ class Register extends BaseModule
$additional_account = false; $additional_account = false;
if (!local_user() && !empty($arr['post']['parent_password'])) { if (!local_user() && !empty($arr['post']['parent_password'])) {
notice(L10n::t('Permission denied.') . EOL); notice(L10n::t('Permission denied.'));
return; return;
} elseif (local_user() && !empty($arr['post']['parent_password'])) { } elseif (local_user() && !empty($arr['post']['parent_password'])) {
try { try {
Model\User::getIdFromPasswordAuthentication(local_user(), $arr['post']['parent_password']); Model\User::getIdFromPasswordAuthentication(local_user(), $arr['post']['parent_password']);
} catch (\Exception $ex) { } catch (\Exception $ex) {
notice(L10n::t("Password doesn't match")); notice(L10n::t("Password doesn't match."));
$regdata = ['nickname' => $arr['post']['nickname'], 'username' => $arr['post']['username']]; $regdata = ['nickname' => $arr['post']['nickname'], 'username' => $arr['post']['username']];
DI::baseUrl()->redirect('register?' . http_build_query($regdata)); DI::baseUrl()->redirect('register?' . http_build_query($regdata));
} }
$additional_account = true; $additional_account = true;
} elseif (local_user()) { } elseif (local_user()) {
notice(L10n::t('Please enter your password')); notice(L10n::t('Please enter your password.'));
$regdata = ['nickname' => $arr['post']['nickname'], 'username' => $arr['post']['username']]; $regdata = ['nickname' => $arr['post']['nickname'], 'username' => $arr['post']['username']];
DI::baseUrl()->redirect('register?' . http_build_query($regdata)); DI::baseUrl()->redirect('register?' . http_build_query($regdata));
} }
@ -216,7 +216,7 @@ class Register extends BaseModule
case self::CLOSED: case self::CLOSED:
default: default:
if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) { if (empty($_SESSION['authenticated']) && empty($_SESSION['administrator'])) {
\notice(L10n::t('Permission denied.') . EOL); notice(L10n::t('Permission denied.'));
return; return;
} }
$blocked = 1; $blocked = 1;
@ -242,7 +242,7 @@ class Register extends BaseModule
if ($additional_account) { if ($additional_account) {
$user = DBA::selectFirst('user', ['email'], ['uid' => local_user()]); $user = DBA::selectFirst('user', ['email'], ['uid' => local_user()]);
if (!DBA::isResult($user)) { if (!DBA::isResult($user)) {
notice(L10n::t('User not found')); notice(L10n::t('User not found.'));
DI::baseUrl()->redirect('register'); DI::baseUrl()->redirect('register');
} }
@ -267,7 +267,7 @@ class Register extends BaseModule
try { try {
$result = Model\User::create($arr); $result = Model\User::create($arr);
} catch (\Exception $e) { } catch (\Exception $e) {
\notice($e->getMessage()); notice($e->getMessage());
return; return;
} }
@ -307,29 +307,29 @@ class Register extends BaseModule
); );
if ($res) { if ($res) {
\info(L10n::t('Registration successful. Please check your email for further instructions.') . EOL); info(L10n::t('Registration successful. Please check your email for further instructions.'));
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} else { } else {
\notice( 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.', 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'], $user['email'],
$result['password']) $result['password'])
); );
} }
} else { } else {
\info(L10n::t('Registration successful.') . EOL); info(L10n::t('Registration successful.'));
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} }
} elseif (intval(Config::get('config', 'register_policy')) === self::APPROVE) { } elseif (intval(Config::get('config', 'register_policy')) === self::APPROVE) {
if (!strlen(Config::get('config', 'admin_email'))) { if (!strlen(Config::get('config', 'admin_email'))) {
\notice(L10n::t('Your registration can not be processed.') . EOL); notice(L10n::t('Your registration can not be processed.'));
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} }
// Check if the note to the admin is actually filled out // Check if the note to the admin is actually filled out
if (empty($_POST['permonlybox'])) { if (empty($_POST['permonlybox'])) {
\notice(L10n::t('You have to leave a request note for the admin.') notice(L10n::t('You have to leave a request note for the admin.')
. L10n::t('Your registration can not be processed.') . EOL); . L10n::t('Your registration can not be processed.'));
DI::baseUrl()->redirect('register/'); DI::baseUrl()->redirect('register/');
} }
@ -376,7 +376,7 @@ class Register extends BaseModule
$result['password'] $result['password']
); );
\info(L10n::t('Your registration is pending approval by the site owner.') . EOL); info(L10n::t('Your registration is pending approval by the site owner.'));
DI::baseUrl()->redirect(); DI::baseUrl()->redirect();
} }