2016-11-03 3 views
2

私はlaravel auth機能を内蔵しています。うまくいきます。次の2つの機能をオーバーライドしようとしています。オーバーライド認証Laravelのパスワードを忘れました5.3

1.send mandrelを使用してパスワードを忘れました。

2.アカウントの登録中に送信確認メールを送信します。

いずれかがこの問題を解決するために私を助けることができる

私の目的は、マンドレルの代わりに、デフォルトの電子メール

を使用することです私は、認証がメソッドに建てられたが、私はその

をオーバーライドすることができますどのように得たアイデアをdidntの見ることができます
trait ResetsPasswords 
{ 
    use RedirectsUsers; 

    /** 
    * Display the password reset view for the given token. 
    * 
    * If no token is present, display the link request form. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param string|null $token 
    * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View 
    */ 
    public function showResetForm(Request $request, $token = null) 
    { 
     return view('auth.passwords.reset')->with(
      ['token' => $token, 'email' => $request->email] 
     ); 
    } 

    /** 
    * Reset the given user's password. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @return \Illuminate\Http\Response 
    */ 
    public function reset(Request $request) 
    { 
     $this->validate($request, $this->rules(), $this->validationErrorMessages()); 

     // Here we will attempt to reset the user's password. If it is successful we 
     // will update the password on an actual user model and persist it to the 
     // database. Otherwise we will parse the error and return the response. 
     $response = $this->broker()->reset(
      $this->credentials($request), function ($user, $password) { 
       $this->resetPassword($user, $password); 
      } 
     ); 

     // If the password was successfully reset, we will redirect the user back to 
     // the application's home authenticated view. If there is an error we can 
     // redirect them back to where they came from with their error message. 
     return $response == Password::PASSWORD_RESET 
        ? $this->sendResetResponse($response) 
        : $this->sendResetFailedResponse($request, $response); 
    } 

答えて

1

LaravelはSMTP、Mailgun、マンドリル、アマゾンSES、 PHPのメール機能、およびsendmai用のドライバを提供しますあなたがすぐに始めることを可能にする あなたの選択のローカルまたはクラウドベースのサービスを介してメールを送信します。

.envファイルを開き、次の情報をマンドリルの資格情報で変更してください。

MAIL_DRIVER =マンドリル

MAIL_HOST =

MAIL_PORT = 2525

MAIL_USERNAME =ヌル

MAIL_PASSWORD =ヌル

MAIL_ENCRYPTION =ヌル

+0

.Thanks.Ya.iもmail.php configファイルで見ました。登録時に電子メールの検証を送信し、テンプレートを変更すると – iCoders

+0

私はマンドリルに変更するとエラーが発生しました。 "body"リクエストオプションを配列としてパッシングPOST要求を送信することは推奨されていません。application/x-www-form-urlencodedリクエストを送信するには、 "form_params"リクエストオプションを使用し、multipart/form-dataリクエストを送信するには "multipart"リクエストオプションを使用してください。 – iCoders

+0

ああ!これは、GuzzleHttpの減価償却の問題によるものです。ここをクリックしてください:https://laracasts.com/discuss/channels/laravel/l5-mandrill-error –

0

独自のresetメソッドをコントローラで作成して、その特性を使用してその特性のメソッドをオーバーライドすることができます。

2

Mahfuzalの回答によれば、Laravelには、箱から取り出したメールドライバがたくさんあります。正しいドライバを使用するには、.envファイルを更新してください。

アカウントを作成するときに確認メールを送信するために、あなたはちょうどそうのようなAuth/AuthControllerpostRegister()関数をオーバーライドする必要があるとして:

public function postRegister(Request $request) 
    { 

     $validator = $this->validator($request->all()); 

     if ($validator->fails()) { 
      $this->throwValidationException(
       $request, $validator 
      ); 
     } 

     $confirmation_code = str_random(30); 
     $newUser = new User; 
     $newUser->username = $request->username; 
     $newUser->email = $request->email; 
     $newUser->password = bcrypt($request->password); 
     $newUser->confirmation_code = $confirmation_code; 

     $newUser->save(); 

     $data = array('confirmation_code' => $confirmation_code, 'username' => $request->username); 

     Mail::send('emails.verify', $data, function ($message) use ($newUser){ 
      $message->to($newUser->email, $newUser->username); 
       $message->subject('Please verify your email address'); 
     }); 

     return redirect('/auth/login'); 
    } 

むしろ何Laravelよりもユーザーを登録するときにこれは上記のコードを実行しますあなたのニーズに合わせて調整するので、デフォルトの状態になります。

トークンをチェックし、リンクをクリックしたときにアカウントを確認する関数を作成するだけで済みます。そのために、私はhereと同様のものを使用します。

+0

@ James.Thanks.iはすでに 'driver' = > 'mandrill'と私は次のエラーを取得していますPOST要求を送信するための配列として "body"リクエストオプションを渡すことは推奨されていません。 application/x-www-form-urlencodedリクエストを送信するには、 "form_params"リクエストオプションを使用し、multipart/form-dataリクエストを送信するには "multipart"リクエストオプションを使用してください。 – iCoders

+0

@iCoders https://laracasts.com/discuss/channels/laravel/l5-mandrill-error – James

+0

@ james.howその問題を修正してください。 – iCoders

関連する問題