Esempio n. 1
0
 public function actionLogin()
 {
     $email = '';
     $password = '';
     $remember = '';
     $errors = [];
     if (isset($_POST['submit'])) {
         $email = FL::clearStr($_POST['email']);
         $password = FL::clearStr($_POST['password']);
         if (isset($_POST['remember'])) {
             $remember = $_POST['remember'];
         }
         if (!FL::isEmail($email)) {
             $errors[] = 'Некорректный email';
         }
         if (!FL::isValue($password)) {
             $errors[] = 'Пароль не может быть пустым';
         }
         if (empty($errors)) {
             $user = UserModel::checkRegister($email, $password, $remember);
             if ($user) {
                 Session::createSession('user', $user, true);
                 FL::redirectTo('/cabinet');
             } else {
                 $errors[] = 'Неправильные данные для входа на сайт';
             }
         }
     }
     $categories = CategoryModel::getAllUsingColumns();
     $view = new View();
     $view->categories = $categories;
     $view->email = $email;
     $view->password = $password;
     $view->errors = $errors;
     $view->display('user/login.php');
     return true;
 }
Esempio n. 2
0
 public function actionOrder()
 {
     $userName = '';
     $errors = [];
     $categories = CategoryModel::getAllUsingColumns();
     $productsKeysArray = Session::getSession('products');
     if ($productsKeysArray) {
         $keysArray = array_keys($productsKeysArray);
         $keysString = implode(',', $keysArray);
         if ($keysString) {
             $products = ProductModel::getAll($keysString);
             $amountPrice = CartModel::amountProductsPriceInCart($productsKeysArray, $products);
         }
     }
     $user = UserModel::getUser('user');
     if ($user) {
         $userName = $user->name;
         $userId = $user->id;
     } else {
         $userId = 0;
     }
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $phone = FL::clearStr($_POST['phone']);
         $comment = FL::clearStr($_POST['comment']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isValue($phone)) {
             $errors[] = 'Телефон не может быть пустым';
         }
         if (!FL::isPhone($phone)) {
             $errors[] = 'Невалидный телефон';
         }
         if (!FL::isValue($comment)) {
             $errors[] = 'Комментарий не может быть пустым';
         }
         if (empty($errors)) {
             $productsKeysArray = Session::getSession('products');
             if ($productsKeysArray) {
                 $products = json_encode($productsKeysArray);
             }
             $cart = new CartModel();
             $cart->user_name = $name;
             $cart->user_phone = $phone;
             $cart->user_comment = $comment;
             $cart->user_id = $userId;
             $cart->products = $products;
             $orderId = $cart->save();
             if ($orderId) {
                 Session::deleteSession('products');
                 Session::createSession('message', 'Заказ оформлен!');
                 FL::redirectTo('/cart');
             }
         }
     } else {
         $countProducts = CartModel::countProductsInCart();
         if ($countProducts <= 0) {
             FL::redirectTo('/');
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->amountPrice = $amountPrice;
     $view->userName = $userName;
     $view->errors = $errors;
     $view->display('cart/order.php');
     return true;
 }