Commit 032938a9 by 杨树贤

优化无密码登录

parent 70569f70
...@@ -27,7 +27,7 @@ class UserRegister extends FormRequest ...@@ -27,7 +27,7 @@ class UserRegister extends FormRequest
public function rules() public function rules()
{ {
return [ return [
'password' => 'required', //'password' => 'required',
//'salt' => 'required', //'salt' => 'required',
'mobile' => 'required_without:email', 'mobile' => 'required_without:email',
'email' => 'required_without:mobile', 'email' => 'required_without:mobile',
......
...@@ -19,7 +19,9 @@ class UserService ...@@ -19,7 +19,9 @@ class UserService
} }
if (!$ucId) { if (!$ucId) {
$data['password'] = PasswordService::passwordHash($data['password'],$data['salt']); if (!empty($data['password'])) {
$data['password'] = PasswordService::passwordHash($data['password'],$data['salt']);
}
//去新增注册 //去新增注册
$data['create_time'] = time(); $data['create_time'] = time();
$ucId = UserModel::insertGetId($data); $ucId = UserModel::insertGetId($data);
...@@ -53,8 +55,10 @@ class UserService ...@@ -53,8 +55,10 @@ class UserService
} }
$salt = $exists->salt; $salt = $exists->salt;
$passwordHash = '';
$passwordHash = PasswordService::passwordHash($data['password'], $salt); if ($data['password']) {
$passwordHash = PasswordService::passwordHash($data['password'], $salt);
}
$user = $loginQuery->select([ $user = $loginQuery->select([
'uc_id', 'uc_id',
'mobile', 'mobile',
...@@ -84,7 +88,7 @@ class UserService ...@@ -84,7 +88,7 @@ class UserService
//绑定手机 //绑定手机
public static function bindMobile($ucId, $mobile) public static function bindMobile($ucId, $mobile)
{ {
//先去判断这个email是否已经被其它账号使用了 //先去判断这个手机号是否已经被其它账号使用了
$exists = UserModel::where('uc_id', '!=', $ucId)->where('mobile', $mobile)->exists(); $exists = UserModel::where('uc_id', '!=', $ucId)->where('mobile', $mobile)->exists();
if ($exists) { if ($exists) {
throw new InvalidRequestException('该手机号已经被其它账户绑定了,请确认后重新提交'); throw new InvalidRequestException('该手机号已经被其它账户绑定了,请确认后重新提交');
......
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