Laravel重置电子邮件重定向

时间:2018-08-29 21:02:15

标签: laravel

在我的项目中,我有一页处理登录表单,注册表单和密码重置表单。

对于前两个,一切正常。最后,我找到了一种方法来发送自己的电子邮件,而不是laravel的默认电子邮件,但现在我想在成功时停止重定向。

对于这个故事,当我单击“提交”时,我会发出一个甜蜜的通知,用Ajax调用reset控制器并等待响应。

但是,页面会在成功加载时重新加载。我找不到阻止重定向的方法,只是将json发送到我的Ajax。

我的login.js:

$(".m_login_forget_password_submit").click(function(l){

    var t=$(this),r=$(this).closest("form");
    t.addClass("m-loader m-loader--right m-loader--light");

    swal({
        title:"Mot de passe",
        text:"Génération du lien.",
        type:"info"
    });
        var $this = $(this);
        $.ajax({
            type: 'POST',
            url: 'password/request',
            data: $this.serializeArray(),
            success:function(data){
                $("#m_login_signup_submit").toggleClass("m-loader m-loader--right m-loader--light");
                swal({
                    title:"Succès",
                    text:"Votre demande de compte a été transmise à nos équipe.",
                    type:"success"
                });

            },
            error: function(data){
                $("#m_login_signup_submit").toggleClass("m-loader m-loader--right m-loader--light");
                if( data.status === 422 ) {
                    var error = "Les erreurs suivantes ont été trouvées :";
                    var errors = data.responseJSON;
                    $.each( errors, function( key, value ) {
                        error += '<br>&#9656 ' + value[0];
                    });
                    swal("Erreur",error,"error")
                }
            }
        });

我的自定义ResetPasswordController:

class ResetPasswordController extends Controller

{

use ResetsPasswords;

/**
 * Where to redirect users after resetting their password.
 *
 * @var string
 */
protected $redirectTo = '/home';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest');
}

/**
 * Get the response for a successful password reset.
 *
 * @param  string  $response
 * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
 */
protected function sendResetResponse($response)
{
    return 'ok';
}


    }

有人知道如何防止发送电子邮件重设密码成功后重定向,而是发送json吗?

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

重置密码时,#pragma strict import UnityEngine.UI; static var score : int; // The player's score. private var text : Text; // Reference to the Text component. function Awake () { // Set up the reference. text = GetComponent (Text); // Reset the score. score = 0; } function Update () { // Set the displayed text to be the word "Score" followed by the score value. text.text = "Score: " + score; } 中的reset函数将被调用,因此您必须将ResetPasswordController函数重命名为sendResetResponse(因为您想要(以覆盖trait函数)并将默认trait函数指向未使用的函数。另外,如果您想要JSON响应,则需要在返回值中进行指定。

示例:

reset

编辑:

很抱歉,以为您是在谈论重置密码重定向。要在发送电子邮件后处理重定向,您将采用类似的方法并修改class ResetPasswordController extends Controller { use ResetsPasswords { reset as unused; } ... //Override the trait function public function reset(Request $request) { //Call default validation and handle password change $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); } ); //Return the response if ($response == Password::PASSWORD_RESET) { return response()->json(array( 'result' => 'ok', ), 200); } else { return response()->json(array( 'result' => 'fail', ), 500); } } } 并改写ForgotPasswordController函数:

sendResetLinkEmail