I have implemented laravel 5.2 multi authentication.I have two guard web(default) and admin(created new). I have logged out user using Auth::logout() but I am not able to logout admin.
I tried to logout with Auth::guard('admin')->logout() and Auth::guard('admin')->user()->logout(). But its not working.
Try below code for logout method:
App/Http/Controllers/LoginRegisterCtrl.php
public function logout()
{
Auth::guard('web')->logout();
Auth::guard('admin')->logout();
}
Above code should work for you.
Related
I am trying to log Auth activity using Laravel 5.2 built-in Logs API.
The code would be like
\Log::info("Message here");
It works inside HomeController. However, it does not work inside AuthController.
Sample code inside logout method:
public function getLogout()
{
\Log::info('User has logged out.', ['email' => \Auth::user()->email]);
\Auth::logout();
return redirect('/');
}
If you are using Route::auth() to register your Auth related routes, it does not use that method, getLogout. It uses logout.
Check your routes with php artisan route:list to see what controller methods those Auth routes are using.
I create REST API using Laravel. And i am is in Login API, so i use AuthController built it from Laravel.
But, when i authenticate user login using Auth::attempt() in the first time i successfully get User Info cause i call this method Auth::user().
But, when i run again in second time, i get this following Error :
NotFoundHttpException in RouteCollection.php line 161:
I know it send redirect automatically if user has authenticated. And save the session.
Here is my Login Code in AuthController.php
public function demo() {
if (Auth::attempt(Input::only('email','password'))) {
return Auth::user();
} else {
return "false";
}
}
And i write the routes like this :
Route::post('demo', 'Auth\AuthController#demo');
How to disable redirect in that case?
Cause i wanna call my API from my mobile application.
Thank you
Answer
Okay i get the solution, but it's not elegant way. I edit the class
RedirectIfAuthenticated and remove return redirect(/home) in
handle method.
I'm developing website with Laravel framework and Sentinel
I install Sentinel and it's work fine with login and user group data, but when i create my project i don't know how use it to differentiate user who has login as admin or not login.. i follow the indstruction code like this in controller:
public function dashboard()
{
$this->middleware('sentry.member:Admins');
return view('admin.dashboard');
}
But when i access the dashboard without login, it's still open dashboard.. how to fix it? how to redirect page to login if i'm not login yet?
In laravel to check a user while he is login or not login we do like this off-course this is works when we have installed sentry in laravel 5 framework.
public function dashboard(){
//already logged in go to dashboard or else login
if(Sentry::check()){
return Redirect::to('/admin.dashboard');
}else{
return Redirect::to('/login');
}
}
I'm using Laravel's Auth Throttling feature and it is working correctly but I would like to know how to clear the login attempts for that email?
http://laravel.com/docs/5.1/authentication#authentication-throttling
currently the lockout time is at "Too many login attempts. Please try again in 5418 seconds"
run this in the console php artisan cache:clear and you're good to go
In your controller that includes the ThrottlesLogins trait, create a new route handler method:
public function clearThrottle(Request $request) {
$this->clearLoginAttempts($request);
// Forward elsewhere or display a view
}
I am developing a website in laravel. I am facing a problem with the auth filter and the logout method.
In my home controller I want to apply the auth filter for some of the methods as follows.
public function __construct()
{
parent::__construct();
$this->filter('before',array('auth'))->except(array('index','view'));
}
I have action_logout as follows.
public function action_logout()
{
Auth::logout();
return Redirect::to("/home/index");
}
When I have logged in and trying to logout, i am not being able to access the logout action. I tried echoing something from the inside of the action but it didnt work.
changing to this..
$this->filter('before',array('auth'))->except(array('index','view','logout'));
works. Logically I should be able to logout only when i have logged in. But applying the filter above m not being able to access the logout action after loggin in. Help!.