|
@@ -17,7 +17,7 @@ use wxpay;
|
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third', 'getopenid', 'getagreement', 'wxlogin'];
|
|
|
+ protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'registercheck', 'resetpwd', 'changeemail', 'changemobile', 'third', 'getopenid', 'getagreement', 'wxlogin', 'mobileloginregister'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
@@ -2183,4 +2183,32 @@ class User extends Api
|
|
|
|
|
|
$this->success('联系我们', $data);
|
|
|
}
|
|
|
+
|
|
|
+ //手机号登录/注册
|
|
|
+ public function mobileloginregister() {
|
|
|
+ $mobile = $this->request->post('mobile');
|
|
|
+ if (!$mobile) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ $this->error(__('Mobile is incorrect'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = \app\common\model\User::getByMobile($mobile);
|
|
|
+ if ($user) {
|
|
|
+ if ($user->status != 1) {
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
+ }
|
|
|
+ //如果已经有账号则直接登录
|
|
|
+ $ret = $this->auth->direct($user->id);
|
|
|
+ } else {
|
|
|
+ $ret = $this->auth->register($mobile, Random::alnum(), '', $mobile, []);
|
|
|
+ }
|
|
|
+ if ($ret) {
|
|
|
+ $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
+ $this->success(__('Logged in successful'), $data);
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|