コード例 #1
0
ファイル: model.php プロジェクト: victornava/notas
function signupUser($email, $password, $name, $screenName)
{
    global $dbCon;
    if (!Verify::email($email)) {
        echo 'invalid email';
        return;
    }
    if (!Verify::password($password)) {
        echo 'invalid password';
        return;
    }
    if (!Verify::name($name)) {
        echo 'invalid name';
        return;
    }
    if (!Verify::name($screenName)) {
        echo 'invalid screen name';
        return;
    }
    $cols = "email, password, name, screen_name";
    $values = "'{$email}', '{$password}', '{$name}', '{$screenName}'";
    //$dbCon = openConnection();
    $sql = "SELECT user_id FROM users WHERE email='{$email}'";
    $row = $dbCon->query($sql)->fetch(PDO::FETCH_ASSOC);
    if (!$row) {
        //echo $sql;
        $sql = 'INSERT INTO users (' . $cols . ') VALUES (' . $values . ')';
        try {
            $rowCount = $dbCon->exec($sql);
            if ($rowCount > 0) {
                $sql = "SELECT user_id FROM users WHERE email='{$email}'";
                $row = $dbCon->query($sql)->fetch(PDO::FETCH_ASSOC);
                _setNewUserPrefs($row['user_id']);
                loginUser($email, $password);
            } else {
                echo 'Error registering user, plese try again';
            }
        } catch (Exception $e) {
            throw new Exception('DB error ' . $e->getMessage());
        }
    } else {
        echo "e-mail already registered";
    }
}