PHP User::create_user Examples

PHP User::create_user - 14 examples found. These are the top rated real world PHP examples of User::create_user extracted from open source projects. You can rate examples to help us improve the quality of examples.
 /**
  * Gets current user's user entity and includes the necessary classes
  * 
  * @return void
  **/
 function init($args = array())
 {
     $this->parent->add_stylesheet(REASON_HTTP_BASE_PATH . 'css/user_settings/user_settings.css', '', true);
     $user_netid = $this->get_user_netid();
     $user_class = new User();
     $this->user = $user_class->get_user($user_netid);
     if (!$this->user && $this->auto_create_users) {
         $this->user = $user_class->create_user($user_netid);
     }
     if ($this->user) {
         if (isset($this->request['user_setting'])) {
             $this->user_setting_selection = $this->request['user_setting'];
         }
         foreach ($this->settings_mapping as $key => $value) {
             include_once $value['class_filename'];
             $this->settings_mapping[$key]['object'] = new $value['class_name']();
             $this->settings_mapping[$key]['object']->init();
             $this->settings_mapping[$key]['object']->user = $this->user;
         }
         if ($this->user_setting_selection) {
             $this->current_setting_object = $this->settings_mapping[$this->user_setting_selection]['object'];
         }
     }
 }
<?php

session_start();
include_once "functions/users.php";
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])) {
    $ret = User::create_user(array('email' => $_POST['email'], 'username' => $_POST['username'], 'password' => $_POST['password']));
    if ($ret) {
        echo "success.<br>";
    } else {
        echo "fail.<br>";
    }
}
?>

<form action="register.php" method="post">
    email <input name="email"><br>
    username <input name="username"><br>
    password <input name="password"><br>
    <button type="submit">register</button>
</form>
/**
 * Insert an user into the database.
 *
 * Can update a current user or insert a new user based on whether the user's ID
 * is present.
 *
 * Can be used to update the user's info (see below), set the user's role, and
 * set the user's preference on whether they want the rich editor on.
 *
 * Most of the $userdata array fields have filters associated with the values.
 * The exceptions are 'rich_editing', 'role', 'jabber', 'aim', 'yim',
 * 'user_registered', and 'ID'. The filters have the prefix 'pre_user_' followed
 * by the field name. An example using 'description' would have the filter
 * called, 'pre_user_description' that can be hooked into.
 *
 * The $userdata array can contain the following fields:
 * 'ID' - An integer that will be used for updating an existing user.
 * 'user_pass' - A string that contains the plain text password for the user.
 * 'user_login' - A string that contains the user's username for logging in.
 * 'user_nicename' - A string that contains a URL-friendly name for the user.
 *		The default is the user's username.
 * 'user_url' - A string containing the user's URL for the user's web site.
 * 'user_email' - A string containing the user's email address.
 * 'display_name' - A string that will be shown on the site. Defaults to user's
 *		username. It is likely that you will want to change this, for appearance.
 * 'nickname' - The user's nickname, defaults to the user's username.
 * 'first_name' - The user's first name.
 * 'last_name' - The user's last name.
 * 'description' - A string containing content about the user.
 * 'rich_editing' - A string for whether to enable the rich editor. False
 *		if not empty.
 * 'user_registered' - The date the user registered. Format is 'Y-m-d H:i:s'.
 * 'role' - A string used to set the user's role.
 * 'jabber' - User's Jabber account.
 * 'aim' - User's AOL IM account.
 * 'yim' - User's Yahoo IM account.
 *
 * @since 2.0.0
 * @uses $wpdb WordPress database layer.
 * @uses apply_filters() Calls filters for most of the $userdata fields with the prefix 'pre_user'. See note above.
 * @uses do_action() Calls 'profile_update' hook when updating giving the user's ID
 * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
 *
 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
 * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created.
 */
function wp_insert_user($userdata)
{
    global $wpdb;
    if (is_a($userdata, 'stdClass')) {
        $userdata = get_object_vars($userdata);
    } elseif (is_a($userdata, 'WP_User')) {
        $userdata = $userdata->to_array();
    }
    extract($userdata, EXTR_SKIP);
    // Are we updating or creating?
    if (!empty($ID)) {
        $ID = (int) $ID;
        $update = true;
        $old_user_data = WP_User::get_data_by('id', $ID);
    } else {
        $update = false;
        // Hash the password
        $user_pass = wp_hash_password($user_pass);
    }
    $user_login = sanitize_user($user_login, true);
    $user_login = apply_filters('pre_user_login', $user_login);
    //Remove any non-printable chars from the login string to see if we have ended up with an empty username
    $user_login = trim($user_login);
    if (empty($user_login)) {
        return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.'));
    }
    if (!$update && username_exists($user_login)) {
        return new WP_Error('existing_user_login', __('Sorry, that username already exists!'));
    }
    if (empty($user_nicename)) {
        $user_nicename = sanitize_title($user_login);
    }
    $user_nicename = apply_filters('pre_user_nicename', $user_nicename);
    if (empty($user_url)) {
        $user_url = '';
    }
    $user_url = apply_filters('pre_user_url', $user_url);
    if (empty($user_email)) {
        $user_email = '';
    }
    $user_email = apply_filters('pre_user_email', $user_email);
    if (!$update && !defined('WP_IMPORTING') && email_exists($user_email)) {
        return new WP_Error('existing_user_email', __('Sorry, that email address is already used!'));
    }
    if (empty($nickname)) {
        $nickname = $user_login;
    }
    $nickname = apply_filters('pre_user_nickname', $nickname);
    if (empty($first_name)) {
        $first_name = '';
    }
    $first_name = apply_filters('pre_user_first_name', $first_name);
    if (empty($last_name)) {
        $last_name = '';
    }
    $last_name = apply_filters('pre_user_last_name', $last_name);
    if (empty($display_name)) {
        if ($update) {
            $display_name = $user_login;
        } elseif ($first_name && $last_name) {
            /* translators: 1: first name, 2: last name */
            $display_name = sprintf(_x('%1$s %2$s', 'Display name based on first name and last name'), $first_name, $last_name);
        } elseif ($first_name) {
            $display_name = $first_name;
        } elseif ($last_name) {
            $display_name = $last_name;
        } else {
            $display_name = $user_login;
        }
    }
    $display_name = apply_filters('pre_user_display_name', $display_name);
    if (empty($description)) {
        $description = '';
    }
    $description = apply_filters('pre_user_description', $description);
    if (empty($rich_editing)) {
        $rich_editing = 'true';
    }
    if (empty($comment_shortcuts)) {
        $comment_shortcuts = 'false';
    }
    if (empty($admin_color)) {
        $admin_color = 'fresh';
    }
    $admin_color = preg_replace('|[^a-z0-9 _.\\-@]|i', '', $admin_color);
    if (empty($use_ssl)) {
        $use_ssl = 0;
    }
    if (empty($user_registered)) {
        $user_registered = gmdate('Y-m-d H:i:s');
    }
    if (empty($show_admin_bar_front)) {
        $show_admin_bar_front = 'true';
    }
    $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login));
    if ($user_nicename_check) {
        $suffix = 2;
        while ($user_nicename_check) {
            $alt_user_nicename = $user_nicename . "-{$suffix}";
            $user_nicename_check = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login));
            $suffix++;
        }
        $user_nicename = $alt_user_nicename;
    }
    $data = compact('user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered');
    $data = wp_unslash($data);
    $direct = ABSPATH;
    require_once $direct . '/User.php';
    require_once $direct . '/course.php';
    $user = new User();
    if ($update) {
        //echo "hiiiiiiii".compact( 'ID' );
        $get_userlmsid = "select user_lms from wp_users where ID=" . $userdata['ID'];
        $getlms = $wpdb->get_row($get_userlmsid);
        //echo "hiiiiiiii".$getlms->user_lms;
        //echo "hiiiiiiii".$userdata['display_name'];
        //print_r($userdata);
        $response = $user->update_user($getlms->user_lms, $userdata['display_name']);
        //exit();
        $wpdb->update($wpdb->users, $data, compact('ID'));
        $user_id = (int) $ID;
    } else {
        $wpdb->insert($wpdb->users, $data + compact('user_login'));
        $user_id = (int) $wpdb->insert_id;
        //$result_user=$user->create_user(1,$data['display_name'],$user_login,$data['user_pass']);
        $result_user = $user->create_user(1, $data['display_name'], $data['user_email'], $data['user_pass']);
        $qry = 'update wp_users set user_lms=' . $result_user->id . ' where ID=' . $user_id;
        $wpdb->query($qry);
        $config = parse_ini_file($direct . "/config.ini");
        $casurl = $config["casurl"];
        $cookie_set_url = $config["cookieurl"];
        $data = array('username' => $data['user_email'], 'password' => $data['user_pass']);
        $handle = curl_init();
        curl_setopt($handle, CURLOPT_URL, $casurl);
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($handle, CURLOPT_POST, true);
        curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
        $response = json_decode(curl_exec($handle), TRUE);
        if ($response['type'] == "confirmation") {
            setcookie("tgt", $response['tgt'], time() + 3600 * 24, '/', $cookie_set_url);
        } else {
        }
    }
    $user = new WP_User($user_id);
    foreach (_get_additional_user_keys($user) as $key) {
        if (isset(${$key})) {
            update_user_meta($user_id, $key, ${$key});
        }
    }
    if (isset($role)) {
        $user->set_role($role);
    } elseif (!$update) {
        $user->set_role(get_option('default_role'));
    }
    wp_cache_delete($user_id, 'users');
    wp_cache_delete($user_login, 'userlogins');
    if ($update) {
        do_action('profile_update', $user_id, $old_user_data);
    } else {
        do_action('user_register', $user_id);
    }
    return $user_id;
}
Example #4
0
function create_user($ObjectPDO, $params)
{
    // This function is also used by the signup form so be careful for conflicts
    // If something breaks its because I remove this part of the program.
    // require_once($_SERVER['DOCUMENT_ROOT'] . "/reou/includes/const.php");
    // require_once(D_ROOT . "/reou/helpers/users_helper.php");
    // Only admin's can create a new user in this way.
    if (userSignedIn() && userIsAdmin()) {
        // If the users data is being updated.
        if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['_method'])) {
            // If they they are trying to create a new user.
            if ($_POST['_method'] == "post") {
                // Get the post vars and put then in the create user mehots
                // ------ Quick Field Check -----
                unset($_POST['_method']);
                unset($params['_method']);
                $_POST = check_honeypot_fields($_POST);
                // ---------- Field Check End ---------------
                $user = new User($ObjectPDO);
                if ($user->create_user($_POST)) {
                    add_message("alert", "The user has been successfully created");
                    // Direct the admin back to the user list page with the message.
                }
                // If the user is not an admin then move them back one space.
                if (!userIsAdmin()) {
                    if ($_SESSION['id'] != $_POST['userId']) {
                        add_message("error", "there was a problem moving the users");
                        header("Location:" . $_SERVER['REQUEST_URI']);
                        die;
                    }
                }
            } else {
                die("Critical error in creating the user. Incorrect method used");
            }
        }
    } else {
        die("Your not an admin, im not sure how you even got to this page without being detected. users_controller.php");
    }
}
 /**
  * Actions which happen based on the validated data from the form.
  * @access public
  */
 function process()
 {
     // lets make sure the event_agent user exists
     $user = new User();
     if (!$user->get_user('event_agent')) {
         $user->create_user('event_agent');
     }
     $name = str_replace(array($this->delimiter1, $this->delimiter2), '_', $this->get_value('name'));
     $new_data = implode($this->delimiter2, array(strip_tags($this->request_array['date']), strip_tags($name), strip_tags($this->get_value('email')), time()));
     $slot_values = get_entity_by_id($this->request_array['slot_id']);
     $old_data = $slot_values['registrant_data'];
     if (!empty($old_data)) {
         $registrant_data = $old_data . $this->delimiter1 . $new_data;
     } else {
         $registrant_data = $new_data;
     }
     $values = array('registrant_data' => $registrant_data);
     $successful_update = reason_update_entity($this->request_array['slot_id'], get_user_id('event_agent'), $values);
     if ($successful_update) {
         $this->show_form = false;
         $this->send_confirmation_emails();
         $this->show_registration_thanks();
     } else {
         $this->show_registration_error_message();
     }
 }
$selected = mysql_select_db(DB_NAME, $dbhandle) or die("Could not select database");
$file = fopen("/opt/lampp/htdocs/qibla/canvas/cron.log", "w");
//$file = fopen("/u/apps/qibla/canvas/cron.log","w");
fwrite($file, date('m/d/Y h:i:s') . "\n");
fclose($file);
$user = new User();
$course = new Course();
//canvas user propagation
$query = "select * from wp_users where ID not in (select post_id from canvas_post_user)";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
    $lms_result = $user->create_user(1, $row['user_login'], $row['user_email'], $row['user_pass']);
    $query = "insert into canvas_post_user (post_id,canvas_id,description) values(" . $row['ID'] . "," . $lms_result->id . ",'" . mysql_real_escape_string($row['user_login']) . "')";
    mysql_query($query);
}
//canvas teacher propagation
$query = "select * from wp_posts where post_type='teacher' and ID not in (select post_id from canvas_post_teacher)";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
    $lms_result = $user->create_user(1, $row['post_title'], $row['post_name'], "");
    $query = "insert into canvas_post_teacher (post_id,canvas_id,description) values(" . $row['ID'] . "," . $lms_result->id . ",'" . mysql_real_escape_string($row['post_title']) . "')";
    mysql_query($query);
}
//canvas course propagation
$query = "select * from wp_posts where post_type='course' and ID not in (select post_id from canvas_post_course)";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
    $course_id = $row['ID'];
    $lms_course_result = $course->create_course(1, $row['post_id'], $row['post_title'], $row['content']);
    $query = "insert into canvas_post_course (post_id,canvas_id,description) values(" . $row['ID'] . "," . $lms_course_result->id . ",'" . mysql_real_escape_string($row['post_title']) . "')";
    mysql_query($query);
 function createAction()
 {
     $dat = $_POST['user'];
     $user = new User();
     if (isAdmin()) {
         if ($dat['np1'] != $dat['np2']) {
             $_SESSION['flash'][] = array('error', 'Passwords do not match');
             redirect_to(ADMIN_URL . '/users/new');
         }
         if ($user->create_user($dat['username'], $dat['name'], $dat['email'], $dat['admin_privileges'] == 'admin' ? 1 : 0, $dat['allow_email'] == 'allow' ? 1 : 0, $dat['np1'])) {
             $_SESSION['flash'][] = array('info', 'User profile created successfully.');
             redirect_to(ADMIN_URL . '/users/show/' . $user->username);
         } else {
             $_SESSION['flash'][] = array('error', 'Your profile submission failed. ' . $user->status);
             redirect_to(ADMIN_URL . '/users/new');
         }
     } else {
         if ($dat['np1'] != $dat['np2']) {
             $_SESSION['flash'][] = array('error', 'Passwords do not match');
             redirect_to(ADMIN_URL . '/users/signup');
         }
         if ($user->create_user($dat['username'], $dat['name'], $dat['email'], 0, $dat['allow_email'] == 'allow' ? 1 : 0, $dat['np1'])) {
             $_SESSION['flash'][] = array('info', 'Your profile was created successfully. Welcome to Concerto!');
             login_login();
             redirect_to(ADMIN_URL);
         } else {
             $_SESSION['flash'][] = array('error', 'Your profile submission failed. ' . $user->status);
             redirect_to(ADMIN_URL . '/users/signup');
         }
     }
 }
    <body>

    <?php 
echo UI::get_top_bar_logged_out();
?>

    <div id="container">

        <div class="box-shadow card">
            <div class="bold bg card-separator">
                <?php 
if ($signup_successful) {
    ?>
                    <?php 
    // create the user in the database
    if (User::create_user($signup)) {
        echo "Thanks for signing up for Friendbook, " . $signup->firstname . ".";
    } else {
        $signup_successful = false;
        echo "We have encountered a problem on our side. Sorry about that.";
    }
    ?>
                <?php 
} else {
    ?>
                    There were some errors signing you up. Please fix them to proceed.
                <?php 
}
?>
            </div>
            <div class="main-card-content">
Example #9
0
$uname = "";
$pass = "";
$fname = "";
$lname = "";
$gender = "";
$mail = "";
$mob = "";
if (isset($_POST['submit'])) {
    $uname = trim($_POST["uname"]);
    $pass = trim($_POST["pass"]);
    $fname = trim($_POST["fname"]);
    $lname = trim($_POST["lname"]);
    $gender = trim($_POST["gender"]);
    $mail = trim($_POST["mail"]);
    $mob = trim($_POST["mob"]);
    $user_create = User::create_user($fname, $lname, $gender, $mail, $mob, $uname, $pass);
    if ($user_create) {
        $message = "Sucessfully signup";
        //redirect_to("index.php");
    } else {
        $message = "User name already exist";
        //echo "nahi gaya";
    }
}
?>
<html>
<head>
	<title>Signup</title>
	<script language="javascript">
	function validate(){
		if(isNaN(mob.value))
Example #10
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/reou/includes/const.php";
require_once D_ROOT . "/reou/models/User.php";
require_once D_ROOT . "/reou/helpers/users_helper.php";
if ($_SERVER['REQUEST_METHOD'] == "POST" && signin_check_post_params()) {
    // Theres no real reson to do this. Just aliasing the POST params
    $params = $_POST;
    require_once D_ROOT . "/reou/models/database.php";
    // -------- Attempt To Signup -------- //
    $user = new User($db);
    try {
        $results = $user->create_user($params);
        header("location: ../views/courses/course_category.php");
    } catch (Exception $e) {
        // This needs to be an error message
        echo "There was a porblem creating the user check sigup.php";
        $e->getMessage();
    }
}
Example #11
0
function create_admin_user($password)
{
    reason_include_once('classes/user.php');
    $password_hash = sha1($password);
    $my_user = new User();
    $user = $my_user->create_user('admin');
    $user_id = $user->id();
    reason_update_entity($user_id, $user_id, array('unique_name' => 'admin_user', 'user_email' => WEBMASTER_EMAIL_ADDRESS, 'user_password_hash' => $password_hash, 'user_authoritative_source' => 'reason'), false);
    $admin_id = id_of('admin_role');
    $rel_id1 = relationship_id_of('user_to_user_role');
    $rel_id2 = relationship_id_of('site_to_user');
    $ma_id = id_of('master_admin');
    $ls_id = id_of('site_login');
    $pts_id = id_of('page_types_demo_site');
    create_relationship($user_id, $admin_id, $rel_id1, false, true);
    create_relationship($ma_id, $user_id, $rel_id2, false, true);
    create_relationship($ls_id, $user_id, $rel_id2, false, true);
    create_relationship($pts_id, $user_id, $rel_id2, false, true);
    return $user_id;
}
 public function signup()
 {
     $input = Input::all();
     User::create_user($input);
 }
// defined('DS') ? null : define("DS", DIRECTORY_SEPARATOR);
require_once '../../includes/initialize.php';
if ($session->is_logged_in()) {
    redirect_to("index.php");
}
//Give form's submit tag name = "submit"
if (isset($_POST['submit'])) {
    $first_name = trim($_POST['first_name']);
    $last_name = trim($_POST['last_name']);
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    $confirm_password = trim($_POST['confirm_password']);
    // $email = trim($_POST['email']);
    $user = new User();
    // var_dump($user);
    $user->create_user($first_name, $last_name, $username, $password, $confirm_password);
} else {
    // Form has not been submitted
    $first_name = "";
    $last_name = "";
    $username = "";
    $password = "";
    $confirm_password = "";
    // $email = "";
    echo "Fail";
}
include '../layouts/admin_header.php';
?>
	<div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
    <p><a class="navbar-brand text-muted" href="index.php">Photo Gallery</a></p>      
Example #14
0
echo "\n";
if (empty($options['u'])) {
    echo 'A username is required. Please provide a username via -u.' . "\n\n";
    die;
}
$username = (string) $options['u'];
$user = new User();
if ($caller_entity = $user->get_user($caller_username)) {
    $user->set_causal_agent($caller_username);
    echo 'Running as ' . $caller_username . "\n";
} else {
    $caller_entity = $user->create_user($caller_username);
    $user->set_causal_agent($caller_username);
    echo 'Set up to run as ' . $caller_username . "\n";
}
if ($user_entity = $user->get_user($username)) {
    if ($caller_entity->id() != $user_entity->id()) {
        echo 'Username ' . $username . ' already exists.' . "\n";
    }
} else {
    if ($user_entity = $user->create_user($username)) {
        echo 'Username ' . $username . ' created (Reason entity id ' . $user_entity->id() . ')' . "\n";
    } else {
        echo 'Failed to create user.' . "\n\n";
        die;
    }
}
$password = '';
if (!empty($options['p'])) {
    $password = (string) $options['p'];
} elseif (array_key_exists('p', $options)) {
    fwrite(STDOUT, "Enter a password for this user (Hit return to leave password as-is): ");