无法获得laravel来保存新用户,发送电子邮件和登录&重定向

时间:2015-02-18 23:29:27

标签: laravel

我尝试在用户注册时发送欢迎电子邮件,然后将其登录并重定向到其帐户页面。我可以收到电子邮件发送确定但登录/重定向不会工作。如果我删除发送电子邮件的代码,登录/重定向确实有效。我不确定为什么它不会让我同时做这两件事。这是我的路线:

Route::post('register', function()
{   
    $aRules = array(
        'firstname' => 'required',
        'lastname' => 'required',
        'password' => 'required',
        'email' => 'required',
        'membertype_id' => 'required',
        'gender' => 'required',
        'brn' => 'required'
    );

$oValidator = Validator::make(Input::all(),$aRules);

if($oValidator->fails()){

    //return form with error messages and sticky data
    // return Redirect::back()->withInput()->withErrors($oValidator);
    return Redirect::back()->withInput();

}else{

    // Create User Account
    $aUserDetails = Input::all();
    $aUserDetails['photo'] = 'placeholder.png';

    if( Input::hasFile('photo')){

        $sNewName = Input::get('firstname').time().'.'.Input::file('photo')->getClientOriginalExtension();
        Input::file('photo')->move('img/users/', $sNewName);
        $aUserDetails['photo'] = $sNewName;
    }

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

    User::create($aUserDetails);

    // Send Welcome Email
    $emailcontent = array (
        'firstname' => $aUserDetails['firstname'],
        'lastname' => $aUserDetails['lastname'],
        'email' => $aUserDetails['email']

    );

    Mail::send('emails.registrationEmail', $emailcontent, function($message){
        $message->to(Input::get('email'))->subject('Sudarshanaloka Registration Confirmation');
    });



    // Store message
    Session::flash('message', "<i class='fa fa-check'></i> Registation was Successful! &mdash; A confirmation email has also been sent.");

    // Login and redirect to user account page
    $login = array(
        'email' => Input::get('email'),
        'password' => Input::get('password')
    );


    if (Auth::attempt($login)) {
        return Redirect::to('users/'.Auth::user()->id);
    }

}

});

0 个答案:

没有答案