示例#1
0
<?php

// Form Submission
if (Form::submitted("add-user-uni6")) {
    // Check if all of the input you sent is valid:
    Validate::variable("Handle", $_POST['handle'], 1, 22);
    Validate::text("Display Name", $_POST['display_name'], 3, 22);
    Validate::password($_POST['password']);
    Validate::email($_POST['email']);
    // Check if the handle has already been taken
    if (AppAccount::handleTaken($_POST['handle'])) {
        Alert::error("Handle Taken", "That handle has already been taken", 1);
    }
    if (Database::selectOne("SELECT email FROM users WHERE email=? LIMIT 1", array($_POST['email']))) {
        Alert::error("Email", "That email already exists.", 1);
    }
    // Final Validation Test
    if (Validate::pass()) {
        Database::startTransaction();
        $uniID = 0;
        // Check if the account already exists
        if ($checkAuth = Database::selectValue("SELECT uni_id FROM users WHERE handle=? LIMIT 1", array($_POST['handle']))) {
            $uniID = (int) $checkAuth;
        } else {
            if ($regSuccess = Database::query("INSERT INTO users (handle, display_name, email, password, date_joined, auth_token, verified) VALUES (?, ?, ?, ?, ?, ?, ?)", array($_POST['handle'], $_POST['display_name'], $_POST['email'], Security_HashPassword::set($_POST['password']), time(), Security_Hash::random(22, 72), 1))) {
                $uniID = (int) Database::$lastID;
                if (isset($_POST['send_email'])) {
                    // Email a verification letter
                    AppVerification::sendVerification($uniID);
                    Alert::success("Email Sent", "The account was created successfully! A verification email has been sent to " . $_POST['email'] . "!");
                } else {