Commit 17b8616e by 杨树贤

最后登录时间

parent de81acba
......@@ -20,9 +20,8 @@ class AuthController extends Controller
'salt',
]);
$ucId = UserService::register($data);
return $this->setSuccessData(['uc_id' => $ucId]);
$user = UserService::register($data);
return $this->setSuccessData(['uc_id' => $user['uc_id'], 'user' => $user]);
}
public function login(UserLogin $request)
......@@ -33,14 +32,12 @@ class AuthController extends Controller
'password',
]);
$ucId = UserService::login($data);
$user = UserService::login($data);
if (empty($ucId)) {
if (empty($user)) {
$this->setError('账号和密码校验失败');
}
return $this->setSuccessData(['uc_id' => $ucId]);
return $this->setSuccessData(['uc_id' => $user['uc_id'], 'user' => $user]);
}
}
......@@ -18,14 +18,22 @@ class UserService
$ucId = UserModel::where('email', $data['email'])->value('uc_id');
}
if ($ucId) {
return $ucId;
} else {
if (!$ucId) {
//去新增注册
$data['create_time'] = time();
$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
$salt = UserModel::where('email', $data['email'])->value('salt');
$loginQuery->where('email', $data['email']);
}
if (empty($salt)) {
throw new InvalidRequestException('该账号不存在');
}
$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 ?: [];
......
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