From: Benjamin Lorteau Date: Mon, 15 Oct 2018 15:58:52 +0000 (-0400) Subject: Improve transition from previous behavior X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9e1065ff87e22dcf38f97f203030bc7a73ae64ba;p=friendica.git Improve transition from previous behavior - Simplify Model\User methods parameter list - Use DBA methods in mod/regmod - Replace killme with exit in mod/regmod - Simplify goaway() calls --- diff --git a/mod/register.php b/mod/register.php index 79e9455cd5..48fe67afc5 100644 --- a/mod/register.php +++ b/mod/register.php @@ -91,12 +91,10 @@ function register_post(App $a) // 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) { @@ -153,12 +151,9 @@ function register_post(App $a) } // 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'] ); diff --git a/mod/regmod.php b/mod/regmod.php index 433a8f5e4e..3f6f0e04e3 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -20,44 +20,34 @@ function user_allow($hash) $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(); @@ -73,20 +63,20 @@ function user_allow($hash) 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; } @@ -94,17 +84,16 @@ function regmod_content(App $a) { if (!local_user()) { info(L10n::t('Please login.') . EOL); - $o = '

' . 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]; @@ -112,13 +101,11 @@ function regmod_content(App $a) 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/'); } } diff --git a/src/Model/User.php b/src/Model/User.php index 2888410c7f..eb042eb8b4 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -43,9 +43,18 @@ class User } /** - * @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 */ @@ -657,13 +666,13 @@ class User /** * @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, @@ -675,13 +684,13 @@ class User 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 ]); @@ -692,20 +701,19 @@ class User * * 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: @@ -734,14 +742,14 @@ class User 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