本文介绍了Laravel 4:如何确认邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我直到现在已经有一个登录/注册的应用程序,它工作正常。
注册后发送欢迎电子邮件。



但是,我想做的是在邮件中发送链接,只有点击后它可以登录。



像论坛等的常见注册邮件一样。



有人可以帮助我吗?



这是postRegister方法:

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

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

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

if($ validation-> passed()){

$ 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');
}

返回重定向:: back() - > withInput() - > withErrors($ validation) - > with('message','Validation Errors!
}

谢谢

解决方案

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




  • 添加两个确认确认。在Laravel中,如注册/验证/ {确认} ,您可以尝试使用给定的确认代码在您的数据库中找到一个用户(如果找到,则设置用户的确认字段为1)。

  • 在用户注册后,生成唯一的确认码(您可以使用 str_random() / code>帮助函数)

  • 相应地设置新用户的数据库条目(确认 =随机代码, 确认 = 0)

  • 将您的电子邮件中生成的确认码包含在您的验证链接(根据您的验证路线构建)新用户。



现在可以这样完成认证尝试:

  $ user = array(
'username'=> Input :: get('username'),
'password'=> Input :: get('password' ,
'confirm'=> 1
);

if(Auth :: attempt($ user)){
//成功!
return重定向:: route('restricted / area');
}


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..

Someone can help me please?

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 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!');
}

Thank you

解决方案

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');
}

这篇关于Laravel 4:如何确认邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 17:48