Skip to content

Commit

Permalink
Administrator hash password in model
Browse files Browse the repository at this point in the history
  • Loading branch information
veneliniliev committed Jan 10, 2017
1 parent 35fdafe commit 161095a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
20 changes: 15 additions & 5 deletions app/AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

namespace ProVision\Administration;

use Validator;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Notifications\Notifiable;
use Zizaco\Entrust\Traits\EntrustUserTrait;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Hash;
use ProVision\Administration\Notifications\ResetPassword;
use Validator;
use Zizaco\Entrust\Traits\EntrustUserTrait;

class AdminUser extends Authenticatable
{
Expand Down Expand Up @@ -85,6 +86,15 @@ public function errors()
return $this->errors;
}

/**
* Password hash set
* @param string $value
*/
public function setPasswordAttribute($value)
{
$this->attributes['password'] = Hash::make($value);
}

/**
* Send the password reset notification.
*
Expand Down
18 changes: 9 additions & 9 deletions app/Console/Commands/CreateAdministrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace ProVision\Administration\Console\Commands;

use Illuminate\Console\Command;
use ProVision\Administration\Role;
use Illuminate\Support\Facades\Hash;
use ProVision\Administration\AdminUser;
use ProVision\Administration\Http\Controllers\Systems\RolesRepairController;
use ProVision\Administration\Role;

class CreateAdministrator extends Command
{
Expand Down Expand Up @@ -40,7 +40,7 @@ public function __construct()
/*
* command fix
*/
$this->signature = config('provision_administration.command_prefix').':admin {email} {password}';
$this->signature = config('provision_administration.command_prefix') . ':admin {email} {password}';

parent::__construct();
}
Expand All @@ -65,22 +65,22 @@ public function handle()
$adminUser = AdminUser::create([
'name' => 'ProVision Administrator',
'email' => $this->argument('email'),
'password' => Hash::make($this->argument('password')),
'password' => $this->argument('password'),
]);

$this->info('Creating admin user...');
$this->info('email: '.$adminUser->email);
$this->info('password: '.$this->argument('password'));
$this->info('email: ' . $adminUser->email);
$this->info('password: ' . $this->argument('password'));
} else {
/*
* Reset admin password
*/
$adminUser->password = Hash::make($this->argument('password'));
$adminUser->password = $this->argument('password');
$adminUser->save();

$this->info('Reset admin user...');
$this->info('email: '.$adminUser->email);
$this->info('password: '.$this->argument('password'));
$this->info('email: ' . $adminUser->email);
$this->info('password: ' . $this->argument('password'));
}

/*
Expand All @@ -95,7 +95,7 @@ public function handle()
$adminRole->save();
$this->info('Create admin role...');
}
if (! $adminUser->hasRole('admin')) {
if (!$adminUser->hasRole('admin')) {
$this->info('Assign admin role...');
$adminUser->attachRole($adminRole);
}
Expand Down

0 comments on commit 161095a

Please sign in to comment.