22
33namespace  Iamnotstatic \LaravelAPIAuth \Http \Controllers \Auth ;
44
5+ use  App \User ;
6+ use  Illuminate \Http \Request ;
7+ use  Illuminate \Support \Carbon ;
58use  App \Http \Controllers \Controller ;
9+ use  Illuminate \Support \Facades \Validator ;
10+ use  Iamnotstatic \LaravelAPIAuth \Models \PasswordReset ;
11+ use  Iamnotstatic \LaravelAPIAuth \Notifications \PasswordResetSuccess ;
612
713class  ResetPasswordController extends  Controller
814{
@@ -17,5 +23,77 @@ class ResetPasswordController extends Controller
1723 | 
1824 */ 
1925
26+  /** 
27+  * Find token password reset 
28+  * 
29+  * @param [string] $token 
30+  * @return [string] message 
31+  * @return [json] passwordReset object 
32+  */ 
33+  public  function  find ($ token
34+  {
35+  $ passwordResetwhere ('token ' , $ tokenfirst ();
36+ 37+  if  (!$ passwordReset
38+  return  response ()->json ([ 'error '  => 'This password reset token is invalid. ' ], 404 );
39+ 40+  if  (Carbon::parse ($ passwordResetupdated_at )->addMinutes (720 )->isPast ()) {
41+  $ passwordResetdelete ();
42+  return  response ()->json ([ 'error '  => 'This password reset token is invalid. ' ], 404 );
43+  }
44+ 45+  return  response ()->json ($ passwordReset
46+ 47+  }
48+ 49+ 50+  /** 
51+  * Reset password 
52+  * 
53+  * @param [string] email 
54+  * @param [string] password 
55+  * @param [string] password_confirmation 
56+  * @param [string] token 
57+  * @return [string] message 
58+  * @return [json] user object 
59+  */ 
60+  public  function  reset (Request $ request
61+  {
62+  $ validatemake ($ requestall (), [
63+  'email '  => 'required|string|email ' ,
64+  'password '  => 'required|string|min:8|confirmed ' ,
65+  'token '  => 'required|string ' 
66+  ]);
67+ 68+  if  ($ validatefails ()) {
69+  return  response ()->json (['error '  => $ validateerrors ()], 400 );
70+  }
71+ 72+  $ passwordResetwhere ([
73+  ['token ' , $ requesttoken ],
74+  ['email ' , $ requestemail ]
75+  ])->first ();
76+ 77+  if  (!$ passwordReset
78+  return  response ()->json ([ "error "  => "This password reset token is invalid. " ], 404 );
79+ 80+  $ userwhere ('email ' , $ passwordResetemail )->first ();
81+ 82+  if  (!$ user
83+  return  response ()->json (["error "  => "We can't find a user with that e-mail address. " ], 404 );
84+ 85+  $ userpassword  = bcrypt ($ requestpassword );
86+  $ usersave ();
87+  $ passwordResetdelete ();
88+ 89+  try  {
90+  $ usernotify (new  PasswordResetSuccess ($ passwordReset
91+  } catch  (\Throwable   $ th
92+  //throw $th; 
93+  }
94+ 95+  return  response ()->json (['success '  => 'Password was reset successfully you can now login ' ]);
96+  }
97+ 2098
2199}
0 commit comments