I find it difficult to understand the Sentry 2 implementation for login. I mean, in Sentry, it was pretty complicated. Provide the username / email address and password from the input method to the Sentry::login() method, however they changed it now and it is really confusing.
First of all, they deleted the user column, which does not make sense.
Secondly, the login method now accepts the User object that you need to get using the user ID, which again does not make sense, since you do not know the user ID unless you make another request, so that they really complicate everything.
My code is:
public function login() { // Deny access to already logged-in user if(!Sentry::check()) { $rules = array( 'username' => 'required|unique:users', 'password' => 'required' ); $validator = Validator::make(Input::all(), $rules); if($validator->fails()) { Session::flash('error', $validator->errors()); return Redirect::to('/'); } $fetch = User::where('username', '=', trim(Input::get('username'))); $user = Sentry::getUserProvider()->findById($fetch->id); if(!Sentry::login($user, false)) { Session::flash('error', 'Wrong Username or Password !'); } return Redirect::to('/'); } return Redirect::to('/'); }
I tried to use this approach, but it throws an exception: this identifier is unknown, despite the fact that the identifier is part of the table, and the User model is nothing more than a class declaration using $ table = 'users'; attribute.
What am I doing wrong here or do not understand.
source share