Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User needs admin approval after registration for login and redirect to login page right after registration

In my Laravel 5.5 application with default auth system,I am trying to implement a login procedure like this,

1.I have a is_approved field in users table which is default 0;

2.If admin approved a user, it will be 1 and user can log in.

3.User will be redirected to login page after the registration with a message "You have been successfully registered.Please wait for the admin approval".

So when a user registered he should be redirected to login page instead of home and if he tries to login in the login page with email and password it should say "You are not approved yet ! ".

What i need to modify for this in Laravel authentication system ?

like image 521
Jason Avatar asked Oct 28 '25 20:10

Jason


1 Answers

I override and modify the register method in my RegisterController ,

public function register(Request $request)
    {
        $this->validator($request->all())->validate();

        event(new Registered($user = $this->create($request->all())));

        return redirect()->back()->with('success', 'You have been successfully registered!. Please wait for the admin approval');
    }

and in my LoginController I override and modify the credentials method,

public function credentials(Request $request)
    {
        return [
            'email' => $request->email,
            'password' => $request->password,
            'is_approved' => 1,
        ];
    }

Its working perfectly !

like image 81
Jason Avatar answered Oct 30 '25 10:10

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!