thinktomorrow /
chief
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Thinktomorrow\Chief\App\Console; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Thinktomorrow\Chief\Admin\Users\User; |
||
| 7 | |||
| 8 | abstract class BaseCommand extends Command |
||
| 9 | { |
||
| 10 | protected function createUser(string $firstname, string $lastname, string $email, string $password, $roles = []): void |
||
| 11 | { |
||
| 12 | $user = new User(); |
||
| 13 | $user->firstname = $firstname; |
||
| 14 | $user->lastname = $lastname; |
||
| 15 | $user->email = $email; |
||
| 16 | $user->password = bcrypt($password); |
||
| 17 | $user->enabled = true; |
||
| 18 | $user->save(); |
||
| 19 | |||
| 20 | $user->assignRole((array)$roles); |
||
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @return null|string |
||
| 25 | * @throws \Exception |
||
| 26 | */ |
||
| 27 | protected function askPassword() |
||
| 28 | { |
||
| 29 | $password = $passwordConfirm = null; |
||
| 30 | $tries = 0; |
||
| 31 | |||
| 32 | while (! $password || strlen($password) < 4 || $password != $passwordConfirm) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 33 | if ($tries > 2) { |
||
| 34 | throw new \Exception('Aborting. Too many failed attempts to set password'); |
||
| 35 | } |
||
| 36 | |||
| 37 | $password = $this->secret('Password (min. 5 chars)'); |
||
| 38 | $passwordConfirm = $this->secret('Password (confirm)'); |
||
| 39 | |||
| 40 | $tries++; |
||
| 41 | } |
||
| 42 | |||
| 43 | return $password; |
||
| 44 | } |
||
| 45 | } |
||
| 46 |