add event EncryptUserPassword
This commit is contained in:
parent
ea1948dc59
commit
e0a59900a3
|
|
@ -4,7 +4,7 @@ namespace App\Events;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
|
||||||
class CheckUserPassword extends Event
|
class EncryptUserPassword extends Event
|
||||||
{
|
{
|
||||||
public $rawPasswd;
|
public $rawPasswd;
|
||||||
|
|
||||||
|
|
@ -6,6 +6,7 @@ use DB;
|
||||||
use App;
|
use App;
|
||||||
use Utils;
|
use Utils;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Events\EncryptUserPassword;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class User extends Model
|
class User extends Model
|
||||||
|
|
@ -69,13 +70,13 @@ class User extends Model
|
||||||
*/
|
*/
|
||||||
public function checkPasswd($raw_passwd)
|
public function checkPasswd($raw_passwd)
|
||||||
{
|
{
|
||||||
$responses = event(new \App\Events\CheckUserPassword($raw_passwd, $this));
|
$responses = event(new EncryptUserPassword($raw_passwd, $this));
|
||||||
|
|
||||||
if (isset($responses[0])) {
|
if (isset($responses[0])) {
|
||||||
return (bool) $responses[0];
|
$this->password = $responses[0];
|
||||||
} else {
|
|
||||||
return (app('cipher')->encrypt($raw_passwd, config('secure.salt')) == $this->password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (app('cipher')->encrypt($raw_passwd, config('secure.salt')) == $this->password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,7 +111,14 @@ class User extends Model
|
||||||
*/
|
*/
|
||||||
public function changePasswd($new_passwd)
|
public function changePasswd($new_passwd)
|
||||||
{
|
{
|
||||||
$this->password = app('cipher')->encrypt($new_passwd, config('secure.salt'));
|
$responses = event(new EncryptUserPassword($new_passwd, $this));
|
||||||
|
|
||||||
|
if (isset($responses[0])) {
|
||||||
|
$this->password = $responses[0];
|
||||||
|
} else {
|
||||||
|
$this->password = app('cipher')->encrypt($new_passwd, config('secure.salt'));
|
||||||
|
}
|
||||||
|
|
||||||
return $this->save();
|
return $this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user