|
5 | 5 | use Illuminate\Console\Command; |
6 | 6 | use Illuminate\Support\Composer; |
7 | 7 | use Illuminate\Support\Facades\File; |
| 8 | +use Illuminate\Support\Facades\Hash; |
8 | 9 |
|
9 | 10 | class LaravelCrmInstall extends Command |
10 | 11 | { |
@@ -125,6 +126,40 @@ public function handle() |
125 | 126 | $this->callSilent('db:seed', [ |
126 | 127 | '--class' => 'VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmTablesSeeder', |
127 | 128 | ]); |
| 129 | + |
| 130 | + if (\App\User::where('crm_access')->count() < 1) { |
| 131 | + $this->info('Create your default owner user'); |
| 132 | + |
| 133 | + $firstname = $this->ask('Whats your first name?'); |
| 134 | + $lastname = $this->ask('Whats your last name?'); |
| 135 | + $email = $this->ask('Whats your email address?'); |
| 136 | + $password = $this->secret('Enter a password'); |
| 137 | + |
| 138 | + if ($user = \App\User::where('email', $email)->first()) { |
| 139 | + $this->info('User already exists, granting crm access...'); |
| 140 | + |
| 141 | + $user->update([ |
| 142 | + 'crm_access' => 1, |
| 143 | + ]); |
| 144 | + |
| 145 | + if (! $user->hasRole('Owner')) { |
| 146 | + $user->assignRole('Owner'); |
| 147 | + } |
| 148 | + |
| 149 | + $this->info('User access and role updated.'); |
| 150 | + } else { |
| 151 | + $user = \App\User::forceCreate([ |
| 152 | + 'name' => trim($firstname.' '.$lastname), |
| 153 | + 'email' => $email, |
| 154 | + 'password' => Hash::make($password), |
| 155 | + 'crm_access' => 1, |
| 156 | + ]); |
| 157 | + |
| 158 | + $user->assignRole('Owner'); |
| 159 | + |
| 160 | + $this->info('User created with owner role'); |
| 161 | + } |
| 162 | + } |
128 | 163 |
|
129 | 164 | $this->info('Laravel CRM is now installed.'); |
130 | 165 |
|
|
0 commit comments