Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Reset password check for validation before login and redirecting

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 493
    Comment on it

    In Laravel 5.0 we have in built functionality for forgot password or resetting password. Once the user reset his/her password he/she is logged-in and redirected to the specific URL. But what if the user is deactivated by the super admin temporarily and we do not want to allow him/her from logging-in after resetting the password.


    Further more, if you have multiple roles you want to redirect the user to the corresponding URL according to the role he/she belongs to you may need to follow the following steps to accomplish it :-


    Step 1st:- Add the following line in the PasswordController.php file.

    protected $redirectTo = '/';
    

    Step 2nd:- Replace the following code in the ResetsPasswords.php file. Available under the path [project_name]/vendor/laravel/framework/src/Illuminate/Foundation/Auth/ResetsPasswords.php

    $this->auth->login($user);

    With

    // Check if the user is activate or not before log-in and redirecting to the specific URL according to its role. 
    if($user->status == 1){ 
         $this->auth->login($user);
         if(isset($user) && ($user != null) && (isset($user->role)) && ($user->role == 'admin') ){
              $this->redirectTo = '/admin/profile'; 
         } else if(isset($user) && ($user != null) && (isset($user->role)) && ($user->role == 'ngo') ){
              $this->redirectTo = '/ngo/profile'; 
         } else {
              $this->redirectTo = '/profile';
         }
     }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: