1

Is there any way to authenticate a user via email/link/code in Cartalyst Sentinel?

I'm building a simple user registration in Laravel 5.1 which sends a activation email after sign up. By clicking the link, I'd like to activate and authenticate the user in the same action, but I haven't managed to do that.

The only way seems to be passing the credentials (Sentinel::($credentials)), but I just have the $code and $id, needed for the activation, and it asks for the password (which would be a little insecure the send via email, by the way).

Is there any way to do this? Thanks in advance!

henriale
  • 1,012
  • 9
  • 21

1 Answers1

3

If you have or can retrieve the user object (which you need to complete the users activation anyway), then you can use login() to login a user without their credentials.

$user = Sentinel::findById($id);

Sentinel::login($user);

The whole process should look something like this:

$user = Sentinel::findById($id);

if ( ! Activation::complete($user, $activationCode))
{
    // ERROR - Invalid or expired activation code.
}

// Login the User
Sentinel::login($user);

// Redirect to where you want to take them
Jeemusu
  • 10,415
  • 3
  • 42
  • 64