Merge pull request #264 from hammerdawn/RepairUserRepo

Repair user creation functionality
This commit is contained in:
Dane Everitt 2017-01-22 13:24:19 -05:00 committed by GitHub
commit 0ec659f44f
3 changed files with 13 additions and 7 deletions

View file

@ -35,6 +35,9 @@ class MakeUser extends Command
* @var string * @var string
*/ */
protected $signature = 'pterodactyl:user protected $signature = 'pterodactyl:user
{--firstname= : First name to use for this account.}
{--lastname= : Last name to use for this account.}
{--username= : Username to use for this account.}
{--email= : Email address to use for this account.} {--email= : Email address to use for this account.}
{--password= : Password to assign to the user.} {--password= : Password to assign to the user.}
{--admin= : Boolean flag for if user should be an admin.}'; {--admin= : Boolean flag for if user should be an admin.}';
@ -63,19 +66,22 @@ class MakeUser extends Command
*/ */
public function handle() public function handle()
{ {
$email = is_null($this->option('email')) ? $this->ask('Email') : $this->option('email'); $data['name_first'] = is_null($this->option('firstname')) ? $this->ask('First Name') : $this->option('firstname');
$password = is_null($this->option('password')) ? $this->secret('Password') : $this->option('password'); $data['name_last'] = is_null($this->option('lastname')) ? $this->ask('Last Name') : $this->option('lastname');
$data['username'] = is_null($this->option('username')) ? $this->ask('Username') : $this->option('username');
$data['email'] = is_null($this->option('email')) ? $this->ask('Email') : $this->option('email');
$data['password'] = is_null($this->option('password')) ? $this->secret('Password') : $this->option('password');
$password_confirmation = is_null($this->option('password')) ? $this->secret('Confirm Password') : $this->option('password'); $password_confirmation = is_null($this->option('password')) ? $this->secret('Confirm Password') : $this->option('password');
if ($password !== $password_confirmation) { if ($data['password'] !== $password_confirmation) {
return $this->error('The passwords provided did not match!'); return $this->error('The passwords provided did not match!');
} }
$admin = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin'); $data['root_admin'] = is_null($this->option('admin')) ? $this->confirm('Is this user a root administrator?') : $this->option('admin');
try { try {
$user = new UserRepository; $user = new UserRepository;
$user->create($email, $password, $admin); $user->create($data);
return $this->info('User successfully created.'); return $this->info('User successfully created.');
} catch (\Exception $ex) { } catch (\Exception $ex) {

View file

@ -67,7 +67,7 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
* *
* @var [type] * @var [type]
*/ */
protected $fillable = ['username', 'email', 'name_first', 'name_last', 'password', 'language', 'use_totp', 'totp_secret', 'gravatar']; protected $fillable = ['username', 'email', 'name_first', 'name_last', 'password', 'language', 'use_totp', 'totp_secret', 'gravatar', 'root_admin'];
/** /**
* Cast values to correct type. * Cast values to correct type.

View file

@ -90,7 +90,7 @@ class UserRepository
'username' => $data['username'], 'username' => $data['username'],
'name_first' => $data['name_first'], 'name_first' => $data['name_first'],
'name_last' => $data['name_last'], 'name_last' => $data['name_last'],
'password' => Hash::make((empty($data['password'])) ? str_random(30) : $password), 'password' => Hash::make((empty($data['password'])) ? str_random(30) : $data['password']),
'root_admin' => $data['root_admin'], 'root_admin' => $data['root_admin'],
'language' => Settings::get('default_language', 'en'), 'language' => Settings::get('default_language', 'en'),
]); ]);