Reputation: 5302
I have this code:
jQuery.ajax({
type:"POST",
url:"/password/email/",
data:{
_token: jQuery("#forgotPasswordContainer input[name='_token']").val(),
email: email
},
dataType:'json',
beforeSend:function(){
},
success:function(data){
},
complete:function(){
}
});
it seems that it is doing nothing.
When I checked firebug, i am getting an html page containing the html of /password/email
page.
I am guessing I need to modify how sending password reset link works.
Can someone help me on this matter.
Your help will be greatly appreciated!
Thanks!
Upvotes: 4
Views: 4969
Reputation: 2059
If you want to customized or changed the POST
URL that you send via AJAX
here is the complete answer:
jQuery.ajax({
type:"POST",
url:"/user/password/reset",
data:{
_token: jQuery("#forgotPasswordContainer input[name='_token']").val(),
email: email
},
dataType:'json',
beforeSend:function(){
},
success:function(data){
},
complete:function(){
}
});
Route::post('user/password/reset', [
'uses' => 'Controller_name@index'
]);
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Contracts\Auth\PasswordBroker;
class Controller_name extends Controller
{
public function index(Request $request, PasswordBroker $passwords)
{
if( $request->ajax() )
{
$this->validate($request, ['email' => 'required|email']);
$response = $passwords->sendResetLink($request->only('email'));
switch ($response)
{
case PasswordBroker::RESET_LINK_SENT:
return[
'error'=>'false',
'msg'=>'A password link has been sent to your email address'
];
case PasswordBroker::INVALID_USER:
return[
'error'=>'true',
'msg'=>"We can't find a user with that email address"
];
}
}
return false;
}
}
Create a new directory auth > emails > password.blade.php
for email template:
Click here to reset your password .<br />
<a target="_blank" href="{{ url('password/reset', $token).'?email='.urlencode($user->getEmailForPasswordReset()) }}">Click to Reset Password</a>
Upvotes: 2
Reputation: 5302
Ok, I managed to solved this one by putting this on my PasswordController.php
public function getEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = $this->passwords->sendResetLink($request->only('email'), function($m)
{
$m->subject($this->getEmailSubject());
});
switch ($response)
{
case PasswordBroker::RESET_LINK_SENT:
return[
'error'=>'false',
'msg'=>'A password link has been sent to your email address'
];
case PasswordBroker::INVALID_USER:
return[
'error'=>'true',
'msg'=>"We can't find a user with that email address"
];
}
}
I am not sure if this is efficient but this works for me. Hope this helps someone.
Thanks!
Upvotes: 5