/** * Handle a login request to the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function postLogin(Request $request) { $usernames = $this->loginUsername(); if (!is_array($usernames)) { $usernames = [$usernames]; } $usernamesR = []; foreach ($usernames as $username) { $usernamesR[$username] = 'required'; } $this->validate($request, array_merge($usernamesR, ['password' => 'required'])); // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and // the IP address of the client making these requests into this application. $throttles = $this->isUsingThrottlesLoginsTrait(); if ($throttles && $this->hasTooManyLoginAttempts($request)) { return $this->sendLockoutResponse($request); } $credentials = $this->getCredentials($request); if ($token = JWTAuth::attempt($credentials, $this->customClaims())) { return $this->handleUserWasAuthenticated($request, $throttles, $token); } // If the login attempt was unsuccessful we will increment the number of attempts // to login and redirect the user back to the login form. Of course, when this // user surpasses their maximum number of attempts they will get locked out. if ($throttles) { $this->incrementLoginAttempts($request); } return new JsonResponse([implode('.', $usernames) => [$this->getFailedLoginMessage()]], 422); }
public function login(Request $request) { $data = $request->only('username', 'password'); $gcm_token = $request->get('gcm_token'); $throttler = Throttle::get($request, 5, 1); if (!$throttler->check()) { $response = Response(['error' => 'too many wrong requests']); $response->setStatusCode('420', "Enhance Your Calm"); return $response; } try { if (!($token = JWTAuth::attempt($data))) { // Invalid authentication, hit the throttler $throttler->hit(); return response()->json(['error' => true, 'message' => 'invalid_credentials'], 401); } // We have a google token, so let's set it if (null != $gcm_token) { $user = JWTAuth::toUser($token); $user->setGCMToken($gcm_token); $user->save(); } } catch (JWTException $e) { $throttler->hit(); return response()->json(['error' => true, 'message' => 'couldnt_create_token'], 401); } return response()->json(compact('token')); }
public function authenticate(Request $request) { // \Cache::flush(); // grab credentials from the request $credentials = $request->only('name', 'password'); try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['message' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['message' => 'could_not_create_token'], 500); } //cek double login $token = compact('token'); Input::merge(['token' => $token['token']]); $this->model = $this->model->where('name', $credentials['name'])->first(); if ($request->get('name') != 'admin') { //user is login $tempStorage = app('\\App\\Http\\Controllers\\TEMPStorage\\UserTempStorage'); if (!empty($tempStorage->get('id_company', $this->model->id))) { return response()->json(['message' => trans('user_already_login')], 500); } } // all good so return the token $this->model->update(['login' => 1]); $data = json_decode($this->item($this->model, $this->transformer)->morph()->getContent(), true) + $token; return $this->response->array($data)->withHeader('Content-Type', 'application/json'); // return response()->json(compact('token')); }
/** * Autheticate user using email and password * @param Request $request * @return array */ public function authenticate(Request $request) { # validate the request $validator = Validator::make($request->all(), ['email' => 'required|email', 'password' => 'required|min:6']); if ($validator->fails()) { return jsend()->error()->message('Invalid Input')->errors($validator->errors()->all())->get(); } # grab credentials from the request $credentials = $request->only('email', 'password'); # verify that the email does not belong to a provider $user = User::where(['email' => $credentials['email']])->first(); if (!empty($user->provider)) { return jsend()->error()->message('E-Mail has been registered using ' . $user->provider)->errors($validator->errors()->all())->get(); } try { # attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return jsend()->error()->message('Invalid Credentials. Login Failed.')->get(); } } catch (JWTException $e) { # Something went wrong whilst attempting to encode the token return jsend()->error()->message('Could not create token.')->errors([$e->getMessage()])->get(); } $user = Auth::user(); if ($user->verified) { # All good so return the token return jsend()->success()->message('User logged in successfully')->data(['user' => $user, 'api-token' => $token])->get(); } else { # User not verified yet return jsend()->error()->message('Account Activation Pending. Please check your E-Mail.')->get(); } }
public function signin() { $credentials = Input::only('email', 'password'); if (!($token = JWTAuth::attempt($credentials))) { return Response::json(false, HttpResponse::HTTP_UNAUTHORIZED); } return Response::json(compact('token')); }
public function postLogin(Request $request) { $credentials = $request->only('email', 'password'); $token = JWTAuth::attempt($credentials); if (!$token) { return response()->json('Incorrect username or password combination.', Response::HTTP_UNAUTHORIZED); } return response()->json(compact('token')); }
/** * @param SigninRequest $request * @return mixed */ public function signin(SigninRequest $request) { $credentials = $request->only('email', 'password'); if (!($token = JWTAuth::attempt($credentials))) { return $this->response->withError('Combinaison email / mot de passe érronée', 401); } $user = Auth::user(); // if no errors are encountered we can return a JWT return $this->response->array(['token' => $token, 'user' => $user->toArray()]); }
/** * Token-based Authentication login. * * @param LoginUserRequest $request * * @return Response * * @api {post} /v1/auth/login User Login * @apiVersion 1.0.0 * @apiName AuthLogin * @apiGroup Authentication * * @apiParam {String} email Email of the User. * @apiParam {String} Password Password of the User. * * @apiSuccess {String} token Authentication token. * * @apiUse ApiLimitError */ public function login(LoginUserRequest $request) { $credentials = $request->only(['email', 'password']); try { if (!($token = JWTAuth::attempt($credentials))) { return $this->response->errorUnauthorized(); } } catch (JWTException $e) { return $this->response->error('could_not_create_token', 500); } return response()->json(compact('token')); }
public function login(Request $request) { $credentials = $request->only('email', 'password'); try { if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { return response()->json(['error' => 'could_not_create_token'], 500); } return response()->json(compact('token')); }
public function testLogout() { $credentials = ['email' => '*****@*****.**', 'password' => '123456']; $token = JWTAuth::attempt($credentials); $this->assertEquals('*****@*****.**', Auth::user()->email); $res = $this->call('POST', '/auth/logout', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); $this->assertEquals(204, $res->getStatusCode()); $this->assertNull(Auth::user()); // check re-logout $res = $this->call('POST', '/auth/logout', [], [], [], ['HTTP_Authorization' => "Bearer {$token}"]); $this->assertEquals(401, $res->getStatusCode()); }
/** * Authenticate the user using JWT. * * @param AuthJwtRequest $request * @return $this|\Illuminate\Http\JsonResponse */ public function authenticate(AuthJwtRequest $request) { $credentials = $request->only(['email', 'password']); // Attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { $response = $this->response->error(ResponseCode::UNAUTHORIZED, trans('texts.invalid_credentials')); } else { $data = ['token' => $token, 'user' => JWTAuth::authenticate($token)]; $response = $this->response->ok($data); } return $response; }
protected function signin(Request $request) { $credentials = $request->only('email', 'password'); try { if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'Could not log you in.'], 401); } } catch (\Tymon\JWTAuth\Exceptions\JWTException $e) { return response()->json(['error' => 'Could not create token.'], 500); } return response()->json(compact('token')); }
public function authenticate(Request $request) { $user = User::where('email', $request->email)->first(); if (!$user) { throw new BadRequestHttpException('Invalid credentials'); } $customClaims = ['name' => $user->name, 'email' => $user->email, 'role' => $user->role, 'gravatar' => $user->gravatar]; $token = JWTAuth::attempt($request->only('email', 'password'), $customClaims); if (!$token) { throw new BadRequestHttpException('Invalid credentials'); } return api_response(200, compact('token')); }
function authenticate(Request $request) { $credentials = $request->only('email', 'password'); try { if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { return response()->json(['error' => 'could_not_create_token'], 500); } // if no errors are encountered we can return a JWT return response()->json(compact('token')); }
public function postLogin(Request $request) { $credentials = $request->only('email', 'password'); try { Auth::attempt($credentials); // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['error' => 'could_not_create_token'], 500); } return Response::json(['token' => $token, 'data' => $this->transform(Auth::user())], 200); }
/** * API Login, on success return JWT Auth token * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function login(Request $request) { $credentials = $request->only('email', 'password'); try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['error' => 'could_not_create_token'], 500); } // all good so return the token return response()->json(compact('token')); }
public function postLogin(Request $req) { $credentials = $req->only('email', 'password'); try { // verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong return response()->json(['error' => 'could_not_create_token'], 500); } // if no errors are encountered we can return a JWT return response()->json(compact('token')); }
protected function login(Request $request) { $this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required']); $throttles = $this->isUsingThrottlesLoginsTrait(); if ($throttles && $this->hasTooManyLoginAttempts($request)) { return $this->sendTokenLockoutResponse($request); } $credentials = $this->getCredentials($request); if ($token = JWTAuth::attempt($credentials)) { return $this->tokenWasAuthenticated($request, $token); } if ($throttles) { $this->incrementLoginAttempts($request); } return $this->sendFailedLoginResponse($request); }
/** * Autentica usuario * * @return \Illuminate\Http\Response */ public function authenticate(Request $request) { $credentials = $request->only('email', 'password'); $user = null; try { // verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong return response()->json(['error' => 'could_not_create_token'], 500); } $response = ['token' => $token, 'user' => app('auth')->user()]; return response()->json($response); }
public function login(Request $request) { $credentials = $request->only(['email', 'password']); $validator = Validator::make($credentials, ['email' => 'required', 'password' => 'required']); if ($validator->fails()) { throw new ValidationHttpException($validator->errors()->all()); } try { if (!($token = JWTAuth::attempt($credentials))) { return $this->response->errorUnauthorized(); } } catch (JWTException $e) { return $this->response->error('could_not_create_token', 500); } return response()->json(compact('token')); }
/** * @api {post} /auth/login 登录 */ public function login(Request $request) { // grab credentials from the request $credentials = $request->only('username', 'password'); try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return responseWrong('账号或密码错误'); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return responseWrong('token创建失败'); } // all good so return the token return response()->json(compact('token')); }
/** * login a user into the application using oauth * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function login(Request $request) { //dd(Hash::make('secret')); $credentials = $request->only('username', 'password'); try { if (!($token = JWTAuth::attempt($credentials))) { // if the user entered invalid credentials return response()->json(['error' => 'invalid_credentials', 401]); } } catch (JWTException $e) { // if there was an jwt error encountered return response()->json(['error' => 'could_not_create_token'], 500); } // if every thing went OK return response()->json(compact('token'), 200); }
public function postAuthenticate(Request $request) { $credentials = $request->only('username', 'password'); try { // verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong return response()->json(['error' => 'could_not_create_token'], 500); } $user = Ulibier::where('username', $credentials['username'])->get(); // if no errors are encountered we can return a JWT return response()->json(compact('token', 'user')); }
public function authenticate(Request $request) { // agarrar credenciais do pedido $credentials = $request->only('email', 'password'); try { // tentar verificar as credenciais e criar um token para o usuário if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'credenciais_inválidas'], 401); } } catch (JWTException $e) { // algo deu errado enquanto tenta codificar o token return response()->json(['error' => 'não_poderia_criar_token'], 500); } // tudo de bom assim retornar o token return response()->json(compact('token')); }
public function login() { // Get credentials from the request $credentials = Input::only('email', 'password'); try { // Attempt to verify the credentials and create a token for the user. if (!($token = JWTAuth::attempt($credentials))) { return API::response()->array(['error' => 'invalid_credentials'])->statusCode(401); } } catch (JWTException $e) { // Something went wrong - let the app know. return API::response()->array(['error' => 'could_not_create_token'])->statusCode(500); } // Return success. return compact('token'); }
public function login($domain, Request $request) { // grab credentials from the request $credentials = $request->only('email', 'password'); try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'Email hoặc Password không đúng'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['error' => 'could_not_create_token'], 500); } $user = User::where('email', $credentials['email'])->first(); // all good so return the token return response()->json(['token' => compact('token')['token'], 'user' => $user]); }
public function authenticate(Request $request) { // grab credentials from the request $credentials = $request->only('email', 'password'); try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'Invalid credentials'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['error' => 'Could not create token'], 500); } Auth::user()->api_token = $token; Auth::user()->save(); // all good so return the token return response()->json(compact('token')); }
public function authenticate(Request $request) { $credentials = $request->only('username', 'password'); if ($credentials['username'] == '' or $credentials['password'] == '') { return response()->json(['error' => 'Usuario o Contraseña Incorrectas'], 401); } try { // verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'Usuario o Contraseña Incorrectas'], 500); } } catch (JWTException $e) { // something went wrong return response()->json(['error' => 'could_not_create_token'], 500); } // if no errors are encountered we can return a JWT return response()->json(compact('token')); }
public function login(LoginRequest $request) { // grab credentials from the request $credentials = $request->only('email', 'password'); $claims = ['company' => 'Worklemon']; try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials, $claims))) { return $this->apiResponse(401, ['message' => LOGIN_INVALID_CREDENTIALS, 'error' => 'invalid_credentials']); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return $this->apiResponse(400, ['message' => LOGIN_TOKEN_FAIL]); } catch (\Exception $e) { return $this->apiResponse(400, ['message' => LOGIN_FAIL]); } // all good so return the token return $this->apiResponse(200, ['message' => TOKEN_CREATED, 'token' => $token]); }
/** * Handle a login request to the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function postLogin(Request $request) { try { $this->validate($request, ['email' => 'required|email|max:255', 'password' => 'required']); } catch (HttpResponseException $e) { return response()->json(['error' => ['message' => 'Invalid auth', 'status_code' => IlluminateResponse::HTTP_BAD_REQUEST]], IlluminateResponse::HTTP_BAD_REQUEST, $headers = []); } $credentials = $this->getCredentials($request); try { // attempt to verify the credentials and create a token for the user if (!($token = JWTAuth::attempt($credentials))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { // something went wrong whilst attempting to encode the token return response()->json(['error' => 'could_not_create_token'], 500); } // all good so return the token return response()->json(compact('token')); }