mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Add UserCreate command
This commit is contained in:
parent
0b9a5a26ad
commit
edce1dcf54
1 changed files with 88 additions and 0 deletions
88
app/Console/Commands/UserCreate.php
Normal file
88
app/Console/Commands/UserCreate.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\User;
|
||||
|
||||
class UserCreate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:create';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create a new user';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Creating a new user...');
|
||||
|
||||
$name = $this->ask('Name');
|
||||
|
||||
$username = $this->ask('Username');
|
||||
|
||||
if(User::whereUsername($username)->exists()) {
|
||||
$this->error('Username already in use, please try again...');
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = $this->ask('Email');
|
||||
|
||||
if(User::whereEmail($email)->exists()) {
|
||||
$this->error('Email already in use, please try again...');
|
||||
exit;
|
||||
}
|
||||
|
||||
$password = $this->secret('Password');
|
||||
$confirm = $this->secret('Confirm Password');
|
||||
|
||||
if($password !== $confirm) {
|
||||
$this->error('Password mismatch, please try again...');
|
||||
exit;
|
||||
}
|
||||
|
||||
$is_admin = $this->confirm('Make this user an admin?');
|
||||
$confirm_email = $this->confirm('Manually verify email address?');
|
||||
|
||||
if($this->confirm('Are you sure you want to create this user?') &&
|
||||
$username &&
|
||||
$name &&
|
||||
$email &&
|
||||
$password
|
||||
) {
|
||||
$user = new User;
|
||||
$user->username = $username;
|
||||
$user->name = $name;
|
||||
$user->email = $email;
|
||||
$user->password = bcrypt($password);
|
||||
$user->is_admin = $is_admin;
|
||||
$user->email_verified_at = $confirm_email ? now() : null;
|
||||
$user->save();
|
||||
|
||||
$this->info('Created new user!');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue