Commit 17b8616e by 杨树贤

最后登录时间

parent de81acba
...@@ -20,9 +20,8 @@ class AuthController extends Controller ...@@ -20,9 +20,8 @@ class AuthController extends Controller
'salt', 'salt',
]); ]);
$ucId = UserService::register($data); $user = UserService::register($data);
return $this->setSuccessData(['uc_id' => $user['uc_id'], 'user' => $user]);
return $this->setSuccessData(['uc_id' => $ucId]);
} }
public function login(UserLogin $request) public function login(UserLogin $request)
...@@ -33,14 +32,12 @@ class AuthController extends Controller ...@@ -33,14 +32,12 @@ class AuthController extends Controller
'password', 'password',
]); ]);
$ucId = UserService::login($data); $user = UserService::login($data);
if (empty($ucId)) { if (empty($user)) {
$this->setError('账号和密码校验失败'); $this->setError('账号和密码校验失败');
} }
return $this->setSuccessData(['uc_id' => $user['uc_id'], 'user' => $user]);
return $this->setSuccessData(['uc_id' => $ucId]);
} }
} }
...@@ -18,14 +18,22 @@ class UserService ...@@ -18,14 +18,22 @@ class UserService
$ucId = UserModel::where('email', $data['email'])->value('uc_id'); $ucId = UserModel::where('email', $data['email'])->value('uc_id');
} }
if ($ucId) { if (!$ucId) {
return $ucId;
} else {
//去新增注册 //去新增注册
$data['create_time'] = time(); $data['create_time'] = time();
$ucId = UserModel::insertGetId($data); $ucId = UserModel::insertGetId($data);
} }
return $ucId; $user = UserModel::select([
'uc_id',
'mobile',
'email',
'create_time',
])->where('uc_id', $ucId)->first();
UserModel::where('uc_id', $user['uc_id'])->update(['last_login_time'], time());
return $user;
} }
//登录接口 //登录接口
...@@ -39,13 +47,18 @@ class UserService ...@@ -39,13 +47,18 @@ class UserService
$salt = UserModel::where('email', $data['email'])->value('salt'); $salt = UserModel::where('email', $data['email'])->value('salt');
$loginQuery->where('email', $data['email']); $loginQuery->where('email', $data['email']);
} }
if (empty($salt)) { if (empty($salt)) {
throw new InvalidRequestException('该账号不存在'); throw new InvalidRequestException('该账号不存在');
} }
$passwordHash = PasswordService::passwordHash($data['password'], $salt); $passwordHash = PasswordService::passwordHash($data['password'], $salt);
$user = $loginQuery->where('password', $passwordHash)->first(); $user = $loginQuery->select([
'uc_id',
'mobile',
'email',
'create_time',
])->where('password', $passwordHash)->first();
UserModel::where('uc_id', $user['uc_id'])->update(['last_login_time'], time());
return $user ?: []; return $user ?: [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment