Skip to content

Commit 12d0f8d

Browse files
committed
reset password workflow now working #129
1 parent b33accf commit 12d0f8d

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

angular/app/components/forgot-password/forgot-password.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ForgotPasswordController {
1212
}
1313

1414
submit() {
15-
this.API.all('auth/forgot').post({
15+
this.API.all('auth/password/email').post({
1616
email: this.email
1717
}).then(() => {
1818
this.ToastService.show(`Please check your email for instructions on how to reset your password.`);

angular/app/components/reset-password/reset-password.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<div class="ResetPassword-loader" layout="row" layout-align="center center">
2-
<md-progress-circular md-mode="indeterminate" ng-if="!vm.isValidToken"></md-progress-circular>
1+
<div class="ResetPassword-loader" ng-if="!vm.isValidToken" layout="row" layout-align="center center">
2+
<md-progress-circular md-mode="indeterminate"></md-progress-circular>
33
</div>
44

55
<form ng-submit="vm.submit()" ng-show="vm.isValidToken">

angular/app/components/reset-password/reset-password.component.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ class ResetPasswordController {
2323
email, token
2424
}).then(() => {
2525
this.isValidToken = true;
26+
}, () => {
27+
this.$state.go('app.landing');
2628
});
2729
}
2830

29-
reset() {
31+
submit() {
3032
let data = {
3133
email: this.$state.params.email,
3234
token: this.$state.params.token,

app/Http/Controllers/Auth/PasswordResetController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public function sendResetLinkEmail(Request $request)
1616
'email' => 'required|email|exists:users,email',
1717
]);
1818

19+
//invalidate old tokens
20+
PasswordReset::whereEmail($request->email)->delete();
21+
1922
$email = $request->email;
2023
$reset = PasswordReset::create([
2124
'email' => $email,
@@ -26,6 +29,7 @@ public function sendResetLinkEmail(Request $request)
2629

2730
Mail::send('auth.reset_link', compact('email', 'token'), function ($mail) use ($email) {
2831
$mail->to($email)
32+
->from('noreply@localhost')
2933
->subject('Password reset link');
3034
});
3135

@@ -62,6 +66,9 @@ public function reset(Request $request)
6266
$user->password = bcrypt($request->password);
6367
$user->save();
6468

69+
//delete pending resets
70+
PasswordReset::whereEmail($request->email)->delete();
71+
6572
return response()->success(true);
6673
}
6774
}

app/Http/routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// Password Reset Routes...
3030
$api->post('auth/password/email', 'Auth\PasswordResetController@sendResetLinkEmail');
31-
$api->post('auth/password/verify', 'Auth\PasswordResetController@verify');
31+
$api->get('auth/password/verify', 'Auth\PasswordResetController@verify');
3232
$api->post('auth/password/reset', 'Auth\PasswordResetController@reset');
3333

3434
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Your reset password link:
22

3-
http://localhost:8000/reset-password/{{$email}}/{{$token}}
3+
http://localhost:8000/#/reset-password/{{$email}}/{{$token}}

tests/PasswordResetTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ public function testVerifyTokenSuccessfully()
2525
{
2626
$reset = factory(PasswordReset::class)->create();
2727

28-
$this->post('/api/auth/password/verify', [
29-
'email' => $reset->email,
30-
'token' => $reset->token,
31-
])
32-
->seeApiSuccess();
28+
$this->get("/api/auth/password/verify?email={$reset->email}&token={$reset->token}")
29+
->seeApiSuccess();
3330
}
3431

3532
public function testVerifyTokenUnsuccessfully()
3633
{
3734
$reset = factory(PasswordReset::class)->create();
3835

39-
$this->post('/api/auth/password/verify', [
36+
$this->get('/api/auth/password/verify', [
4037
'email' => $reset->email,
4138
'token' => str_random(10),
4239
])
@@ -45,7 +42,7 @@ public function testVerifyTokenUnsuccessfully()
4542

4643
public function testResetPasswordWithTokenSuccessfully()
4744
{
48-
$user = factory(App\User::class)->create();
45+
$user = factory(App\User::class)->create();
4946
$reset = factory(PasswordReset::class)->create([
5047
'email' => $user->email,
5148
]);
@@ -66,7 +63,7 @@ public function testResetPasswordWithTokenSuccessfully()
6663

6764
public function testResetPasswordWithTokenUnsuccessfully()
6865
{
69-
$user = factory(App\User::class)->create();
66+
$user = factory(App\User::class)->create();
7067
$reset = factory(PasswordReset::class)->create([
7168
'email' => $user->email,
7269
]);

0 commit comments

Comments
 (0)