add event EncryptUserPassword

This commit is contained in:
printempw 2016-11-05 20:11:48 +08:00
parent ea1948dc59
commit e0a59900a3
2 changed files with 14 additions and 6 deletions

View File

@ -4,7 +4,7 @@ namespace App\Events;
use App\Models\User;
class CheckUserPassword extends Event
class EncryptUserPassword extends Event
{
public $rawPasswd;

View File

@ -6,6 +6,7 @@ use DB;
use App;
use Utils;
use Carbon\Carbon;
use App\Events\EncryptUserPassword;
use Illuminate\Database\Eloquent\Model;
class User extends Model
@ -69,13 +70,13 @@ class User extends Model
*/
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])) {
return (bool) $responses[0];
} else {
return (app('cipher')->encrypt($raw_passwd, config('secure.salt')) == $this->password);
$this->password = $responses[0];
}
return (app('cipher')->encrypt($raw_passwd, config('secure.salt')) == $this->password);
}
/**
@ -110,7 +111,14 @@ class User extends Model
*/
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();
}