コード例 #1
0
ファイル: session.php プロジェクト: jvillasante/wildvapor
});
$app->get('/session/forgotpassword', function () use($app) {
    $flash = $app->view()->getData('flash');
    $errors = isset($flash['errors']) ? $flash['errors'] : array();
    $app->view()->set_template('layouts/basic.php');
    $app->render('session/forgotpassword.php', array('page_title' => $app->view()->tr('pages.forgotpassword'), 'errors' => $errors));
});
$app->post('/session/forgotpassword', function () use($app, $db, $config) {
    include BASE_URI . DS . 'routes' . DS . 'validators' . DS . 'forgotpassword.php';
    $data = $app->request()->post();
    $errors = validate($data);
    if ($errors) {
        $app->flash('errors', $errors);
        $app->redirect($app->view()->url('/session/forgotpassword'));
    }
    $user = \Data\UserRepository::get_user_by_email($db, $data['email']);
    if ($user) {
        $password = substr(md5(uniqid(rand(), true)), 10, 15);
        if (\Data\UserRepository::update_password($db, $password, $user['id'])) {
            $result = sendForgotPasswordMail($user, $password, $config);
            if (!is_array($result)) {
                $app->flash('info', $result);
                $app->redirect($app->view()->url_secure('/session/login'));
            } else {
                $app->error(new \Exception($result['error']));
            }
        } else {
            $app->error(new \Exception($app->view()->tr('session.forgot.system.error')));
        }
    } else {
        $app->flash('error', $app->view()->tr('session.forgot.email.error'));