This commit is contained in:
wispx
2018-12-05 10:29:21 +08:00
parent 3a5709acb0
commit 2bb92177b4
2 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -113,7 +113,7 @@ function str_rand($length = 16, $char = '0123456789abcdefghijklmnopqrstuvwxyzABC
*/
function make_token()
{
return md5('LSKY PRO' . time());
return md5('LSKY PRO' . uniqid() . time());
}
/**
+7 -6
View File
@@ -17,7 +17,7 @@ class Users extends Model
{
use SoftDelete;
protected $insert = ['reg_ip', 'quota'];
protected $insert = ['reg_ip', 'quota', 'token'];
public function setPassWordAttr($password)
{
@@ -34,6 +34,11 @@ class Users extends Model
return Config::where('name', 'user_initial_quota')->value('value');
}
public function setTokenAttr()
{
return make_token();
}
public function getUseQuotaAttr()
{
return $this->hasMany('Images', 'user_id', 'id')->sum('size');
@@ -58,11 +63,7 @@ class Users extends Model
if ($user->password !== md5($password)) {
throw new Exception('密码不正确');
}
$token = make_token();
Session::set('uid', $user->id);
Session::set('token', $token);
$user->token = $token;
$user->save();
} else {
throw new Exception('用户不存在');
}
@@ -72,4 +73,4 @@ class Users extends Model
{
return $this->hasMany('Images', 'user_id', 'id');
}
}
}