M
M
Minat0_2020-07-14 14:42:10
Laravel
Minat0_, 2020-07-14 14:42:10

How to manually unauthorize a user and submit an error?

Actually, the question is in the title. I do manual authorization (and registration) of the user.
The idea is this: in the database, each user has a column "verify" , in it, respectively, either true or false.
In the model, I send a request to the database, in the controller I use.

So, I have two questions:
1. Is this correct from the point of view of architecture?
Because, in fact, the check should probably occur at the expense of the middlewire, and not the controller.
2. How can I "unauthorize" a user and display an error?

The code itself in the LoginController

public function authenticated(Request $request, $user)
  {
    $credentials = $request->only('email','password');
      if (Auth::attempt($credentials) && User::isVerify($request->input('email'))) {
          Auth::login($user, true);
      } else {
      	Auth::logout();
      	redirect('/login')->withErrors(['user_not_verified' => "Ошибка: неподтверждённый пользователь!"]);
      }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Minat0_, 2020-07-14
@zhenyavka

I just added an intermediary and, accordingly, canceled the authorization in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question