// Only send a password mail when the password wasn't manually provided
if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
$res = Model\User::sendRegisterOpenEmail(
- $user['email'],
+ $user,
Config::get('config', 'sitename'),
$a->getBaseUrl(),
- $user['username'],
- $result['password'],
- $user
+ $result['password']
);
if ($res) {
}
// send notification to the user, that the registration is pending
Model\User::sendRegisterPendingEmail(
- $user['uid'],
- $user['email'],
+ $user,
Config::get('config', 'sitename'),
- $user['username'],
$a->getBaseURL(),
- $user['nickname'],
$result['password']
);
$a = get_app();
$register = Register::getByHash($hash);
-
if (!DBA::isResult($register)) {
return false;
}
- $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
- intval($register['uid'])
- );
-
+ $user = User::getById($register['uid']);
if (!DBA::isResult($user)) {
- killme();
+ exit();
}
Register::deleteByHash($hash);
- $r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
- intval($register['uid'])
- );
+ DBA::update('user', ['blocked' => false, 'verified' => true], ['uid' => $register['uid']]);
- $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
- intval($user[0]['uid'])
- );
- if (DBA::isResult($r) && $r[0]['net-publish']) {
- $url = System::baseUrl() . '/profile/' . $user[0]['nickname'];
- if ($url && strlen(Config::get('system', 'directory'))) {
- Worker::add(PRIORITY_LOW, "Directory", $url);
- }
+ $profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid'], 'is-default' => true]);
+
+ if (DBA::isResult($profile) && $profile['net-publish'] && Config::get('system', 'directory')) {
+ $url = System::baseUrl() . '/profile/' . $user['nickname'];
+ Worker::add(PRIORITY_LOW, "Directory", $url);
}
L10n::pushLang($register['language']);
$res = User::sendRegisterOpenEmail(
- $user[0]['email'],
+ $user,
Config::get('config', 'sitename'),
- System::baseUrl(),
- $user[0]['username'],
- 'Sent in a previous email',
- $user[0]);
+ $a->getBaseUrl(),
+ defaults($register, 'password', 'Sent in a previous email')
+ );
L10n::popLang();
function user_deny($hash)
{
$register = Register::getByHash($hash);
-
if (!DBA::isResult($register)) {
return false;
}
- $user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
- intval($register['uid'])
- );
+ $user = User::getById($register['uid']);
+ if (!DBA::isResult($user)) {
+ exit();
+ }
DBA::delete('user', ['uid' => $register['uid']]);
Register::deleteByHash($register['hash']);
- notice(L10n::t('Registration revoked for %s', $user[0]['username']) . EOL);
+ notice(L10n::t('Registration revoked for %s', $user['username']) . EOL);
return true;
}
{
if (!local_user()) {
info(L10n::t('Please login.') . EOL);
- $o = '<br /><br />' . Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
- return $o;
+ return Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
}
- if ((!is_site_admin()) || (x($_SESSION, 'submanage') && intval($_SESSION['submanage']))) {
+ if (!is_site_admin() || !empty($_SESSION['submanage'])) {
notice(L10n::t('Permission denied.') . EOL);
return '';
}
if ($a->argc != 3) {
- killme();
+ exit();
}
$cmd = $a->argv[1];
if ($cmd === 'deny') {
user_deny($hash);
- goaway(System::baseUrl() . "/admin/users/");
- killme();
+ goaway('admin/users/');
}
if ($cmd === 'allow') {
user_allow($hash);
- goaway(System::baseUrl() . "/admin/users/");
- killme();
+ goaway('admin/users/');
}
}
}
/**
- * @brief Returns the user id of a given profile url
+ * @param integer $uid
+ * @return array|boolean User record if it exists, false otherwise
+ */
+ public static function getById($uid)
+ {
+ return DBA::selectFirst('user', [], ['uid' => $uid]);
+ }
+
+ /**
+ * @brief Returns the user id of a given profile URL
*
- * @param string $profile
+ * @param string $url
*
* @return integer user id
*/
/**
* @brief Sends pending registration confirmation email
*
- * @param string $email
+ * @param array $user User record array
* @param string $sitename
- * @param string $username
+ * @param string $siteurl
* @param string $password Plaintext password
* @return NULL|boolean from notification() and email() inherited
*/
- public static function sendRegisterPendingEmail($uid, $email, $sitename, $username, $siteurl, $nickname, $password)
+ public static function sendRegisterPendingEmail($user, $sitename, $siteurl, $password)
{
$body = deindent(L10n::t('
Dear %1$s,
Login Name: %4$s
Password: %5$s
',
- $body, $username, $sitename, $siteurl, $nickname, $password
+ $body, $user['username'], $sitename, $siteurl, $user['nickname'], $password
));
return notification([
'type' => SYSTEM_EMAIL,
- 'uid' => $uid,
- 'to_email' => $email,
+ 'uid' => $user['uid'],
+ 'to_email' => $user['email'],
'subject' => L10n::t('Registration at %s', $sitename),
'body' => $body
]);
*
* It's here as a function because the mail is sent from different parts
*
- * @param string $email
+ * @param array $user User record array
* @param string $sitename
* @param string $siteurl
- * @param string $username
- * @param string $password
+ * @param string $password Plaintext password
* @return NULL|boolean from notification() and email() inherited
*/
- public static function sendRegisterOpenEmail($email, $sitename, $siteurl, $username, $password, $user)
+ public static function sendRegisterOpenEmail($user, $sitename, $siteurl, $password)
{
$preamble = deindent(L10n::t('
Dear %1$s,
Thank you for registering at %2$s. Your account has been created.
',
- $preamble, $username, $sitename
+ $preamble, $user['username'], $sitename
));
$body = deindent(L10n::t('
The login details are as follows:
If you ever want to delete your account, you can do so at %3$s/removeme
Thank you and welcome to %2$s.',
- $body, $email, $sitename, $siteurl, $username, $password
+ $body, $user['email'], $sitename, $siteurl, $user['username'], $password
));
return notification([
'uid' => $user['uid'],
'language' => $user['language'],
'type' => SYSTEM_EMAIL,
- 'to_email' => $email,
+ 'to_email' => $user['email'],
'subject' => L10n::t('Registration details for %s', $sitename),
'preamble' => $preamble,
'body' => $body