Esempio n. 1
0
/**
 * add a new user
 *
 * @param   string $user_name  user name
 * @param   string $user_first user first name (for display name)
 * @param   string $user_last  user last name (for display name)
 *
 * @return  array                   array with user id and initial password (user id is FALSE on error)
 */
function ace_db_user_create($user_name, $user_first, $user_last)
{
    ace_db_esc($user_name);
    ace_db_esc($user_first);
    ace_db_esc($user_last);
    $user_name = trim($user_name);
    $user_first = trim($user_first);
    $user_last = trim($user_last);
    if (filter_var($user_name, FILTER_VALIDATE_EMAIL)) {
        if (!ace_db_user_exists($user_name)) {
            $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            $initial_password = substr(str_shuffle($chars), 0, 8);
            $enc_initial_password = sha1($initial_password);
            $sql = "INSERT INTO user (`name`,`first`,`last`,`password`,`state`)\n\t\t            VALUES ('{$user_name}','{$user_first}','{$user_last}','{$enc_initial_password}',1)";
            $db_result = ace_db_query($sql);
            if ($db_result->last_insert_id != 0) {
                $return['password'] = $initial_password;
                $user_id = $db_result->last_insert_id;
                $group_id = ace_db_group_get_id_by_name('Users');
                ace_db_group_add_user($group_id, $user_id);
            } else {
                $user_id = FALSE;
            }
        } else {
            $user_id = FALSE;
        }
    } else {
        $user_id = FALSE;
    }
    $return['user_id'] = $user_id;
    return $return;
}
Esempio n. 2
0
/**
 * returns if a given user account already exists
 *
 * @api
 *
 * @param $user_name
 *
 * @return bool                     TRUE | FALSE
 */
function ace_user_exists($user_name)
{
    return ace_db_user_exists($user_name);
}