12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace app\api\controller;
- use app\api\model\UsersModel;
- use app\common\controller\Api;
- use think\Cache;
- use think\Controller;
- use think\Db;
- use think\exception\HttpResponseException;
- use think\Request;
- use think\Response;
- /**
- * 忘记密码
- */
- class Forgetpwd extends Controller
- {
- protected $noNeedRight = '*';
- protected $noNeedLogin = '*';
- /**
- * 忘记密码
- * @ApiMethod (POST)
- * @param string $user_tel 用户手机号
- * @param string $user-pwd 密码
- * @param string $code 验证码
- */
- public function forgetPwd()
- {
- $params = $this->request->post();
- $check = '/^(1(([35789][0-9])|(47)))\d{8}$/';
- if (!preg_match($check, $params['user_tel'])) {
- return json(['code' => 100, 'msg' => '手机号不合法','data' => []]);
- }
- $is_tel = UsersModel::where('user_tel',$params['user_tel'])->find();
- if (!$is_tel) {
- return json(['code' => 100, 'msg' => '密码相同','data' => []]);
- }
- if (!Cache::get($params['code'])) {
- return json(['code' => 100, 'msg' => '验证码错误','data' => []]);
- }
- if (!isset($params['user_pwd']) || !isset($params['code'])) {
- return json(['code' => 100, 'msg' => '密码相同','data' => []]);
- }
- $params['user_pwd'] = sha1(md5($params['user_pwd']));
- //验证密码是否已存在
- $is_pwd = Db::name('users')->where('user_tel',$params['user_tel'])->where('user_pwd', $params['user_pwd'])->find();
- if ($is_pwd) {
- return json(['code' => 100, 'msg' => '密码相同','data' => []]);
- }
- $updPwd = Db::name('users')->where('user_tel',$params['user_tel'])->update(['user_pwd' => $params['user_pwd']]);
- if ($updPwd) {
- Cache::rm($params['code']);
- return json(['code' => 200, 'msg' => '修改成功','data' => []]);
- } else {
- return json(['code' => 100, 'msg' => '修改失败','data' => []]);
- }
- }
- }
|