$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')); $app->redirect($app->view()->url('/session/forgotpassword')); } });
} $params['attributes'] = $attributes; if (isset($params['cart'])) { add_to_cart($app, $db, $params); } elseif (isset($params['wishlist'])) { add_to_wish_list($app, $db, $params); } }); $app->get('/shop/checkout', $require_ssl, function () use($app, $db) { $app->view()->set_template('layouts/basic.php'); $app->render('shop/checkout.php', array('page_title' => 'Checkout Options')); }); $app->get('/shop/cccheckout', $require_ssl, function () use($app, $db) { $flash = $app->view()->getData('flash'); if (!isset($flash['data'])) { $user = \Data\UserRepository::get_user_by_id($db, $_SESSION['user_id']); if ($user) { \Helpers\User::copy_user_to_flash($user); } } $checkout_errors = isset($flash['checkout_errors']) ? $flash['checkout_errors'] : array(); $app->view()->set_template('layouts/basic.php'); $app->render('shop/cccheckout.php', array('page_title' => 'Checkout', 'checkout_errors' => $checkout_errors)); }); $app->post('/shop/cccheckout', $require_ssl, function () use($app, $db, $config) { $cart = $app->view()->getData('cart'); $data = $app->request()->post(); if (isset($cart['messages']) && count($cart['messages'])) { $app->flash('checkout_errors', $cart['messages']); $app->flash('data', $data); $app->redirect($app->view()->url_secure('/shop/checkout'));
$app->view()->set_template('layouts/basic.php'); $app->render('users/profile.php', array('page_title' => $app->view()->tr('pages.changepassword'), 'errors' => $errors)); }); $app->post('/users/:id/account', $require_ssl, $authenticate, function ($id) use($app, $db) { if ($id != $_SESSION['user_id']) { $app->notFound(); } include BASE_URI . DS . 'routes' . DS . 'validators' . DS . 'profile.php'; $data = $app->request()->post(); $errors = validate($data); if ($errors) { $app->flash('errors', $errors); $app->redirect($app->view()->url_secure('/users/' . $id . '/account')); } $data['use_same_address'] = isset($data['use_same_address']) ? 1 : 0; $stmt = \Data\UserRepository::update_user($db, $data, $id); if ($stmt) { $app->flash('info', 'User Updated.'); $app->redirect($app->view()->url('/users/' . $id)); } else { $app->error(new \Exception('Error updating user. Please, try again later.')); } }); $app->get('/users/:id/orders', $authenticate, function ($id) use($app, $db) { if ($id != $_SESSION['user_id']) { $app->notFound(); } $orders = \Data\OrderRepository::get_orders_by_user_id($db, $id); $app->view()->set_template('layouts/basic.php'); $app->render('users/orders.php', array('page_title' => 'Your Orders', 'orders' => $orders)); });