Skip to content

Instantly share code, notes, and snippets.

@romaninsh romaninsh/forgot.php
Created Feb 18, 2019

What would you like to do?
namespace saasty;
use atk4\ui\Form;
use saasty\Model\User;
require '../vendor/autoload.php';
// added this shit here.
$app = new frontend\App(['appRequired'=>false, 'authRequired'=>false, 'useLayout'=>'Wide']);
$app->add(['Header', 'Password Reminder', 'size'=>2]);
$app->add(['ui'=>'hidden divider']);
if(isset($_GET['sent'])) {
$app->add(['Message', 'Email Recovery', 'success', 'icon'=>'thumbs up'])
->text->addParagraph('We have sent you an email with the password recovery instructions');
$app->add(['Button', 'Back', 'icon'=>'left arrow'])->link(['index']);
if ($token = $_GET['token'] ?? null) {
try {
$t_model = new Model\User\Token\PasswordReset($app->db);
$t_model->loadBy('token', $token);
if(isset($_GET['changed'])) {
$app->add(['Message', 'Password change', 'success', 'icon'=>'thumbs up'])
->text->addParagraph('Your password have been successfully changed');
$app->add(['Button', 'Back', 'icon'=>'left arrow'])->link(['index']);
if (!$t_model['is_valid']) {
throw new Exception(['Token was already used or is expired']);
$form = $app->add('Form');
$form->onSubmit(function(Form $form) use ($t_model) {
return $form->app->jsRedirect(['changed'=>'true']);
$form->add(['Button', 'Back', 'icon'=>'left arrow'])->link(['index']);
} catch (\Exception $e) {
$app->add(['Message', 'Incorrect token', 'error'])
$app->add(['Button', 'Back', 'icon'=>'left arrow'])->link(['index']);
$form = $app->add(['Form']);
$form->add(['Button', 'Back', 'secondary', 'icon'=>'left arrow'])->link(['login']);
$form->onSubmit(function($form) use ($app){
// look up user by email
$user = new Model\User($app->db);
$user->tryLoadBy('email', $form->model['email']);
if (!$user->loaded()) {
return $form->error('email', 'Email is specified incorrectly');
//$token = $user->ref('Tokens:password-reset')->save()['token'];
return $form->app->jsRedirect(['sent'=>true]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.