Esempio n. 1
0
function SignupPost()
{
    $username = htmlspecialchars($_POST["username"]);
    $email = htmlspecialchars($_POST['email']);
    $password = htmlspecialchars($_POST['password']);
    $passwordConfirm = htmlspecialchars($_POST['passwordconfirm']);
    //username validation
    if (!ModelFacade::checkUsernameAvaiable($username)) {
        $message = "Username: "******" is not available";
    } else {
        if (strlen($username) < 6) {
            $message = "username must be 6 or more characters";
        } else {
            if (!preg_match("/^[a-zA-Z0-9]*\$/", $username)) {
                $message = "username must be alphanumeric";
            } else {
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                    $message = $email . " is not a valid email address";
                } else {
                    if ($_POST["email"] == "" || $_POST["email"] == null) {
                        $message = "email must not be empty";
                    } else {
                        if (!ModelFacade::checkEmailAvaiable($email)) {
                            $message = "Email: " . $email . " has already been used to create an account.";
                        } else {
                            if (strlen($password) < 6) {
                                $message = "password must be more then 6 characters";
                            } else {
                                if ($password == "" || $password == null) {
                                    $message = "password must not be empty";
                                } else {
                                    if ($password != $passwordConfirm) {
                                        $message = "passwords do not match";
                                    } else {
                                        //signup user
                                        ModelFacade::signup($_POST["username"], $_POST["password"], $_POST['email']);
                                        //log user in
                                        ModelFacade::login($_POST["username"], $_POST["password"]);
                                        //store that this is a new signup so user gets nice notification
                                        $_SESSION['newsignup'] = true;
                                        //redirect to index
                                        header('Location: Index.php');
                                        exit;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //
    include_once "/Views/Signup.html";
}
Esempio n. 2
0
function loginPost()
{
    if (isset($_POST["identify"]) && isset($_POST["password"])) {
        //Attemp to log user in
        ModelFacade::login($_POST["identify"], $_POST["password"]);
        if (ModelFacade::checkLoggedIn()) {
            //redirect
            header('Location: Index.php');
            exit;
        } else {
            if (ModelFacade::checkIfBanned($_POST["identify"])) {
                $message = "Your account has been banned!";
                include_once "/Views/Login.html";
            } else {
                $message = "Username or password does not exist";
                include_once "/Views/Login.html";
            }
        }
    } else {
        $message = "Please enter username and password";
        include_once "/Views/Login.html";
    }
}