Laravel 4: how to make confirmation email?

后端 未结 1 1567
你的背包
你的背包 2021-01-02 02:22

I have made until now an app with login/register and it works fine. After the registration a welcome email is sent.

But what i would like to do is to send a link, wi

1条回答
  •  执笔经年
    2021-01-02 03:07

    Here are a few clues (not gonna write the code for you).

    • Add two fields to your user table: confirmation, confirmed.
    • Create a route in Laravel like registration/verify/{confirmation}, in which you try and find a user in your DB with the given confirmation code (if found, set user's confirmed field to 1).
    • Upon user registration, generate a unique confirmation code (you can use the str_random() helper function for this).
    • Set DB entry of new user accordingly (confirmation = the random code, confirmed = 0)
    • Include a verification link (built according to your verification route) with the generated confirmation code in your email to your new user.

    Auth attempts can now be done like this:

    $user = array(
            'username' => Input::get('username'),
            'password' => Input::get('password'),
            'confirmed' => 1
    );
    
    if (Auth::attempt($user)) {
        // success!
        return Redirect::route('restricted/area');
    }
    

    0 讨论(0)
提交回复
热议问题