-
Notifications
You must be signed in to change notification settings - Fork 554
/
CreateSuperAdmin.php
52 lines (44 loc) · 1.41 KB
/
CreateSuperAdmin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace A17\Twill\Commands;
use A17\Twill\Models\User;
use Illuminate\Console\Command;
use Validator;
class CreateSuperAdmin extends Command
{
protected $signature = 'twill:superadmin';
protected $description = "Create the superadmin account";
public function handle()
{
$this->info("Let's create a superadmin account!");
$email = $this->ask('Enter an email');
if ($this->validateEmail($email)) {
$password = $this->ask('Enter a password');
if ($this->validatePassword($password)) {
return User::create([
'name' => "Admin",
'email' => $email,
'password' => bcrypt($password),
'role' => 'SUPERADMIN',
'published' => true,
]);
} else {
$this->error("Your password is not valid");
}
} else {
$this->error("Your email is not valid");
}
$this->info("Your account has been created");
}
private function validateEmail($email)
{
return Validator::make(['email' => $email], [
'email' => 'required|email|max:255|unique:users',
]);
}
private function validatePassword($password)
{
return Validator::make(['password' => $password], [
'password' => 'required|confirmed|min:6',
]);
}
}