Beispiel #1
0
 public function loginHandle($request, $response, $args)
 {
     // $data = $request->post('sdf');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     $rememberMe = $request->getParam('remember_me');
     // Handle Login
     $user = User::where('email', '=', $email)->first();
     if ($user == null) {
         $res['ret'] = 0;
         $res['error_code'] = self::UserNotExist;
         $res['msg'] = "邮箱或者密码错误";
         return $this->echoJson($response, $res);
     }
     if (!Hash::checkPassword($user->pass, $passwd)) {
         $res['ret'] = 0;
         $res['error_code'] = self::UserPasswordWrong;
         $res['msg'] = "邮箱或者密码错误";
         return $this->echoJson($response, $res);
     }
     // @todo
     $time = 3600 * 24;
     if ($rememberMe) {
         $time = 3600 * 24 * 7;
     }
     Logger::info("login user {$user->id} ");
     Auth::login($user->id, $time);
     $res['ret'] = 1;
     $res['msg'] = "欢迎回来";
     return $this->echoJson($response, $res);
 }
 public function loginHandle($request, $response, $next)
 {
     // $data = $request->post('sdf');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     $rememberMe = $request->getParam('remember_me');
     // Handle Login
     $user = User::where('email', '=', $email)->first();
     if ($user == null) {
         $rs['code'] = '0';
         $rs['msg'] = "401 邮箱或者密码错误";
         return $response->getBody()->write(json_encode($rs));
     }
     if ($user->pass != Hash::passwordHash($passwd)) {
         $rs['code'] = '0';
         $rs['msg'] = "402 邮箱或者密码错误";
         return $response->getBody()->write(json_encode($rs));
     }
     // @todo
     $time = 3600 * 24;
     if ($rememberMe) {
         $time = 3600 * 24 * 7;
     }
     Auth::login($user->id, $time);
     $rs['code'] = '1';
     $rs['ok'] = '1';
     $rs['msg'] = "欢迎回来";
     return $response->getBody()->write(json_encode($rs));
 }
Beispiel #3
0
        return redirect('/');
    }
});
Route::get('/setting', function () {
    Auth::login();
    if (Auth::checkAdmin()) {
        $controller = new \App\Http\Controllers\ControllerSetting();
        return $controller->init();
    } else {
        return redirect('/');
    }
});
Route::any('/api/{model?}.{method?}', function ($model = null, $method = null) {
    $controller = 'App\\Http\\Controllers\\Api\\ControllerApi' . ucfirst($model);
    try {
        App\Services\Auth::login();
        if (class_exists($controller)) {
            if (!method_exists($controller, $method)) {
                throw new \App\Exceptions\ExceptionApiMethodbad($model, $method, Request::all());
            }
            $ob = new $controller();
            $reflection = new ReflectionMethod($ob, $method);
            if (!$reflection->isPublic()) {
                throw new \App\Exceptions\ExceptionApiMethodbad($model, $method, Request::all());
            }
        } else {
            throw new \App\Exceptions\ExceptionApiTypebad($model, $method, Request::all());
        }
        if (!$ob instanceof App\Http\Controllers\Api\ControllerApi) {
            throw new \App\Exceptions\ExceptionApiTypebad($model, $method, Request::all());
        }
Beispiel #4
0
 public function auth()
 {
     $this->_methodName = 'auth';
     $this->resolveParams();
     $arNeed = ['email' => 'required|email|max:200', 'passwd' => 'required|min:8|max:32'];
     if (Auth::check()) {
         throw new \App\Exceptions\ExceptionApiAuthAlready(['email' => $this->_request_params['email']], $this->_typeName, $this->_methodName);
     }
     $this->checkAttr($arNeed);
     $auth_user = \App\Users::whereEmail($this->_request_params['email'])->first();
     if (is_null($auth_user)) {
         $auth_user = \App\Admin::whereEmail($this->_request_params['email'])->first();
         if (is_null($auth_user)) {
             throw new \App\Exceptions\ExceptionApiUserNotFound(['email' => $this->_request_params['email']], $this->_typeName, $this->_methodName);
         }
     }
     if (Hash::check($this->_request_params['passwd'], $auth_user->password)) {
         Auth::login($auth_user->email);
         $user = Auth::user();
         $this->_arData['data']['token'] = Auth::getToken();
         if (!$this->checkUserUnable() && !Auth::checkAdmin()) {
             $this->_arData['warning'] = 'NOT_FULL_USER_INFO';
         }
     } else {
         throw new \App\Exceptions\ExceptionApiAuthFail(['email' => $this->_request_params['email']], $this->_typeName, $this->_methodName);
     }
     return $this;
 }