|
@@ -18,7 +18,7 @@ use app\common\model\UserDeviceInfo;
|
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
|
|
+ protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
@@ -142,6 +142,41 @@ class User extends Api
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
+ //微信登录+注册
|
|
|
+ public function wechatlogin(){
|
|
|
+ $nickname = input('nickname','');
|
|
|
+ $avatar = input('avatar','');
|
|
|
+ $gender = input('gender',1);
|
|
|
+ $wechat_openid = input('wechat_openid','');
|
|
|
+
|
|
|
+ if (!$wechat_openid) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ if($gender != 1){
|
|
|
+ $gender = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = \app\common\model\User::getByOpenid($wechat_openid);
|
|
|
+ if ($user) {
|
|
|
+ if ($user->status != 1) {
|
|
|
+ $this->error(__('Account is locked'));
|
|
|
+ }
|
|
|
+ //如果已经有账号则直接登录
|
|
|
+ $ret = $this->auth->direct($user->id);
|
|
|
+ } else {
|
|
|
+ if (!$nickname || !$avatar) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ $reg_data = ['nickname'=>$nickname,'avatar'=>$avatar,'gender'=>$gender];
|
|
|
+ $ret = $this->auth->openid_register($wechat_openid,$reg_data);
|
|
|
+ }
|
|
|
+ if ($ret) {
|
|
|
+ $data = $this->userInfo('return');
|
|
|
+ $this->success(__('Logged in successful'), $data);
|
|
|
+ } else {
|
|
|
+ $this->error($this->auth->getError());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
//用户详细资料
|
|
@@ -360,7 +395,7 @@ class User extends Api
|
|
|
*/
|
|
|
public function profile()
|
|
|
{
|
|
|
- $field_array = ['nickname','introcode','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo'];
|
|
|
+ $field_array = ['nickname','introcode','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo','wechat_openid'];
|
|
|
|
|
|
$data = [];
|
|
|
foreach($field_array as $key => $field){
|
|
@@ -554,6 +589,41 @@ class User extends Api
|
|
|
Sms::flush($mobile, 'changemobile');
|
|
|
$this->success();
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 微信注册来的,绑定手机号
|
|
|
+ *
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string $mobile 手机号
|
|
|
+ * @param string $captcha 验证码
|
|
|
+ */
|
|
|
+ public function bindmobile()
|
|
|
+ {
|
|
|
+ $user = $this->auth->getUser();
|
|
|
+ $mobile = $this->request->request('mobile');
|
|
|
+ $captcha = $this->request->request('captcha');
|
|
|
+
|
|
|
+ if (!$mobile || !$captcha) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ $this->error(__('Mobile is incorrect'));
|
|
|
+ }
|
|
|
+ if (\app\common\model\User::where('mobile', $mobile)->find()) {
|
|
|
+ $this->error(__('Mobile already exist'));
|
|
|
+ }
|
|
|
+ $result = Sms::check($mobile, $captcha, 'changemobile');
|
|
|
+ if (!$result) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+ $verification = $user->verification;
|
|
|
+ $verification->mobile = 1;
|
|
|
+ $user->verification = $verification;
|
|
|
+ $user->mobile = $mobile;
|
|
|
+ $user->save();
|
|
|
+
|
|
|
+ Sms::flush($mobile, 'changemobile');
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 第三方登录
|