dimanche 27 mars 2016

Laravle 5 reset password is not working when user is already logged in

I have written following code to send reset password link to user and it is working perfect when user is not logged in and getting mail too but when I try to send reset password when user is logged in it is not working.

I have checked when user is logged in postEmail method is not calling by Ajax. Any idea where I am wrong.

Here is my code

Form:

<form id="resetAccountForm" class="form-horizontal" role="form" method="POST" action="http://localhost/project-name/password/email">
    <input type="hidden" name="_token" id="_token" value="OaIG5OWKP3F5YrZwaVDN6uYbATtDqKzpgZ5S66mk">
    <input type="hidden" name="nickname" value="example">
    <input type="hidden" name="ID" value="example@gmail.com">
    <div class="find_acc_btn_contianer re_container">
        <button class="reset_pwd reset-my-account" type="submit">Reset</button>
    </div>
</form>

JS Code for Ajax submission:

$(document.body).on('submit', 'form#resetAccountForm', function(event) {
    event.preventDefault();

    var formData = $(this).serialize(); // form data as string
    var formAction = $(this).attr('action'); // form handler url
    var formMethod = $(this).attr('method'); // GET, POST

    $.ajaxSetup({
        headers: {
            'X-XSRF-Token': $('meta[name="_token"]').attr('content')
        }
    });

    $.ajax({
        type: formMethod,
        url: formAction,
        data: formData,
        cache: false,
        beforeSend: function() {
            $("#ajax-loader").show();
            $('.reset-my-account').prop('disabled', true);
        },
        success: function(data) {
            $("#ajax-loader").hide();
        }
    });
});

Routes:

Route::get('home', 'HomeController@index');
Route::controllers([
    'auth'=>'Auth\AuthController',
    'password'=>'Auth\PasswordController',
]);

Route::get('password/email', 'Auth\PasswordController@getEmail');
Route::post('password/email', 'Auth\PasswordController@postEmail');

PasswordController.php

/**
 * Send a reset link to the given user.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function postEmail(Request $request)
{
    $this->validate($request, ['ID' => 'required|email']);

    // Pass data to reset password mail template
    view()->composer('emails.password', function($view) {
        $view->with([
            'Nickname'   => Input::get('nickname'),
        ]);
    });

    $response = Password::sendResetLink($request->only('ID'), function (Message $message) {
        $message->subject($this->getEmailSubject());
    });

    if ($response == "passwords.sent") {
        $html = '<div class="img_left_dv"><img src="resources/assets/front/images/suggestion_2.png" alt=""/></div>
        <div class="text_right_dv">
            <h3>'.Input::get('nickname').'</h3>
            <p><a href="javascript:void(0);">'.Input::get('ID').'</a> '.trans('messages.reset_password_popup.confirmation_message').'</p>
        </div>';
        echo $html;
    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1LRDTY1
via IFTTT

Aucun commentaire:

Enregistrer un commentaire