diff --git a/application/common.php b/application/common.php index 48c4f647..d0635c92 100644 --- a/application/common.php +++ b/application/common.php @@ -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()); } /** diff --git a/application/common/model/Users.php b/application/common/model/Users.php index a9d2c97a..5cbaad52 100644 --- a/application/common/model/Users.php +++ b/application/common/model/Users.php @@ -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'); } -} \ No newline at end of file +}