gpt4 book ai didi

email - Laravel 4 : how to make confirmation email?

转载 作者:行者123 更新时间:2023-12-04 00:19:29 30 4
gpt4 key购买 nike

到目前为止,我已经制作了一个带有登录/注册功能的应用程序,它运行良好。
注册后会发送欢迎电子邮件。

但是我想要做的是在该邮件中发送一个链接,只有在单击它后才能登录。

比如论坛常用的注册邮箱等。

有人可以帮助我吗?

这是 postRegister 方法:

public function postRegister()
{
$input = Input::all();

$rules = array(
'username' => 'required',
'password' => 'required');

$validation = Validator::make($input, $rules);

if ($validation->passes()) {

$password = $input['password'];
$password = Hash::make($password);

$user = new User;
$user->username = $input['username'];
$user->email = $input['email'];
$user->password = $password;

$mailer = new Mailers\UserMailer($user);

// var_dump($mailer);

$mailer->welcomeMail()->deliver();

$user->save();

return Redirect::to('afterRegister');
}

return Redirect::back()->withInput()->withErrors($validation)->with('message', 'Validation Errors!');
}

谢谢

最佳答案

这里有一些线索(不会为你写代码)。

  • 向您的用户表中添加两个字段:confirmation , confirmed .
  • 在 Laravel 中创建一条路由,如 registration/verify/{confirmation} ,其中您尝试使用给定的确认代码在数据库中查找用户(如果找到,将用户的 confirmed 字段设置为 1)。
  • 用户注册后,生成唯一的确认码(您可以使用 str_random() 帮助函数)。
  • 相应地设置新用户的数据库条目(confirmation = 随机代码,confirmed = 0)
  • 在发送给新用户的电子邮件中包含带有生成的确认码的验证链接(根据您的验证路线构建)。

  • 现在可以像这样进行身份验证尝试:
    $user = array(
    'username' => Input::get('username'),
    'password' => Input::get('password'),
    'confirmed' => 1
    );

    if (Auth::attempt($user)) {
    // success!
    return Redirect::route('restricted/area');
    }

    关于email - Laravel 4 : how to make confirmation email?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18482338/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com