Skip to content

Commit 728161e

Browse files
committed
Create a default owner user with installer
1 parent 31c338f commit 728161e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/Console/LaravelCrmInstall.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Console\Command;
66
use Illuminate\Support\Composer;
77
use Illuminate\Support\Facades\File;
8+
use Illuminate\Support\Facades\Hash;
89

910
class LaravelCrmInstall extends Command
1011
{
@@ -125,6 +126,40 @@ public function handle()
125126
$this->callSilent('db:seed', [
126127
'--class' => 'VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmTablesSeeder',
127128
]);
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+
}
128163

129164
$this->info('Laravel CRM is now installed.');
130165

0 commit comments

Comments
 (0)