Add Exception support to User::create usages
This commit is contained in:
parent
9063c830f5
commit
4d72a40aa6
1 changed files with 15 additions and 8 deletions
|
@ -1466,13 +1466,20 @@ function admin_page_users_post(App $a)
|
||||||
check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
|
check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
|
||||||
|
|
||||||
if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
|
if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
|
||||||
$result = User::create(array('username' => $nu_name, 'email' => $nu_email,
|
try {
|
||||||
'nickname' => $nu_nickname, 'verified' => 1, 'language' => $nu_language));
|
$result = User::create([
|
||||||
if (!$result['success']) {
|
'username' => $nu_name,
|
||||||
notice($result['message']);
|
'email' => $nu_email,
|
||||||
|
'nickname' => $nu_nickname,
|
||||||
|
'verified' => 1,
|
||||||
|
'language' => $nu_language
|
||||||
|
]);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
notice($ex->getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$nu = $result['user'];
|
|
||||||
|
$user = $result['user'];
|
||||||
$preamble = deindent(t('
|
$preamble = deindent(t('
|
||||||
Dear %1$s,
|
Dear %1$s,
|
||||||
the administrator of %2$s has set up an account for you.'));
|
the administrator of %2$s has set up an account for you.'));
|
||||||
|
@ -1502,12 +1509,12 @@ function admin_page_users_post(App $a)
|
||||||
|
|
||||||
Thank you and welcome to %4$s.'));
|
Thank you and welcome to %4$s.'));
|
||||||
|
|
||||||
$preamble = sprintf($preamble, $nu['username'], $a->config['sitename']);
|
$preamble = sprintf($preamble, $user['username'], $a->config['sitename']);
|
||||||
$body = sprintf($body, System::baseUrl(), $nu['email'], $result['password'], $a->config['sitename']);
|
$body = sprintf($body, System::baseUrl(), $user['email'], $result['password'], $a->config['sitename']);
|
||||||
|
|
||||||
notification(array(
|
notification(array(
|
||||||
'type' => SYSTEM_EMAIL,
|
'type' => SYSTEM_EMAIL,
|
||||||
'to_email' => $nu['email'],
|
'to_email' => $user['email'],
|
||||||
'subject' => sprintf(t('Registration details for %s'), $a->config['sitename']),
|
'subject' => sprintf(t('Registration details for %s'), $a->config['sitename']),
|
||||||
'preamble' => $preamble,
|
'preamble' => $preamble,
|
||||||
'body' => $body));
|
'body' => $body));
|
||||||
|
|
Loading…
Reference in a new issue