Search code examples
phpemaillaravellaravel-4cartalyst-sentry

Sentry Login using username or email (any of em) in Laravel 4


Currently I am using sentry login using email , I know how easily it can be converted into username if I simply change the

sentry config file to this

'login_attribute' => 'username',

But I find it odd because then the emailing of forget password info became unreachable. What I want is, I want to give user the freedom to choose the artibute as username or email any of them, during the login ....

Any idea How to start ?


Solution

  • This is one way of doing it:

    Locate the user using whatever login field your user choose:

    $user = User::where(Input::get('login_field'), Input::get('login_name'))->first();
    

    Create valid credentials using the e-mail of the user you just found:

    $credentials = array(
        'email'    => $user ? $user->email : null,
        'password' => Input::get('password'),
    );    
    

    And authenticate it:

    $user = Sentry::authenticate($credentials, false);