$flash = $app->view()->getData('flash');
            $flash['error'] = "Activation code expired, please try the forgotton password link again";
            $app->redirect("/login");
        }
    } catch (ResourceNotFoundException $e) {
        // return 404 server error
        $app->response()->status(404);
    } catch (Exception $e) {
        $app->response()->status(400);
        $app->response()->header('X-Status-Reason', $e->getMessage());
    }
});
$app->post("/forgotpassword", function () use($app) {
    $email = $app->request()->post('email');
    if (trim($email) == false || preg_match("/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,3})+\$/", $email) === 0 || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $app->flash('error', "Please enter in a valid email.<br />");
        $app->redirect('/forgotpassword');
    }
    //run the forgotten password method to email an activation code to the user
    $auth = new Authentication($email);
    if ($auth->fogottenPassword()) {
        //if there were no errors
        $app->redirect("/success");
    } else {
        $app->flash('error', $auth->getError());
        $app->redirect('/forgotpassword');
    }
});
$app->get("/success", function () use($app) {
    $app->render("Authentication/Success.php");
});
Пример #2
0
     }
     if (is_null($email)) {
         $error[] = "Email";
         $e_email = true;
     }
     if (count($error) > 0) {
         $loadfile = "login/login_error.tpl";
     } else {
         $auth->setEmail($email);
         $auth->setUsername($username);
         $auth->setPassword($password);
         if ($auth->Authenticate()) {
             $loadfile = "login/login_successful.tpl";
             $redirect = "/#1";
         } else {
             $loadfile = "login/login_{$auth->getError()}.tpl";
             switch ($auth->getError()) {
                 case "email":
                     $e_email = true;
                     break;
                 case "username":
                     $e_username = true;
                     break;
                 case "password":
                     $e_password = true;
                     break;
             }
         }
     }
 } else {
     $loadfile = "login/login_form.tpl";