mirror of
https://github.com/friendica/friendica
synced 2024-12-23 15:20:17 +00:00
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
This commit is contained in:
parent
540adaf829
commit
9e1065ff87
3 changed files with 48 additions and 58 deletions
|
@ -91,12 +91,10 @@ function register_post(App $a)
|
||||||
// Only send a password mail when the password wasn't manually provided
|
// Only send a password mail when the password wasn't manually provided
|
||||||
if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
|
if (!x($_POST, 'password1') || !x($_POST, 'confirm')) {
|
||||||
$res = Model\User::sendRegisterOpenEmail(
|
$res = Model\User::sendRegisterOpenEmail(
|
||||||
$user['email'],
|
$user,
|
||||||
Config::get('config', 'sitename'),
|
Config::get('config', 'sitename'),
|
||||||
$a->getBaseUrl(),
|
$a->getBaseUrl(),
|
||||||
$user['username'],
|
$result['password']
|
||||||
$result['password'],
|
|
||||||
$user
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($res) {
|
if ($res) {
|
||||||
|
@ -153,12 +151,9 @@ function register_post(App $a)
|
||||||
}
|
}
|
||||||
// send notification to the user, that the registration is pending
|
// send notification to the user, that the registration is pending
|
||||||
Model\User::sendRegisterPendingEmail(
|
Model\User::sendRegisterPendingEmail(
|
||||||
$user['uid'],
|
$user,
|
||||||
$user['email'],
|
|
||||||
Config::get('config', 'sitename'),
|
Config::get('config', 'sitename'),
|
||||||
$user['username'],
|
|
||||||
$a->getBaseURL(),
|
$a->getBaseURL(),
|
||||||
$user['nickname'],
|
|
||||||
$result['password']
|
$result['password']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -20,44 +20,34 @@ function user_allow($hash)
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
$register = Register::getByHash($hash);
|
$register = Register::getByHash($hash);
|
||||||
|
|
||||||
if (!DBA::isResult($register)) {
|
if (!DBA::isResult($register)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
$user = User::getById($register['uid']);
|
||||||
intval($register['uid'])
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!DBA::isResult($user)) {
|
if (!DBA::isResult($user)) {
|
||||||
killme();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Register::deleteByHash($hash);
|
Register::deleteByHash($hash);
|
||||||
|
|
||||||
$r = q("UPDATE `user` SET `blocked` = 0, `verified` = 1 WHERE `uid` = %d",
|
DBA::update('user', ['blocked' => false, 'verified' => true], ['uid' => $register['uid']]);
|
||||||
intval($register['uid'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1",
|
$profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid'], 'is-default' => true]);
|
||||||
intval($user[0]['uid'])
|
|
||||||
);
|
if (DBA::isResult($profile) && $profile['net-publish'] && Config::get('system', 'directory')) {
|
||||||
if (DBA::isResult($r) && $r[0]['net-publish']) {
|
$url = System::baseUrl() . '/profile/' . $user['nickname'];
|
||||||
$url = System::baseUrl() . '/profile/' . $user[0]['nickname'];
|
|
||||||
if ($url && strlen(Config::get('system', 'directory'))) {
|
|
||||||
Worker::add(PRIORITY_LOW, "Directory", $url);
|
Worker::add(PRIORITY_LOW, "Directory", $url);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
L10n::pushLang($register['language']);
|
L10n::pushLang($register['language']);
|
||||||
|
|
||||||
$res = User::sendRegisterOpenEmail(
|
$res = User::sendRegisterOpenEmail(
|
||||||
$user[0]['email'],
|
$user,
|
||||||
Config::get('config', 'sitename'),
|
Config::get('config', 'sitename'),
|
||||||
System::baseUrl(),
|
$a->getBaseUrl(),
|
||||||
$user[0]['username'],
|
defaults($register, 'password', 'Sent in a previous email')
|
||||||
'Sent in a previous email',
|
);
|
||||||
$user[0]);
|
|
||||||
|
|
||||||
L10n::popLang();
|
L10n::popLang();
|
||||||
|
|
||||||
|
@ -73,20 +63,20 @@ function user_allow($hash)
|
||||||
function user_deny($hash)
|
function user_deny($hash)
|
||||||
{
|
{
|
||||||
$register = Register::getByHash($hash);
|
$register = Register::getByHash($hash);
|
||||||
|
|
||||||
if (!DBA::isResult($register)) {
|
if (!DBA::isResult($register)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
$user = User::getById($register['uid']);
|
||||||
intval($register['uid'])
|
if (!DBA::isResult($user)) {
|
||||||
);
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
DBA::delete('user', ['uid' => $register['uid']]);
|
DBA::delete('user', ['uid' => $register['uid']]);
|
||||||
|
|
||||||
Register::deleteByHash($register['hash']);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,17 +84,16 @@ function regmod_content(App $a)
|
||||||
{
|
{
|
||||||
if (!local_user()) {
|
if (!local_user()) {
|
||||||
info(L10n::t('Please login.') . EOL);
|
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 Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === REGISTER_CLOSED ? 0 : 1);
|
||||||
return $o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!is_site_admin()) || (x($_SESSION, 'submanage') && intval($_SESSION['submanage']))) {
|
if (!is_site_admin() || !empty($_SESSION['submanage'])) {
|
||||||
notice(L10n::t('Permission denied.') . EOL);
|
notice(L10n::t('Permission denied.') . EOL);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($a->argc != 3) {
|
if ($a->argc != 3) {
|
||||||
killme();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmd = $a->argv[1];
|
$cmd = $a->argv[1];
|
||||||
|
@ -112,13 +101,11 @@ function regmod_content(App $a)
|
||||||
|
|
||||||
if ($cmd === 'deny') {
|
if ($cmd === 'deny') {
|
||||||
user_deny($hash);
|
user_deny($hash);
|
||||||
goaway(System::baseUrl() . "/admin/users/");
|
goaway('admin/users/');
|
||||||
killme();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cmd === 'allow') {
|
if ($cmd === 'allow') {
|
||||||
user_allow($hash);
|
user_allow($hash);
|
||||||
goaway(System::baseUrl() . "/admin/users/");
|
goaway('admin/users/');
|
||||||
killme();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* @return integer user id
|
||||||
*/
|
*/
|
||||||
|
@ -657,13 +666,13 @@ class User
|
||||||
/**
|
/**
|
||||||
* @brief Sends pending registration confirmation email
|
* @brief Sends pending registration confirmation email
|
||||||
*
|
*
|
||||||
* @param string $email
|
* @param array $user User record array
|
||||||
* @param string $sitename
|
* @param string $sitename
|
||||||
* @param string $username
|
* @param string $siteurl
|
||||||
* @param string $password Plaintext password
|
* @param string $password Plaintext password
|
||||||
* @return NULL|boolean from notification() and email() inherited
|
* @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('
|
$body = deindent(L10n::t('
|
||||||
Dear %1$s,
|
Dear %1$s,
|
||||||
|
@ -675,13 +684,13 @@ class User
|
||||||
Login Name: %4$s
|
Login Name: %4$s
|
||||||
Password: %5$s
|
Password: %5$s
|
||||||
',
|
',
|
||||||
$body, $username, $sitename, $siteurl, $nickname, $password
|
$body, $user['username'], $sitename, $siteurl, $user['nickname'], $password
|
||||||
));
|
));
|
||||||
|
|
||||||
return notification([
|
return notification([
|
||||||
'type' => SYSTEM_EMAIL,
|
'type' => SYSTEM_EMAIL,
|
||||||
'uid' => $uid,
|
'uid' => $user['uid'],
|
||||||
'to_email' => $email,
|
'to_email' => $user['email'],
|
||||||
'subject' => L10n::t('Registration at %s', $sitename),
|
'subject' => L10n::t('Registration at %s', $sitename),
|
||||||
'body' => $body
|
'body' => $body
|
||||||
]);
|
]);
|
||||||
|
@ -692,20 +701,19 @@ class User
|
||||||
*
|
*
|
||||||
* It's here as a function because the mail is sent from different parts
|
* 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 $sitename
|
||||||
* @param string $siteurl
|
* @param string $siteurl
|
||||||
* @param string $username
|
* @param string $password Plaintext password
|
||||||
* @param string $password
|
|
||||||
* @return NULL|boolean from notification() and email() inherited
|
* @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('
|
$preamble = deindent(L10n::t('
|
||||||
Dear %1$s,
|
Dear %1$s,
|
||||||
Thank you for registering at %2$s. Your account has been created.
|
Thank you for registering at %2$s. Your account has been created.
|
||||||
',
|
',
|
||||||
$preamble, $username, $sitename
|
$preamble, $user['username'], $sitename
|
||||||
));
|
));
|
||||||
$body = deindent(L10n::t('
|
$body = deindent(L10n::t('
|
||||||
The login details are as follows:
|
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
|
If you ever want to delete your account, you can do so at %3$s/removeme
|
||||||
|
|
||||||
Thank you and welcome to %2$s.',
|
Thank you and welcome to %2$s.',
|
||||||
$body, $email, $sitename, $siteurl, $username, $password
|
$body, $user['email'], $sitename, $siteurl, $user['username'], $password
|
||||||
));
|
));
|
||||||
|
|
||||||
return notification([
|
return notification([
|
||||||
'uid' => $user['uid'],
|
'uid' => $user['uid'],
|
||||||
'language' => $user['language'],
|
'language' => $user['language'],
|
||||||
'type' => SYSTEM_EMAIL,
|
'type' => SYSTEM_EMAIL,
|
||||||
'to_email' => $email,
|
'to_email' => $user['email'],
|
||||||
'subject' => L10n::t('Registration details for %s', $sitename),
|
'subject' => L10n::t('Registration details for %s', $sitename),
|
||||||
'preamble' => $preamble,
|
'preamble' => $preamble,
|
||||||
'body' => $body
|
'body' => $body
|
||||||
|
|
Loading…
Reference in a new issue