本文介绍了Laravel 4:如何制作确认邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我已经制作了一个带有登录/注册功能的应用程序,它运行良好.注册后会发送一封欢迎电子邮件.
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, within that mail, that only after clicking on it, it is possible to login.
比如论坛常用的注册邮箱等.
Like the common registration email for forum etc..
有人可以帮帮我吗?
这是 postRegister 方法:
This is the postRegister method:
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 MailersUserMailer($user);
// var_dump($mailer);
$mailer->welcomeMail()->deliver();
$user->save();
return Redirect::to('afterRegister');
}
return Redirect::back()->withInput()->withErrors($validation)->with('message', 'Validation Errors!');
}
谢谢
推荐答案
这里有一些线索(不会给你写代码).
Here are a few clues (not gonna write the code for you).
- 在您的用户表中添加两个字段:
confirmation
、confirmed
. - 在 Laravel 中创建一个类似
registration/verify/{confirmation}
的路由,您可以在其中尝试使用给定的确认码在数据库中查找用户(如果找到,请设置用户的confirmed
字段为 1). - 在用户注册后,生成一个唯一的确认码(您可以使用
str_random()
帮助函数). - 相应地设置新用户的数据库条目(
confirmation
= 随机码,confirmed
= 0) - 在发送给新用户的电子邮件中包含一个带有生成的确认码的验证链接(根据您的验证路线构建).
- 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'sconfirmed
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');
}
这篇关于Laravel 4:如何制作确认邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!