|
@@ -36,27 +36,7 @@ class User extends Api
|
|
|
$this->success('', ['welcome' => $this->auth->nickname]);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 会员登录
|
|
|
- *
|
|
|
- * @param string $account 账号
|
|
|
- * @param string $password 密码
|
|
|
- */
|
|
|
- public function login()
|
|
|
- {
|
|
|
- $account = $this->request->request('account');
|
|
|
- $password = $this->request->request('password');
|
|
|
- if (!$account || !$password) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- $ret = $this->auth->login($account, $password);
|
|
|
- if ($ret) {
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
- $this->success(__('Logged in successful'), $data);
|
|
|
- } else {
|
|
|
- $this->error($this->auth->getError());
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 手机验证码登录
|
|
@@ -179,39 +159,6 @@ class User extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 注册会员
|
|
|
- *
|
|
|
- * @param string $username 用户名
|
|
|
- * @param string $password 密码
|
|
|
- * @param string $email 邮箱
|
|
|
- * @param string $mobile 手机号
|
|
|
- * @param string $code 验证码
|
|
|
- */
|
|
|
- public function register()
|
|
|
- {
|
|
|
- $username = input('username');
|
|
|
- $password = input('password');
|
|
|
- $mobile = input('mobile');
|
|
|
- $code = input('code');
|
|
|
- if (!$username || !$password) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
- $this->error(__('Mobile is incorrect'));
|
|
|
- }
|
|
|
-// $ret = Sms::check($mobile, $code, 'register');
|
|
|
-// if (!$ret) {
|
|
|
-// $this->error(__('Captcha is incorrect'));
|
|
|
-// }
|
|
|
- $ret = $this->auth->register($username, $password, $mobile, []);
|
|
|
- if ($ret) {
|
|
|
- $data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
- $this->success(__('Sign up successful'), $data);
|
|
|
- } else {
|
|
|
- $this->error($this->auth->getError());
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 退出登录
|
|
@@ -332,36 +279,7 @@ class User extends Api
|
|
|
$this->success("手机号更换成功!");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 第三方登录
|
|
|
- *
|
|
|
- * @param string $platform 平台名称
|
|
|
- * @param string $code Code码
|
|
|
- */
|
|
|
- public function third()
|
|
|
- {
|
|
|
- $url = url('user/index');
|
|
|
- $platform = input("platform");
|
|
|
- $code = input("code");
|
|
|
- $config = get_addon_config('third');
|
|
|
- if (!$config || !isset($config[$platform])) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- $app = new \addons\third\library\Application($config);
|
|
|
- //通过code换access_token和绑定会员
|
|
|
- $result = $app->{$platform}->getUserInfo(['code' => $code]);
|
|
|
- if ($result) {
|
|
|
- $loginret = \addons\third\library\Service::connect($platform, $result);
|
|
|
- if ($loginret) {
|
|
|
- $data = [
|
|
|
- 'userinfo' => $this->auth->getUserinfo(),
|
|
|
- 'thirdinfo' => $result
|
|
|
- ];
|
|
|
- $this->success(__('Logged in successful'), $data);
|
|
|
- }
|
|
|
- }
|
|
|
- $this->error(__('Operation failed'), $url);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 重置密码
|
|
@@ -778,19 +696,21 @@ class User extends Api
|
|
|
|
|
|
//微信登录,预先假注册
|
|
|
public function wechatlogin(){
|
|
|
-
|
|
|
- $code = $this->request->param('code','');
|
|
|
+ $code = input('code','');
|
|
|
if(!$code){
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
//微信
|
|
|
$wechat = new Wechat();
|
|
|
+ $wxuserinfo = $wechat->getAccessToken($code);
|
|
|
|
|
|
- $wxuserinfo = $wechat->getwxuserinfo($code);
|
|
|
- Log::error('code:'.$code.',wxuserinfo:'.json_encode($wxuserinfo));
|
|
|
if(!$wxuserinfo){
|
|
|
$this->error('openid获取失败');
|
|
|
}
|
|
|
+ if(!is_array($wxuserinfo) || !isset($wxuserinfo['openid'])){
|
|
|
+ $this->error('openid获取失败');
|
|
|
+ }
|
|
|
+
|
|
|
$openid = $wxuserinfo['openid'];
|
|
|
|
|
|
$user = Db::name('user')->where('openid',$openid)->find();
|