作者:Worklemo
项目:ap
public function __construct()
{
$this->app_list_limit = env('APP_LIST_LIMIT', 50);
$token = JWTAuth::getToken();
if (!empty($token)) {
$user = JWTAuth::toUser($token);
$this->logged_user = User::find($user->id);
}
}
作者:masmik
项目:scafoldin
public function inValidateToken()
{
$tempStorage = app('\\App\\Http\\Controllers\\TEMPStorage\\UserTempStorage');
$tempStorage->forget('id_company');
//set model login
$user = JWTAuth::parseToken()->authenticate();
$this->model->find($user->id)->update(['login' => 0]);
JWTAuth::invalidate(JWTAuth::getToken());
return API::response()->array(['message' => 'success'])->statusCode(200);
}
作者:raspara
项目:diplomsk
public function __construct(User $user, Project $project, Invitation $invitation)
{
$this->loggedUser = JWTAuth::parseToken()->authenticate();
$this->user = $user;
$this->project = $project;
$this->invitation = $invitation;
}
作者:antoniopachec
项目:CECINTRANET-AP
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $aplicacion)
{
$metodo = $request->method();
$user = JWTAuth::parseToken()->authenticate();
switch ($metodo) {
case 'GET':
$tipo_permiso = 1;
break;
case 'POST':
$tipo_permiso = 2;
break;
case 'PUT':
$tipo_permiso = 2;
break;
case 'DELETE':
$tipo_permiso = 2;
break;
}
$privilegios = Privilegio::with('aplicacion')->where('user_id', $user->id)->where('aplicacion_id', $aplicacion);
if ($tipo_permiso == 1) {
$privilegios = $privilegios->where(function ($query) {
$query->where('privilegios_tipo_id', 1)->orWhere('privilegios_tipo_id', 2);
});
} else {
$privilegios = $privilegios->where('privilegios_tipo_id', $tipo_permiso);
}
$privilegios = $privilegios->first();
if ($privilegios) {
return $next($request);
} else {
return response('Unauthorized.', 401);
}
}
作者:thecse
项目:jwt-aut
/**
* 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);
}
作者:amteknolog
项目:e-commerc
/**
* Permintaan refresh token
*
* @param Request $request
* @return array
*/
public function refreshToken(Request $request)
{
$this->middleware('auth');
$user = app('auth')->user();
$newToken = JWTAuth::parseToken()->refresh();
return ['status' => 'success', 'user' => $user, 'token' => $newToken];
}
作者:zenoZ
项目:laravelap
protected function me()
{
if ($token = JWTAuth::getToken()) {
return JWTAuth::parseToken()->toUser();
}
return false;
}
作者:jubaedprinc
项目:nohunchAP
public function addPoint(Request $request)
{
$user = JWTAuth::parseToken()->authenticate();
$user->points = $user->points + $request->input('amount');
$user->save();
return response()->json(['success' => true, 'message' => "Users points added", 'users' => $user]);
}
作者:everdanie
项目:vue-starter-laravel-ap
public function register(UserRequest $request)
{
$newUser = ['name' => $request->get('name'), 'email' => $request->get('email'), 'password' => bcrypt($request->get('password'))];
$user = User::create($newUser);
$token = JWTAuth::fromUser($user);
return response()->json(compact('token'));
}
作者:B1naryStudi
项目:ascii
public function getUserFromCookie($cookie)
{
$tokenObject = new Token($cookie);
// Get a payload info from the token
try {
$payload = JWTAuth::decode($tokenObject);
} catch (TokenExpiredException $e) {
$message = 'Token in cookie was expired';
throw new TokenInCookieExpiredException($message, null, $e);
}
// Get user by the payload info
try {
$user = $this->userUpdater->updateBaseInfo($payload);
} catch (RepositoryException $e) {
throw new AuthException($e->getMessage(), null, $e);
}
// Attempt to update his profile by API or just log the error
try {
$user = $this->userUpdater->updateAdditionalInfo($cookie, $user);
} catch (UpdatingFailureException $e) {
Log::warning('An additional user information was\'nt updated. ' . $e->getMessage());
}
// Login
Auth::login($user, true);
// Return an actual user model if login passes
if (Auth::check()) {
return $this->userRepository->findWithRelations(Auth::id(), ['localRole']);
} else {
throw new AuthException('Login error. User is not authorized.');
}
}
作者:adiachenk
项目:catchy_ap
public function index(FacebookAuthentication $request, FacebookGraphClient $client, FacebookUserResolver $resolver)
{
$data = $client->init($request->token)->getUser(['id', 'email', 'first_name', 'last_name']);
$user = $resolver->findOrCreateUser($data);
$customClaims = ['name' => $user->name, 'email' => $user->email, 'role' => $user->role, 'gravatar' => $user->gravatar];
return api_response(200, ['token' => JWTAuth::fromUser($user, $customClaims)]);
}
作者:a1ex
项目:ascii
/**
* Display a listing of the resource.
*
* @return Response
*/
public function auth(Request $request)
{
$customClaims = ['id' => '55dc13391846c68a1ad56daa', 'email' => 'admin@admin', 'role' => 'ADMIN', 'iat' => 1440615292];
$payload = JWTFactory::make($customClaims);
$data = JWTAuth::encode($payload);
$redirectPath = $request->cookie('referer');
return Redirect::to($redirectPath, 303)->withCookie('x-access-token', $data->get())->withCookie('serverUID', '55dc13391846c68a1ad56daa');
}
作者:BinaryStudioAcadem
项目:review
/**
* Display a listing of the resource.
*
* @return Response
*/
public function auth(Request $request)
{
$userData = $this->currentUser->payloadInfo;
$payload = JWTFactory::make($userData);
$data = JWTAuth::encode($payload);
$redirectPath = $request->cookie('referer');
return Redirect::to($redirectPath, 303)->withCookie('x-access-token', $data->get())->withCookie('serverUID', $userData['id']);
}
作者:BaptisteDixneu
项目:laravel-angularjs-jw
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'));
}
作者:fredlaw
项目:planebox-ap
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'));
}
作者:developscrip
项目:laravel-with-angula
public function postRegister(Request $request)
{
$validator = $this->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}
$token = JWTAuth::fromUser($this->create($request->all()));
return response()->json(['token' => $token]);
}
作者:S4M3
项目:Project_GangOfThre
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (count(Enseignant_Privilege::where(function ($query) {
$query->where('id_Enseignant', '=', JWTAuth::parseToken()->toUser()->id_Enseignant)->where('id_Privilege', '=', '7');
})->get()) > 0) {
return $next($request);
} else {
return Response::json(['error' => 'Permission denied'], HttpResponse::HTTP_UNAUTHORIZED);
}
}
作者:JolitaGrazyt
项目:lockedorno
public function getState()
{
$token = JWTAuth::getToken();
$user = JWTAuth::toUser($token);
$unlocked = $user->devices()->unlocked();
$device_state = $unlocked->count() == 0 ? 1 : 0;
$data = ['state' => $device_state, 'username' => $user->first_name];
$this->putStats($user);
return Response::json($data);
}
作者:jubaedprinc
项目:nohunchAP
public function currentUserIsOwner()
{
$user = JWTAuth::parseToken()->authenticate();
$user_id = $user->id;
if ($this->user_id == $user_id) {
return true;
} else {
return false;
}
}
作者:poiut
项目:mida
/**
* Return request headers needed to interact with the API.
*
* @return Array array of headers.
*/
protected function headers($user = null)
{
$headers = ['Accept' => 'application/json'];
if (!is_null($user)) {
$token = JWTAuth::fromUser($user);
JWTAuth::setToken($token);
$headers['Authorization'] = 'Bearer ' . $token;
}
return $headers;
}