Move "User::deny()" to own method and update usages
parent
6aee153bbd
commit
b4f6e8fda1
|
@ -20,44 +20,19 @@
|
|||
*/
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Register;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Security\Login;
|
||||
|
||||
// This does not have to go through user_remove() and save the nickname
|
||||
// permanently against re-registration, as the person was not yet
|
||||
// allowed to have friends on this system
|
||||
function user_deny($hash)
|
||||
{
|
||||
$register = Register::getByHash($hash);
|
||||
if (!DBA::isResult($register)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = User::getById($register['uid']);
|
||||
if (!DBA::isResult($user)) {
|
||||
exit();
|
||||
}
|
||||
|
||||
DBA::delete('user', ['uid' => $register['uid']]);
|
||||
|
||||
Register::deleteByHash($register['hash']);
|
||||
|
||||
notice(DI::l10n()->t('Registration revoked for %s', $user['username']) . EOL);
|
||||
return true;
|
||||
}
|
||||
|
||||
function regmod_content(App $a)
|
||||
{
|
||||
if (!local_user()) {
|
||||
info(DI::l10n()->t('Please login.') . EOL);
|
||||
info(DI::l10n()->t('Please login.'));
|
||||
return Login::form(DI::args()->getQueryString(), intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 0 : 1);
|
||||
}
|
||||
|
||||
if (!is_site_admin() || !empty($_SESSION['submanage'])) {
|
||||
notice(DI::l10n()->t('Permission denied.') . EOL);
|
||||
notice(DI::l10n()->t('Permission denied.'));
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -69,13 +44,15 @@ function regmod_content(App $a)
|
|||
$hash = $a->argv[2];
|
||||
|
||||
if ($cmd === 'deny') {
|
||||
user_deny($hash);
|
||||
if (User::deny($hash)) {
|
||||
notice(DI::l10n()->t('Registration revoked'));
|
||||
}
|
||||
DI::baseUrl()->redirect('admin/users/');
|
||||
}
|
||||
|
||||
if ($cmd === 'allow') {
|
||||
if (User::allow($hash)) {
|
||||
info(DI::l10n()->t('Account approved.') . EOL);
|
||||
info(DI::l10n()->t('Account approved.'));
|
||||
}
|
||||
DI::baseUrl()->redirect('admin/users/');
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ Usage
|
|||
bin/console user password <nickname> [<password>] [-h|--help|-?] [-v]
|
||||
bin/console user add [<name> [<nickname> [<email> [<language>]]]] [-h|--help|-?] [-v]
|
||||
bin/console user allow [<nickname>] [-h|--help|-?] [-v]
|
||||
bin/console user deny [<nickname>] [-h|--help|-?] [-v]
|
||||
|
||||
Description
|
||||
Modify user settings per console commands.
|
||||
|
@ -104,7 +105,9 @@ HELP;
|
|||
case 'add':
|
||||
return $this->addUser();
|
||||
case 'allow':
|
||||
return $this->allowUser();
|
||||
return $this->pendingUser(true);
|
||||
case 'deny':
|
||||
return $this->pendingUser(false);
|
||||
default:
|
||||
throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.');
|
||||
}
|
||||
|
@ -200,12 +203,14 @@ HELP;
|
|||
}
|
||||
|
||||
/**
|
||||
* Allows a user based on it's nickname
|
||||
* Allows or denys a user based on it's nickname
|
||||
*
|
||||
* @param bool $allow True, if the pending user is allowed, false if denies
|
||||
*
|
||||
* @return bool True, if allow was successful
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function allowUser()
|
||||
public function pendingUser(bool $allow = true)
|
||||
{
|
||||
$nick = $this->getArgument(1);
|
||||
|
||||
|
@ -227,6 +232,6 @@ HELP;
|
|||
throw new RuntimeException($this->l10n->t('User is not pending.'));
|
||||
}
|
||||
|
||||
return UserModel::allow($pending['hash']);
|
||||
return ($allow) ? UserModel::allow($pending['hash']) : UserModel::deny($pending['hash']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -941,6 +941,34 @@ class User
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Denys a pending registration
|
||||
*
|
||||
* @param string $hash The hash of the pending user
|
||||
*
|
||||
* This does not have to go through user_remove() and save the nickname
|
||||
* permanently against re-registration, as the person was not yet
|
||||
* allowed to have friends on this system
|
||||
*
|
||||
* @return bool True, if the deny was successfull
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function deny(string $hash)
|
||||
{
|
||||
$register = Register::getByHash($hash);
|
||||
if (!DBA::isResult($register)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = User::getById($register['uid']);
|
||||
if (!DBA::isResult($user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DBA::delete('user', ['uid' => $register['uid']]) &&
|
||||
Register::deleteByHash($register['hash']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new user based on a minimal set and sends an email to this user
|
||||
*
|
||||
|
|
|
@ -81,14 +81,18 @@ class Users extends BaseAdmin
|
|||
if (!empty($_POST['page_users_approve'])) {
|
||||
require_once 'mod/regmod.php';
|
||||
foreach ($pending as $hash) {
|
||||
User::allow($hash);
|
||||
if (User::allow($hash)) {
|
||||
info(DI::l10n()->t('Account approved.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['page_users_deny'])) {
|
||||
require_once 'mod/regmod.php';
|
||||
foreach ($pending as $hash) {
|
||||
user_deny($hash);
|
||||
if (User::deny($hash)) {
|
||||
notice(DI::l10n()->t('Registration revoked'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue