简体   繁体   中英

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 ?

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM