Example #1
0
<?php

include_once "da_access.php";
$userName = $_COOKIE['account_user'];
if ($userName == null) {
    echo "<script type='text/javascript'>";
    echo "window.location.href='login.php?msg=请先登录'";
    echo "</script>";
}
$result = getUserByUserName($userName);
if (mysql_fetch_object($result) == null) {
    echo "<script type='text/javascript'>";
    echo "window.location.href='login.php?msg=请先登录'";
    echo "</script>";
}
Example #2
0
<?php

/**
 * Created by ChenguangBai
 * Date: 2016/2/28
 * return data:
 *				0 --> insert user successfully
 *				1 --> has already exist this user name
 */
include_once "../dao/DBHelper.php";
include_once "../dao/getUser.php";
include_once "../dao/createUser.php";
$userName = $_POST['userName'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$password = $_POST['password'];
$user = mysql_fetch_array(getUserByUserName($userName));
if ($user == null) {
    $result = createUser($userName, $firstName, $lastName, $password);
    if ($result) {
        echo 0;
    }
} else {
    echo 1;
}
Example #3
0
<?php

$error = '';
if (isset($_POST['signup'])) {
    if (empty($_POST['username_signup']) || empty($_POST['password_signup'])) {
        $error = 'Username or Password is invalid!';
    } else {
        $username = $_POST['username_signup'];
        if (existsUserByName($username)) {
            echo '<span class="message">User name "' . $username . '" is already taken!</span>';
            exit;
        }
        $password = $_POST['password_signup'];
        $options = ['cost' => strlen($username)];
        $hashedpass = password_hash($password, PASSWORD_DEFAULT, $options);
        insertIntoUser($username, $hashedpass);
        $user = getUserByUserName($username);
        session_start();
        $_SESSION['login_user'] = $username;
        $_SESSION['user_id'] = $user['id'];
        if (!isset($_SESSION['csrf_token'])) {
            $_SESSION['csrf'] = getToken(16);
        }
        echo '<script>window.location = "profile.php"</script>';
    }
}
<?php

header("Content-Type: application/json");
include "../dbconnection.php";
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$user_name = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string(md5($_POST['password']));
$phone_number = mysql_real_escape_string($_POST['phone']);
$gender = mysql_real_escape_string($_POST['gender']);
$location = mysql_real_escape_string($_POST['location']);
$birth_date = mysql_real_escape_string($_POST['birthday']);
$android_app = mysql_real_escape_string($_POST['android_app']);
$user_emails = getUserByEmail($email);
$user = mysql_fetch_array($user_emails);
if ($email == $user['email']) {
    $status = array('status' => 0, 'error' => 'Email already exits');
    echo json_encode($status);
}
$usernames = getUserByUserName($user_name);
$user_result = mysql_fetch_array($usernames);
if ($user_name == $user_result['user_name']) {
    $status = array('status' => 2, 'error' => 'User name already exits');
    echo json_encode($status);
} else {
    $birth_date = date("Y-m-d", strtotime($birth_date));
    $verificationcode = generateCode(1);
    $activation = md5($email . time());
    $result = registerNewUser($name, $email, $user_name, $password, $gender, $birth_date, $location, $phone_number, $activation, $verificationcode, $android_app);
    $status = array('status' => 1, 'error' => 'User successfully added');
}