function actionIndex() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!ClearInput::validate_email($_POST['email'])) { $errors[] = 'Email не валидный'; } $email = $_POST['email']; $password = ClearInput::clearInput($_POST['password'], 's'); if (strlen($password) < 6) { $errors[] = 'Введено меньше 6 символов'; } if (!($user = $this->model->getUserByEmail($email))) { $errors[] = 'Неверен Email'; } if ($user['password'] != UserModel::encrypt_pass($password)) { $errors[] = "Пароль не верен"; } if (!isset($errors)) { $hash = md5(UserModel::generateCode(10)); $this->model->updateUserHashById($user['id'], $hash); $ses_data = array('id' => $user['id'], 'name' => $user['name'], 'role' => $user['role']); $this->session->start($ses_data, $hash); if ($user['role'] == 2) { header("Location: /admin/"); } else { header("Location: / "); } } } $data = array('title' => 'Авторизация', 'is_logged' => Session::is_logged(), 'user_name' => isset($_SESSION['user_name']) ? $_SESSION['user_name'] : null, 'errors' => isset($errors) ? $errors : null); $this->view->render('auth_view.twig', $data); }
function actionIndex() { $managers = $this->model->getManagers(); /* Google capcha settings */ $config = parse_ini_file(ROOT . "/app/config/config.ini"); $secret = $config['Secret_key']; $publicKey = $config['Site_key']; if ($_SERVER["REQUEST_METHOD"] == "POST") { $recaptcha = $_POST['g-recaptcha-response']; if (!empty($recaptcha)) { $google_url = "https://www.google.com/recaptcha/api/siteverify"; $ip = $_SERVER['REMOTE_ADDR']; $url = $google_url . "?secret=" . $secret . "&response=" . $recaptcha . "&remoteip=" . $ip; $res = $this->getCurlData($url); $res = json_decode($res, true); //reCaptcha введена if ($res['success']) { $fio = ClearInput::clearInput($_POST['fio'], 's'); if (mb_strlen($fio) < 6) { $errors[] = 'Поле ФИО должно иметь больше 6 символов'; } if (!($phone = ClearInput::cheackPhone($_POST['tel']))) { $errors[] = 'Телефон должен быть из 10 цифр например: 044 537 02 22'; } if (!($email = ClearInput::validate_email($_POST['email']))) { $errors[] = 'Email не валидный'; } $message = ClearInput::clearInput($_POST['message'], 's'); if (mb_strlen($message) < 6) { $errors[] = 'Сообщение должно иметь больше 6 символов'; } } else { $errors[] = "Please re-enter your reCAPTCHA."; } } else { $errors[] = "Please re-enter your reCAPTCHA."; } if (!isset($errors)) { $body = "ФИО: {$fio} <br/>\n Телефон: {$phone} <br/>\n Email: {$email} <br/>\n {$message}"; $subject = 'Форма связаться с нами'; $emails = $config['admin_email']; try { $mail = new SendEmail($body, $emails, $subject); $result = 'Письмо успешно отправлено'; } catch (Exception $e) { $errors[] = $e->getMessage(); } } } $products = new ProductsModel(); $data = array('title' => 'Контакты', 'is_left_slider' => true, 'is_right_slider' => true, 'is_logged' => Session::is_logged(), 'categories' => $products->get_categories(), 'products' => $products->get_data(), 'managers' => $managers, 'errors' => isset($errors) ? $errors : null, 'result' => isset($result) ? $result : null, 'capchaPublicKey' => $publicKey); $this->view->render('contact_view.twig', $data); }