作者 何书鹏
1 个管道 的构建 通过 耗费 4 秒

合并分支 'heshupeng' 到 'master'

app账号与pc端账号统一



查看合并请求 !168
... ... @@ -70,7 +70,7 @@ class User extends Api
Db::startTrans();
try {
$ret = $this->auth->register($username=get_order_sn(), $password, $email='', $mobile, []);
$ret = $this->auth->register($mobile, $password, $email='', $mobile, []);
// 记录每日注册数量
$statistic = Statistic::where('today',date('Y-m-d'))->find();
if($statistic){
... ... @@ -81,6 +81,8 @@ class User extends Api
'today' => date('Y-m-d')
]);
}
// 密码设置为明文,与pc端统一
$this->auth->getUser()->save(['password'=>$password]);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ... @@ -156,7 +158,7 @@ class User extends Api
Db::startTrans();
try {
$ret = $this->auth->register($username=get_order_sn(), $password, $email='', $mobile, []);
$ret = $this->auth->register($mobile, $password, $email='', $mobile, []);
$company = Company::create([
'user_id' => $this->auth->id,
'name' => $name,
... ... @@ -176,6 +178,8 @@ class User extends Api
'today' => date('Y-m-d')
]);
}
// 密码设置为明文,与pc端统一
$this->auth->getUser()->save(['password'=>$password]);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ... @@ -266,41 +270,27 @@ class User extends Api
$mobile = $this->request->param('mobile');
$password = $this->request->param('password');
empty($mobile) && $this->error('请输入手机号');
empty($mobile) && $this->error('请输入账号或手机号');
empty($password) && $this->error('请输入密码');
!Validate::regex($mobile, "^1\d{10}$") && $this->error('手机号格式不正确');
Db::startTrans();
try {
$ret = $this->auth->login($mobile, $password);
// 记录日活
$statistic = Statistic::where('today',date('Y-m-d'))->find();
if($statistic){
$statistic->save(['active_times' => $statistic->active_times+1]);
}else{
(new Statistic)->save([
'active_times' => 1,
'today' => date('Y-m-d')
]);
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->auth->logout();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->auth->logout();
$this->error($e->getMessage());
}
if ($ret) {
$this->auth->setAllowFields(['id', 'mobile', 'group_id']);
$data = ['userinfo' => $this->auth->getUserInfo()];
$this->success('登录成功', $data);
} else {
Db::rollback();
$this->error($this->auth->getError());
$field = Validate::regex($mobile, '/^1\d{10}$/') ? 'mobile' : 'username';
$user = \app\common\model\User::get([$field => $mobile]);
!$user && $this->error(__('Account is incorrect'));
$user->password != $password && $this->error(__('Password is incorrect'));
//直接登录会员
$this->auth->direct($user->id);
// 记录日活
$statistic = Statistic::where('today',date('Y-m-d'))->find();
if($statistic){
$statistic->save(['active_times' => $statistic->active_times+1]);
}else{
(new Statistic)->save([
'active_times' => 1,
'today' => date('Y-m-d')
]);
}
$this->auth->setAllowFields(['id', 'mobile', 'group_id']);
$data = ['userinfo' => $this->auth->getUserInfo()];
$this->success('登录成功', $data);
}
/**
... ... @@ -543,8 +533,6 @@ class User extends Api
if ($this->auth->password) {
$this->error('已设置过密码');
}
$salt = Random::alnum();
$password = $this->auth->getEncryptPassword($password, $salt);
$user_model = new \app\common\model\User();
$result = $user_model->update(['id' => $this->auth->id, 'password' => $password, 'salt' => $salt]);
if (!$result) {
... ... @@ -579,7 +567,9 @@ class User extends Api
Smslib::flush($mobile, 'resetpwd');
//模拟一次登录
$this->auth->direct($user->id);
$ret = $this->auth->changepwd($newpassword, '', true);
// $ret = $this->auth->changepwd($newpassword, '', true);
// 密码设置为明文,与pc端统一
$ret = $this->auth->getUser()->save(['password'=>$newpassword]);
if ($ret) {
$this->success('重置密码成功');
} else {
... ... @@ -688,6 +678,10 @@ class User extends Api
$sex = $this->request->param('sex');
if($username || $nickname || $image || in_array($sex,[0,1])) {
if ($username) {
$exists = \app\common\model\User::where('username', $username)->where('id', '<>', $this->auth->id)->find();
if ($exists) {
$this->error('用户名已存在');
}
$user->username = $username;
}
if ($nickname) {
... ...