Last active
July 20, 2018 13:29
-
-
Save GMory/43bd6189e2c2abf30683e47f580ba346 to your computer and use it in GitHub Desktop.
Laravel 5.6 ResetPasswordController.php (Fix for $email and compatible with SPA - Vue.js, React, Angular)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
/* | |
* Requires Php-Vars-To-JS-Transformer by Jeffery Way | |
* https://github.com/laracasts/PHP-Vars-To-Js-Transformer | |
* | |
* Import both Javascript (from the aforementioned package), DB, and Hash | |
* | |
* We use the token included in the URL to extract the email from the database. | |
* That way we can continue to use the default PW reset methods. | |
* The Javascript block is meant to easily deliver the variables to a javascript object for use by an SPA framework. | |
*/ | |
public function showResetForm($token = null) | |
{ | |
$resets = DB::table('password_resets')->get(); | |
foreach($resets as $reset) { | |
if(Hash::check($token, $reset->token)) { | |
$email = $reset->email; | |
break; | |
} | |
} | |
JavaScript::put([ | |
'token' => $token, | |
'email' => $email | |
]); | |
return view('app'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm'); | |
Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm'); | |
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail'); | |
Route::post('password/reset', 'Auth\ResetPasswordController@reset'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment