|
@@ -33,7 +33,7 @@ class User extends Api
|
|
|
/**
|
|
|
* 会员登录
|
|
|
*
|
|
|
- * @param string $account 账号
|
|
|
+ * @param string $account 账号
|
|
|
* @param string $password 密码
|
|
|
*/
|
|
|
public function login()
|
|
@@ -55,7 +55,7 @@ class User extends Api
|
|
|
/**
|
|
|
* 手机验证码登录
|
|
|
*
|
|
|
- * @param string $mobile 手机号
|
|
|
+ * @param string $mobile 手机号
|
|
|
* @param string $captcha 验证码
|
|
|
*/
|
|
|
public function mobilelogin()
|
|
@@ -68,7 +68,8 @@ class User extends Api
|
|
|
if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
$this->error(__('Mobile is incorrect'));
|
|
|
}
|
|
|
- if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
|
|
|
+ $ret = session($mobile);
|
|
|
+ if (!$ret || $ret != $captcha) {
|
|
|
$this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
$user = \app\common\model\User::getByMobile($mobile);
|
|
@@ -97,9 +98,8 @@ class User extends Api
|
|
|
*
|
|
|
* @param string $password 密码
|
|
|
* @param string $group_id 身份012
|
|
|
-
|
|
|
- * @param string $mobile 手机号
|
|
|
- * @param string $code 验证码
|
|
|
+ * @param string $mobile 手机号
|
|
|
+ * @param string $code 验证码
|
|
|
*/
|
|
|
public function register()
|
|
|
{
|
|
@@ -120,9 +120,9 @@ class User extends Api
|
|
|
// $this->error('验证码出错 ');
|
|
|
// }
|
|
|
if (!$group_id) {
|
|
|
- $group_id = 0;
|
|
|
+ $group_id = 0;
|
|
|
}
|
|
|
- $ret = $this->auth->register($username, $password, '', $mobile, [],$group_id);
|
|
|
+ $ret = $this->auth->register($username, $password, '', $mobile, [], $group_id);
|
|
|
if ($ret) {
|
|
|
$data = ['userinfo' => $this->auth->getUserinfo()];
|
|
|
$this->success(__('Sign up successful'), $data);
|
|
@@ -143,10 +143,10 @@ class User extends Api
|
|
|
/**
|
|
|
* 修改会员个人信息
|
|
|
*
|
|
|
- * @param string $avatar 头像地址
|
|
|
+ * @param string $avatar 头像地址
|
|
|
* @param string $username 用户名
|
|
|
* @param string $nickname 昵称
|
|
|
- * @param string $bio 个人简介
|
|
|
+ * @param string $bio 个人简介
|
|
|
*/
|
|
|
public function profile()
|
|
|
{
|
|
@@ -176,43 +176,9 @@ class User extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 修改邮箱
|
|
|
- *
|
|
|
- * @param string $email 邮箱
|
|
|
- * @param string $captcha 验证码
|
|
|
- */
|
|
|
- public function changeemail()
|
|
|
- {
|
|
|
- $user = $this->auth->getUser();
|
|
|
- $email = $this->request->post('email');
|
|
|
- $captcha = $this->request->request('captcha');
|
|
|
- if (!$email || !$captcha) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }
|
|
|
- if (!Validate::is($email, "email")) {
|
|
|
- $this->error(__('Email is incorrect'));
|
|
|
- }
|
|
|
- if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
|
|
|
- $this->error(__('Email already exists'));
|
|
|
- }
|
|
|
- $result = Ems::check($email, $captcha, 'changeemail');
|
|
|
- if (!$result) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- $verification = $user->verification;
|
|
|
- $verification->email = 1;
|
|
|
- $user->verification = $verification;
|
|
|
- $user->email = $email;
|
|
|
- $user->save();
|
|
|
-
|
|
|
- Ems::flush($email, 'changeemail');
|
|
|
- $this->success();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 修改手机号
|
|
|
*
|
|
|
- * @param string $mobile 手机号
|
|
|
+ * @param string $mobile 手机号
|
|
|
* @param string $captcha 验证码
|
|
|
*/
|
|
|
public function changemobile()
|
|
@@ -244,42 +210,31 @@ class User extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 第三方登录
|
|
|
+ * 微信登录
|
|
|
*
|
|
|
- * @param string $platform 平台名称
|
|
|
- * @param string $code Code码
|
|
|
+ * @param string $code Code码
|
|
|
*/
|
|
|
+
|
|
|
public function third()
|
|
|
+
|
|
|
{
|
|
|
- $url = url('user/index');
|
|
|
- $platform = $this->request->request("platform");
|
|
|
- $code = $this->request->request("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);
|
|
|
+
|
|
|
+ $wchat = new WeChat();
|
|
|
+
|
|
|
+
|
|
|
+ $code = request()->param('code', "");
|
|
|
+
|
|
|
+ $user = $wchat->getUserAccessUserInfo($code);
|
|
|
+ dump($user);die;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 重置密码
|
|
|
*
|
|
|
- * @param string $mobile 手机号
|
|
|
+ * @param string $mobile 手机号
|
|
|
* @param string $newpassword 新密码
|
|
|
- * @param string $captcha 验证码
|
|
|
+ * @param string $captcha 验证码
|
|
|
*/
|
|
|
public function resetpwd()
|
|
|
{
|
|
@@ -292,42 +247,30 @@ class User extends Api
|
|
|
if (!$newpassword || !$captcha) {
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
- if ($type == 'mobile') {
|
|
|
- if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
- $this->error(__('Mobile is incorrect'));
|
|
|
- }
|
|
|
- $user = \app\common\model\User::getByMobile($mobile);
|
|
|
- if (!$user) {
|
|
|
- $this->error(__('User not found'));
|
|
|
- }
|
|
|
- $ret = session($mobile);
|
|
|
- if (!$ret || $ret!=$captcha) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- Sms::flush($mobile, 'resetpwd');
|
|
|
- } else {
|
|
|
- if (!Validate::is($email, "email")) {
|
|
|
- $this->error(__('Email is incorrect'));
|
|
|
- }
|
|
|
- $user = \app\common\model\User::getByEmail($email);
|
|
|
- if (!$user) {
|
|
|
- $this->error(__('User not found'));
|
|
|
- }
|
|
|
- $ret = Ems::check($email, $captcha, 'resetpwd');
|
|
|
- if (!$ret) {
|
|
|
- $this->error(__('Captcha is incorrect'));
|
|
|
- }
|
|
|
- Ems::flush($email, 'resetpwd');
|
|
|
+
|
|
|
+ if (!Validate::regex($mobile, "^1\d{10}$")) {
|
|
|
+ $this->error(__('Mobile is incorrect'));
|
|
|
+ }
|
|
|
+ $user = \app\common\model\User::getByMobile($mobile);
|
|
|
+ if (!$user) {
|
|
|
+ $this->error(__('User not found'));
|
|
|
+ }
|
|
|
+ $ret = session($mobile);
|
|
|
+
|
|
|
+ if (!$ret || $ret != $captcha) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
}
|
|
|
+
|
|
|
//模拟一次登录
|
|
|
$this->auth->direct($user->id);
|
|
|
- $ret = $this->auth->changepwd($newpassword, '', true);
|
|
|
- if ($ret) {
|
|
|
+ $rets = $this->auth->changepwd($newpassword, '', true);
|
|
|
+ if ($rets) {
|
|
|
$this->success(__('Reset password successful'));
|
|
|
} else {
|
|
|
$this->error($this->auth->getError());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 发送验证码
|
|
|
*
|
|
@@ -340,17 +283,17 @@ class User extends Api
|
|
|
$type = $this->request->param('type');
|
|
|
if (!isset($type) || empty($type)) return $this->error('参数错误');
|
|
|
|
|
|
- if ($type==1) {
|
|
|
- $issetphone = Db::name('user')->where('mobile',$mobile)->find();
|
|
|
+ if ($type == 1) {
|
|
|
+ $issetphone = Db::name('user')->where('mobile', $mobile)->find();
|
|
|
|
|
|
if (isset($issetphone)) return $this->error('此账号已存在');
|
|
|
}
|
|
|
if ($type == 3) {
|
|
|
$user = $this->auth->getUser();
|
|
|
|
|
|
- $isuseourphone = Db::name('user')->where('id',$user['id'])->where('mobile',$mobile)->find();
|
|
|
+ $isuseourphone = Db::name('user')->where('id', $user['id'])->where('mobile', $mobile)->find();
|
|
|
|
|
|
- if(!$isuseourphone) return $this->error('请使用本账号手机号修改密码');
|
|
|
+ if (!$isuseourphone) return $this->error('请使用本账号手机号修改密码');
|
|
|
}
|
|
|
$number = rand(1000, 9999);
|
|
|
session($mobile, $number);
|