22
33namespace Pterodactyl \Http \Controllers \Auth ;
44
5+ use Illuminate \Http \JsonResponse ;
6+ use Illuminate \Support \Facades \Password ;
7+ use Pterodactyl \Exceptions \DisplayException ;
58use Pterodactyl \Http \Controllers \Controller ;
69use Illuminate \Foundation \Auth \ResetsPasswords ;
10+ use Pterodactyl \Http \Requests \Auth \ResetPasswordRequest ;
711
812class ResetPasswordController extends Controller
913{
@@ -17,16 +21,44 @@ class ResetPasswordController extends Controller
1721 public $ redirectTo = '/ ' ;
1822
1923 /**
20- * Return the rules used when validating password reset .
24+ * Reset the given user's password.
2125 *
22- * @return array
26+ * @param \Pterodactyl\Http\Requests\Auth\ResetPasswordRequest $request
27+ * @return \Illuminate\Http\JsonResponse
28+ *
29+ * @throws \Pterodactyl\Exceptions\DisplayException
30+ */
31+ public function __invoke (ResetPasswordRequest $ request ): JsonResponse
32+ {
33+ // Here we will attempt to reset the user's password. If it is successful we
34+ // will update the password on an actual user model and persist it to the
35+ // database. Otherwise we will parse the error and return the response.
36+ $ response = $ this ->broker ()->reset (
37+ $ this ->credentials ($ request ), function ($ user , $ password ) {
38+ $ this ->resetPassword ($ user , $ password );
39+ }
40+ );
41+
42+ // If the password was successfully reset, we will redirect the user back to
43+ // the application's home authenticated view. If there is an error we can
44+ // redirect them back to where they came from with their error message.
45+ if ($ response === Password::PASSWORD_RESET ) {
46+ return $ this ->sendResetResponse ();
47+ }
48+
49+ throw new DisplayException (trans ($ response ));
50+ }
51+
52+ /**
53+ * Send a successful password reset response back to the callee.
54+ *
55+ * @return \Illuminate\Http\JsonResponse
2356 */
24- protected function rules (): array
57+ protected function sendResetResponse (): JsonResponse
2558 {
26- return [
27- 'token ' => 'required ' ,
28- 'email ' => 'required|email ' ,
29- 'password ' => 'required|confirmed|min:8 ' ,
30- ];
59+ return response ()->json ([
60+ 'success ' => true ,
61+ 'redirect_to ' => $ this ->redirectTo ,
62+ ]);
3163 }
3264}
0 commit comments