mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-25 17:26:43 +00:00
Merge pull request #4692 from pixelfed/staging
Update user:admin command, improve logic. Fixes #2465
This commit is contained in:
commit
6f314fa0d2
2 changed files with 20 additions and 12 deletions
|
@ -3,16 +3,17 @@
|
|||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Console\PromptsForMissingInput;
|
||||
use App\User;
|
||||
|
||||
class UserAdmin extends Command
|
||||
class UserAdmin extends Command implements PromptsForMissingInput
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:admin {id}';
|
||||
protected $signature = 'user:admin {username}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
|
@ -22,13 +23,15 @@ class UserAdmin extends Command
|
|||
protected $description = 'Make a user an admin, or remove admin privileges.';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* Prompt for missing input arguments using the returned questions.
|
||||
*
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function __construct()
|
||||
protected function promptForMissingArgumentsUsing()
|
||||
{
|
||||
parent::__construct();
|
||||
return [
|
||||
'username' => 'Which username should we toggle admin privileges for?',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,16 +41,15 @@ class UserAdmin extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$id = $this->argument('id');
|
||||
if(ctype_digit($id) == true) {
|
||||
$user = User::find($id);
|
||||
} else {
|
||||
$user = User::whereUsername($id)->first();
|
||||
}
|
||||
$id = $this->argument('username');
|
||||
|
||||
$user = User::whereUsername($id)->first();
|
||||
|
||||
if(!$user) {
|
||||
$this->error('Could not find any user with that username or id.');
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->info('Found username: ' . $user->username);
|
||||
$state = $user->is_admin ? 'Remove admin privileges from this user?' : 'Add admin privileges to this user?';
|
||||
$confirmed = $this->confirm($state);
|
||||
|
|
|
@ -33,6 +33,7 @@ class UserToggle2FA extends Command implements PromptsForMissingInput
|
|||
'username' => 'Which username should we disable 2FA for?',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
@ -40,6 +41,11 @@ class UserToggle2FA extends Command implements PromptsForMissingInput
|
|||
{
|
||||
$user = User::whereUsername($this->argument('username'))->first();
|
||||
|
||||
if(!$user) {
|
||||
$this->error('Could not find any user with that username');
|
||||
exit;
|
||||
}
|
||||
|
||||
if(!$user->{'2fa_enabled'}) {
|
||||
$this->info('User did not have 2FA enabled!');
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue