vendredi 17 juin 2016

Confirmation Code for a user won't work Laravel 5.2

So was able to create a user, no problem. I wanted to add a confirmation code to validate a users email. I was able to have the application send an email to a user with a link. One a user clicks that link it updates the database. Here's the problem this only works when the user is logged out. When they are logged in nothing seems to happen. I don't want to force a new user to log out and verify before he can log in. Anyway here is my AuthController:

protected function create(array $data)
{
    $confirmation_code = str_random(30);

    $user = User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
        'schoolid' => $data['schoolid'],
        'confirmation_code' => $confirmation_code,
    ]);

    Mail::send('emails.verify', compact('confirmation_code'), function($message) {
        $message->to(Input::get('email'), Input::get('username'))->subject('Verify your email address');
    });

    return $user;

}

 /**
 * Attempt to confirm a users account.
 *
 * @param $confirmation_code
 *
 * @return mixed
 */
 public function confirm($confirmation_code) {
    $user = User::where('confirmation_code', $confirmation_code)->first();
    $user->confirmed = 1;
    $user->confirmation_code = null;
    $user->save();
    return redirect('/');

}
}

I am just showing you the create and confirm methods. If you need more code just let me know. However, I believe my problem may be from this code. Thanks for the help



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire