|
|
@@ -6,9 +6,14 @@ use app\common\controller\Api;
|
|
|
use app\common\library\Ems;
|
|
|
use app\common\library\Sms;
|
|
|
use app\common\model\Order as OrderModel;
|
|
|
+use app\common\model\User as UserModel;
|
|
|
use fast\Random;
|
|
|
+use think\Cache;
|
|
|
use think\Config;
|
|
|
+use think\Db;
|
|
|
use think\Env;
|
|
|
+use think\Exception;
|
|
|
+use think\Hook;
|
|
|
use think\Validate;
|
|
|
|
|
|
/**
|
|
|
@@ -16,7 +21,7 @@ use think\Validate;
|
|
|
*/
|
|
|
class User extends Api
|
|
|
{
|
|
|
- protected $noNeedLogin = ['login', 'mobilelogin', 'register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
|
|
|
+ protected $noNeedLogin = ['login', 'register', 'find_pwd_send_sms', 'verify_code', 'reset_pwd'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
|
@@ -200,6 +205,99 @@ class User extends Api
|
|
|
}
|
|
|
$this->error(__('资金密码重置失败'));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 找回密码发送验证码
|
|
|
+ * @return void
|
|
|
+ * @throws \think\Exception
|
|
|
+ */
|
|
|
+ public function find_pwd_send_sms()
|
|
|
+ {
|
|
|
+ $code = $this->request->post('country_code');
|
|
|
+ $mobile = $this->request->post('mobile');
|
|
|
+ $captcha = $this->request->post('captcha');
|
|
|
+
|
|
|
+ if(!captcha_check($captcha)){
|
|
|
+ $this->error(__('验证码错误'));
|
|
|
+ };
|
|
|
+
|
|
|
+ $user = UserModel::getByCodeAndMobile($code,$mobile);
|
|
|
+ if(empty($user)){
|
|
|
+ $this->error(__('手机号码不存在'));
|
|
|
+ }
|
|
|
+ if($user['is_lock']){
|
|
|
+ $this->error(__('账号锁定'));
|
|
|
+ }
|
|
|
+
|
|
|
+ (new \app\api\controller\Sms())->send_international_sms($user['code'], $user['mobile'], 'find_pwd');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function verify_code()
|
|
|
+ {
|
|
|
+ $country_code = $this->request->post('country_code');
|
|
|
+ $mobile = $this->request->post('mobile');
|
|
|
+ $code = $this->request->post('code');
|
|
|
+
|
|
|
+ $verify = (new \app\api\controller\Sms())->check($country_code, $mobile, $code, 'find_pwd');
|
|
|
+
|
|
|
+ if($verify){
|
|
|
+ $token = uniqid();
|
|
|
+ Cache::set($token, ['code' => $country_code, 'mobile' => $mobile], 60 * 10);//临时token缓存10分钟
|
|
|
+ $this->success('', $token);
|
|
|
+ }
|
|
|
+ $this->error(__('手机验证码错误'));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function reset_pwd()
|
|
|
+ {
|
|
|
+ $token = $this->request->post('token');
|
|
|
+ $new_pwd = $this->request->post("new_pwd", '', null);
|
|
|
+ $confirm_pwd = $this->request->post("confirm_pwd", '', null);
|
|
|
+
|
|
|
+ $rule = [
|
|
|
+ 'new_pwd' => 'require|regex:\S{6,30}',
|
|
|
+ 'confirm_pwd' => 'require|regex:\S{6,30}|confirm:new_pwd',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $msg = [
|
|
|
+ 'new_pwd.confirm' => __('Password and confirm password don\'t match')
|
|
|
+ ];
|
|
|
+ $data = [
|
|
|
+ 'new_pwd' => $new_pwd,
|
|
|
+ 'confirm_pwd' => $confirm_pwd,
|
|
|
+ ];
|
|
|
+ $field = [
|
|
|
+ 'new_pwd' => __('新资金密码'),
|
|
|
+ 'confirm_pwd' => __('新密码')
|
|
|
+ ];
|
|
|
+ $validate = new Validate($rule, $msg, $field);
|
|
|
+ $result = $validate->check($data);
|
|
|
+ if (!$result) {
|
|
|
+ $this->error(__($validate->getError()));
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = Cache::get($token);
|
|
|
+ if(empty($info)){
|
|
|
+ $this->error(__('操作超时'));
|
|
|
+ }
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $salt = Random::alnum();
|
|
|
+ $new_password = $this->auth->getEncryptPassword($new_pwd, $salt);
|
|
|
+ UserModel::where($info)
|
|
|
+ ->update([
|
|
|
+ 'login_pwd' => $new_password,
|
|
|
+ 'salt' => $salt
|
|
|
+ ]);
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ Cache::rm($token);//删除缓存
|
|
|
+ $this->success('');
|
|
|
+ }
|
|
|
/**
|
|
|
* 手机验证码登录
|
|
|
*
|