Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once '../app/db.php';
- if (isset($_POST['submit'])) {
- $name = htmlspecialchars(trim($_POST['name']));
- $email = htmlspecialchars(trim($_POST['email']));
- $password = htmlspecialchars(trim($_POST['password']));
- $password_confirm = htmlspecialchars(trim($_POST['password-confirm']));
- if (empty(($name) || ($email) || ($password) || ($password_confirm))) {
- header("Location: /register-view?signup=empty");
- exit();
- }
- else {
- if (!preg_match('/^([A-Za-zА-Яа-яЁё]+[\s\,\.\-]*)+$/u', $name)) {
- header("Location: /register-view?signup=invalid");
- exit();
- }
- else {
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- header("Location: /register-view?signup=invalid_email");
- exit();
- }
- else {
- if ($password !== $password_confirm) {
- header("Location: /register-view?signup=different_passwords");
- exit();
- }
- else {
- $selectEmail = $db->prepare("SELECT COUNT(*) as count FROM users WHERE email = ?");
- $email = $_POST['email'];
- $selectEmail->execute(array($email));
- $resultCountEmail = $selectEmail->fetch(PDO::FETCH_OBJ);
- if ($resultCountEmail->count > 0) {
- header("Location: /register-view?signup=user_exists");
- exit();
- }
- else {
- $len = strlen($_POST['password']);
- if ($len < 6) {
- header("Location: /register-view?signup=short_password");
- exit();
- }
- else {
- $password = password_hash($password, PASSWORD_BCRYPT);
- $insertUser = $db->prepare("
- INSERT INTO users(name, email, password)
- VALUES(:name, :email, :password)");
- $insertUser->bindParam(':name', $name);
- $insertUser->bindParam(':email', $email);
- $insertUser->bindParam(':password', $password);
- $insertUser->execute();
- header("Location: /auth-view?signup=success");
- exit();
- }
- }
- }
- }
- }
- }
- } else {
- header("Location: /");
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement