Exemplo n.º 1
0
 public function refreshResetCode()
 {
     $phone = request()->input('username');
     $result = API::refreshResetPassportVerifyCode($phone);
     if (isset($result['error'])) {
         return response()->json($result);
     }
     session(['resetRecord' => ['phone' => $phone, 'verifyCode' => $result['data']['code']]]);
     return response()->json([]);
 }
Exemplo n.º 2
0
 public function handle($request, Closure $next, $guard = null)
 {
     if (!API::isLogin()) {
         if (Request::is('api-data/*')) {
             return response()->json(['error' => ['message' => 'need login']]);
         } else {
             return redirect()->route('login');
         }
     }
     return $next($request);
 }
Exemplo n.º 3
0
 public function handle($request, Closure $next, $guard = null)
 {
     if (API::isLogin()) {
         if (Request::is('api-data/*')) {
             return response()->json(['error' => ['message' => 'Illegal request']]);
         } else {
             return abort(403);
         }
     }
     return $next($request);
 }
Exemplo n.º 4
0
 public function reset()
 {
     $requestData = request()->only('pwd', 'confirm-pwd', 'verify-code', 'passport');
     $params = ['passport' => $requestData['passport'], 'code' => $requestData['verify-code'], 'password' => $requestData['pwd'], 'confirmPassword' => $requestData['confirm-pwd']];
     $result = API::resetPassword($params);
     if (!isset($result['error'])) {
         // session里写入数据,防止重置成功页面被重复刷新
         session()->flash('resetPasswordFlag', 'true');
         $result['data']['redirect'] = route('reset-success');
     }
     return response()->json($result);
 }
Exemplo n.º 5
0
 public function forgetValidate()
 {
     if (!request()->has('username') || !request()->isMethod('post')) {
         return abort(403);
     }
     $passport = request()->input('username');
     if (preg_grep('/^1[0-9]{10}$/', [$passport])) {
         return view('forget-phone-validate')->with(['passport' => $passport]);
     } else {
         $result = API::refreshResetPassportVerifyCode($passport);
         // 发送验证邮件失败
         if (isset($result['error'])) {
             return view('forget-email-error', ['message' => $result['error']['message']]);
         }
         session(['resetRecord' => ['email' => $passport, 'verifyCode' => $result['data']['code']]]);
         return view('forget-email-validate')->with(['passport' => $passport]);
     }
 }
Exemplo n.º 6
0
        return self::request('POST', self::HOST . 'user/user/resetPassword ', ['form_params' => $data]);
    }
    private static function request($method, $url, $params = null)
    {
        try {
            $res = self::$client->request($method, $url, $params);
            $data = (string) $res->getBody();
            $res = json_decode($data, true);
        } catch (RequestException $e) {
            if ($e->hasResponse()) {
                $res = json_decode((string) $e->getResponse()->getBody(), true);
            } else {
                return ['error' => ['message' => 'api error']];
            }
        }
        return self::formatResult($res);
    }
    private static function formatResult($res)
    {
        if (isset($res['error'])) {
            return $res;
        } else {
            if ($res['status'] === 0) {
                return ['error' => ['message' => $res['message']]];
            }
        }
        return ['data' => $res];
    }
}
API::__init();