重置密码不适用于mailgun配置

时间:2016-05-03 20:42:15

标签: authentication laravel-5.1 reset mailgun password-recovery

我根据mail docs配置了laravel 5.1。发送邮件工作正常。

下一步是根据resetting passwords文档添加重置密码。在这里,我很难将链接发送到reset-password公式。

似乎没有触发发送重置邮件的功能。我还使用config/mail.php配置pretend = true;进行了检查。日志文件中没有条目,发送了一封电子邮件。

不知怎的,它也很难调试,因为我找不到触发重置电子邮件的功能。

  1. 如何使用mailgun发送重置密码?
  2. 函数位于何处发送重置密码,或者我可以在哪里覆盖它以进行测试?
  3. 这是我的配置:

    .ENV

    # ...
    MAIL_DRIVER=mailgun
    MAIL_HOST=smtp.mail.org
    MAIL_PORT=587
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAILGUN_DOMAIN=mg.foo.com
    MAILGUN_SECRET=key-foobar.etc
    # ....
    

    配置/ service.php

    //...
    'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],
    //...
    

    配置/ mail.php

    // ...
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'foo@test.com', 'name' => 'foo'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'pretend' => false,
    // ...
    

    应用程序/ HTTP / routes.php文件

    // ...
    Route::group([
        'prefix' => LaravelLocalization::setLocale(),
        'middleware' => [ 'localeSessionRedirect', 'localizationRedirect' ]
        ], function() {
    
        //Route::controllers([ 'password' => 'Auth\PasswordController', ]);
    
        // works only if the user is logged out!!!1
        // Password reset link request routes...
        Route::get('password/email', 'Auth\PasswordController@getEmail');
        Route::post('password/email', 'Auth\PasswordController@postEmail');
    
        // Password reset routes...
        Route::get('password/reset/{token}', 'Auth\PasswordController@getReset');
        Route::post('password/reset', 'Auth\PasswordController@postReset');
    });
    //...
    

    资源/视图/ AUTH / password.blade.php

    @extends('layout')
    
    @section('content')
    <div class="container">
        <form method="POST" action="/password/email">
            {!! csrf_field() !!}
    
            @if (count($errors) > 0)
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            @endif
        <div class="row">
            <div class="col-md-6">
                {!! Form::label('email', trans( 'mes.email' )) !!}
                <input type="email" name="email" value="{{ old('email') }}" class="form-control">
            </div>
            <div class="col-md-8">
                <button type="submit" class="btn">
                    Send Password Reset Link
                </button>
            </div>
        <div>
    
        </form>
    </div>
    @endsection
    

1 个答案:

答案 0 :(得分:1)

问题是路线不正确。文档中的示例对action元素中的form值进行了硬编码。

这并不反映我的路线配置。通过以下更改,密码重置电子邮件可以正常运行:

应用程序/ HTTP /路由

// change route to a named route
// Route::post('password/email', 'Auth\PasswordController@postEmail');
Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\PasswordController@postEmail']);

资源/视图/ AUTH / password.blade.php

<!-- Use the named route in the form builder and remove csrf_field -->
{!! Form::open(['route' => 'password.email']) !!}