Create new user

@param   string
@param   string
@param   string  must contain valid email address
@param   int     group id
@param   Array
@return  bool
772659
public function create_user($username, $password, $email, $group = 1, Array $profile_fields = array())
	{
		// prep the password
		$password = trim($password);

		// and validate the email address
		$email = filter_var(trim($email), FILTER_VALIDATE_EMAIL);

		// bail out if we're missing username, password or email address
		if (empty($username) or empty($password) or empty($email))
		{
			throw new \SimpleUserUpdateException('Username, password or email address is not given, or email address is invalid', 1);
		}

		// check if we already have an account with this email address or username
		$duplicate = \Model\Auth_User::query()
			->select(\Config::get('ormauth.table_columns', array()))
			->where('username', '=', $username)
			->or_where('email', '=', $email)
			->get_one();

		// did we find one?
		if ($duplicate)
		{
			// bail out with an exception
			if (strtolower($email) == strtolower($duplicate->email))
			{
				throw new \SimpleUserUpdateException('Email address already exists', 2);
			}
			else
			{
				throw new \SimpleUserUpdateException('Username already exists', 3);
			}
		}

		// do we have a logged-in user?
		if ($currentuser = \Auth::get_user_id())
		{
			$currentuser = $currentuser[1];
		}
		else
		{
			$currentuser = 0;
		}

		// create the new user record
		$user = \Model\Auth_User::forge(array(
			'username'        => (string) $username,
			'password'        => $this->hash_password((string) $password),
			'email'           => $email,
			'group_id'        => (int) $group,
			'last_login'      => 0,
			'previous_login'  => 0,
			'login_hash'      => '',
			'user_id'         => $currentuser,
			'created_at'	  => \Date::forge()->get_timestamp(),
			'updated_at'      => 0,
		));

		// load all additional data, passed as profile fields
		$user->from_array($profile_fields);

		// save the new user record
		try
		{
			$result = $user->save();
		}
		catch (\Exception $e)
		{
			$result = false;
		}

		// and the id of the created user, or false if creation failed
		return $result ? $user->id : false;
	}
10418
public com.authy.api.User createUser(String email, String phone) {
		return createUser(email, phone, DEFAULT_COUNTRY_CODE);
	}
941668
public function createUser($login_name, $organization, $userClassName, $userId)
    {
        $now = new \MUtil_Db_Expr_CurrentTimestamp();;

        $values['gul_user_class'] = $userClassName;
        $values['gul_can_login']  = 1;
        $values['gul_changed']    = $now;
        $values['gul_changed_by'] = $userId;

        $select = $this->db->select();
        $select->from('gems__user_logins', array('gul_id_user'))
                ->where('gul_login = ?', $login_name)
                ->where('gul_id_organization = ?', $organization)
                ->limit(1);

        // Update class definition if it already exists
        if ($login_id = $this->db->fetchOne($select)) {
            $where = implode(' ', $select->getPart(\Zend_Db_Select::WHERE));
            $this->db->update('gems__user_logins', $values, $where);

        } else {
            $values['gul_login']           = $login_name;
            $values['gul_id_organization'] = $organization;
            $values['gul_created']         = $now;
            $values['gul_created_by']      = $userId;

            $this->db->insert('gems__user_logins', $values);
        }

        return $this->getUser($login_name, $organization);
    }
870400
public function Synchronize($UserKey, $Data) {
      $UserID = 0;
      
      $Attributes = ArrayValue('Attributes', $Data);
      if (is_string($Attributes))
         $Attributes = @unserialize($Attributes);

      if (!is_array($Attributes))
         $Attributes = array();

      // If the user didnt log in, they won't have a UserID yet. That means they want a new
      // account. So create one for them.
      if (!isset($Data['UserID']) || $Data['UserID'] <= 0) {
      
         // Prepare the user data.
         $UserData['Name'] = $Data['Name'];
         $UserData['Password'] = RandomString(16);
         $UserData['Email'] = ArrayValue('Email', $Data, 'no@email.com');
         $UserData['Gender'] = strtolower(substr(ArrayValue('Gender', $Data, 'u'), 0, 1));
         $UserData['HourOffset'] = ArrayValue('HourOffset', $Data, 0);
         $UserData['DateOfBirth'] = ArrayValue('DateOfBirth', $Data, '');
         $UserData['CountNotifications'] = 0;
         $UserData['Attributes'] = $Attributes;
         $UserData['InsertIPAddress'] = Gdn::Request()->IpAddress();
         if ($UserData['DateOfBirth'] == '')
            $UserData['DateOfBirth'] = '1975-09-16';
            
         // Make sure there isn't another user with this username.
         if ($this->ValidateUniqueFields($UserData['Name'], $UserData['Email'])) {
            if (!BanModel::CheckUser($UserData, $this->Validation, TRUE))
               throw PermissionException('Banned');
            
            // Insert the new user.
            $this->AddInsertFields($UserData);
            $UserID = $this->_Insert($UserData);
         }

         if ($UserID) {
            $NewUserRoleIDs = $this->NewUserRoleIDs();
            
            // Save the roles.
            $Roles = GetValue('Roles', $Data, FALSE);
            if (empty($Roles))
               $Roles = $NewUserRoleIDs;
            
            $this->SaveRoles($UserID, $Roles, FALSE);
         }
      } else {
         $UserID = $Data['UserID'];
      }
      
      // Synchronize the transientkey from the external user data source if it is present (eg. WordPress' wpnonce).
      if (array_key_exists('TransientKey', $Attributes) && $Attributes['TransientKey'] != '' && $UserID > 0)
         $this->SetTransientKey($UserID, $Attributes['TransientKey']);

      return $UserID;
   }
586184
private function createUser($sendEmail = true)
	{
		$model = new RegisterForm;

		if (!empty($_POST))
		{
			$model->attributes = $_POST;

			// Save the user's information
			if ($model->save($sendEmail))
				return Users::model()->findByAttributes(array('email' => $_POST['email']))->getAPIAttributes(array('password'), array('role', 'metadata'));
			else
				return $this->returnError(400, NULL, $model->getErrors());
		}

		throw new CHttpException(400, Yii::t('Api.user', 'An unexpected error occured fulfilling your request.'));
	}
225980
function user_signup($user, $notify=true) {
        global $CFG, $DB, $PAGE, $OUTPUT;

        require_once($CFG->dirroot.'/user/profile/lib.php');
        require_once($CFG->dirroot.'/user/lib.php');

        if ($this->user_exists($user->username)) {
            print_error('auth_ldap_user_exists', 'auth_ldap');
        }

        $plainslashedpassword = $user->password;
        unset($user->password);

        if (! $this->user_create($user, $plainslashedpassword)) {
            print_error('auth_ldap_create_error', 'auth_ldap');
        }

        $user->id = user_create_user($user, false, false);

        user_add_password_history($user->id, $plainslashedpassword);

        // Save any custom profile field information
        profile_save_data($user);

        $userinfo = $this->get_userinfo($user->username);
        $this->update_user_record($user->username, false, false, $this->is_user_suspended((object) $userinfo));

        // This will also update the stored hash to the latest algorithm
        // if the existing hash is using an out-of-date algorithm (or the
        // legacy md5 algorithm).
        update_internal_user_password($user, $plainslashedpassword);

        $user = $DB->get_record('user', array('id'=>$user->id));

        \core\event\user_created::create_from_userid($user->id)->trigger();

        if (! send_confirmation_email($user)) {
            print_error('noemail', 'auth_ldap');
        }

        if ($notify) {
            $emailconfirm = get_string('emailconfirm');
            $PAGE->set_url('/auth/ldap/auth.php');
            $PAGE->navbar->add($emailconfirm);
            $PAGE->set_title($emailconfirm);
            $PAGE->set_heading($emailconfirm);
            echo $OUTPUT->header();
            notice(get_string('emailconfirmsent', '', $user->email), "{$CFG->wwwroot}/index.php");
        } else {
            return true;
        }
    }
1184856
public function create_user($email, $name, $mention_name = null,
                              $title = null, $is_group_admin = 0,
                              $password = null, $timezone = null) {
    $args = array(
      'email' => $email,
      'name'  => $name,
    );

    if ($mention_name) {
      $args['mention_name'] = $mention_name;
    }

    if ($title) {
      $args['title'] = $title;
    }

    if ($is_group_admin) {
      $args['is_group_admin'] = (int)$is_group_admin;
    }

    if ($password) {
      $args['password'] = $password;
    }

    // @see http://api.hipchat.com/docs/api/timezones
    if ($timezone) {
      $args['timezone'] = $timezone;
    }

    // Return the std object
    return $this->make_request('users/create', $args, 'POST');
  }
402783
public function create(array $input) {
    $data = array (
            "email"          => isset($input["email"]) ? $input["email"] : $input["copyEmail"],
            "password"       => $input["password"],
            "activated"      => $input["activated"],
            "preferred_lang" => isset($input["preferred_lang"]) ? $input["preferred_lang"] : Config::get('authentication::default_preferred_lang')
    );
    try {
      $user = $this->sentry->createUser($data);
    } catch (CartaUserExists $e) {
      throw new UserExistsException;
    }

    return $user;
  }
229146
def new(cls,
            username,
            password=None,
            email=None,
            first_name="",
            last_name="",
            login_method=None,
            role="MEMBER"
            ):
        
        data = {
            "first_name": first_name,
            "last_name": last_name,
            "email": email
        }

        if not password:
            password = utils.generate_random_string()

        username = username.strip().lower()
        if "@" in username and not email:
            if not utils.is_email_valid(username):
                exceptions.AuthError(_("Invalid username"))
            data["email"] = username
        elif email:
            if not utils.is_email_valid(email):
                exceptions.AuthError(_("Invalid username"))

        if not utils.is_username_valid(username):
            exceptions.AuthError(_("Invalid username"))
        if not utils.is_password_valid(password):
            raise exceptions.AuthError(_("Password is invalid"))

        if cls.get_by_username(username):
            raise exceptions.AuthError(_("Username exists already"))
        _email = data.get("email")
        if _email:
            if cls.get_by_email(_email):
                raise exceptions.AuthError(_("Email address exists already"))

        role = AuthUserRole.get_by_name(role or "MEMBER")
        if not role:
            raise exceptions.AuthError(_("Invalid user role"))

        data.update({
            "username": username,
            "password_hash": cls.encrypt_password(password),
            "email_verified": False,
            "login_method": login_method,
            "role": role,
            "status": cls.STATUS_ACTIVE
        })
        user = cls.create(**data)
        user.reset_secret_key()
        return user
1057082
@Override
    public CommandGroup createCommandGroup(String groupId, Object[] members) {
		return createCommandGroup(groupId, members, false, null);
	}
823637
public function createUser($data) {
        $user = new User;

        $user->name       = $data['name'];
        $user->email      = $data['email'];
        $user->password   = bcrypt($data['password']);

        if ($data['activated'] != "1") {
            $user->activated = 0;
        }

        if ($data['enabled'] != "1") {
            $user->enabled = 0;
        }


        // two factor authorization
        // the front-end registrationdoes not set a value for this field,
        // but the admin does
        if ($data['two_factor_auth_enabled'] != "1") {
            $user->two_factor_auth_enabled = 0;
        } else {
            $user->two_factor_auth_enabled = 1;
        }
        $user->phone_country_code      = $data['phone_country_code'];
        $user->phone_number            = $data['phone_number'];



        // When the admin is adding a new user, use their user id
        // for the created_by and updated_by fields. When no
        // one is logged in during this user creation process, it
        // means that someone is initiating their own registration
        // via the front-end. In which case, use the user id 
        // specified in the auth config file.

        if (isset(Auth::user()->id)) {
            $user->created_by  = Auth::user()->id;
            $user->updated_by  = Auth::user()->id;
        } else {
            $user->created_by  = config('lasallecmsusermanagement.auth_user_id_for_created_by_for_frontend_user_registration');
            $user->updated_by  = config('lasallecmsusermanagement.auth_user_id_for_created_by_for_frontend_user_registration');
        }

        // INSERT!
        $saveWentOk = $user->save();

        // If the save to the database table went ok, then let's INSERT related IDs into the pivot tables,
        if ($saveWentOk) {
            // INSERT into the pivot table
            $this->associateRelatedRecordsToNewRecord(
                $user,
                $data['groups'],
                'Lasallecms\Usermanagement\Models',
                'Group'
            );

            return true;
        }

        return false;
    }
70203
public function create(Google_Service_PeopleService_CreateContactGroupRequest $postBody, $optParams = array())
  {
    $params = array('postBody' => $postBody);
    $params = array_merge($params, $optParams);
    return $this->call('create', array($params), "Google_Service_PeopleService_ContactGroup");
  }
957807
public static function create(string $username, string $email, string $password) : User
    {
        $user = new User();
        $user->username = $username;
        $user->email    = $email;
        $user->status   = self::STATUS_ACTIVE;
        $user->setPassword($password);
        $user->generateAuthKey();
        return $user;
    }
668007
private function createCustomerWithUserAccount(
        $email,
        $password,
        $enabled = true,
        $firstName = null,
        $lastName = null,
        $role = null
    ) {
        /** @var ShopUserInterface $user */
        $user = $this->userFactory->createNew();

        /** @var CustomerInterface $customer */
        $customer = $this->customerFactory->createNew();

        $customer->setFirstName($firstName);
        $customer->setLastName($lastName);
        $customer->setEmail($email);

        $user->setUsername($email);
        $user->setPlainPassword($password);
        $user->setEnabled($enabled);
        if (null !== $role) {
            $user->addRole($role);
        }

        $customer->setUser($user);

        $this->sharedStorage->set('customer', $customer);

        return $customer;
    }
445506
public function createUser($user, $roles = [])
    {
        // Create the new user
        $password = [
            'password' => bcrypt(Str::random(10)),
        ];

        $user = array_merge($password, $user);
        $user = $this->user->create($user);

        if (! $user) {
            return $user;
        }

        // Fire the creating event.
        event(new UserCreating($user));

        // Add the extra details needed to finish them.
        // Add the user details.
        $this->userDetails->create($this->getUserDetailsFromRequest($user));

        // Assign the user to the default group
        if (is_array($roles) || $roles instanceof Collection) {
            $user->syncRoles($roles);
        }

        // the user should always have the default role.
        if (empty($roles) || $roles === '') {
            $user->assignRole(config('jumpgate.users.default_role'));
        }

        // If we do not require activation, set the user as active.
        if (! config('jumpgate.users.require_email_activation')) {
            $user->updateActivationDetails();
        }

        // New user needs to set their password.
        $user->generateNewUserPasswordResetToken();

        // Fire the created event.
        event(new UserCreated($user));

        return $user;
    }
578065
public static function create($method = 'GET', $url = null, $config = [])
    {
        if (func_num_args()) {
            if(!preg_match('~^(?:[a-z]+:)?//~i', $url) || !$defaults = parse_url($url)) {
                throw new NetException("Invalid url: `'{$url}'`.");
            }
            $defaults['username'] = isset($defaults['user']) ? $defaults['user'] : null;
            $defaults['password'] = isset($defaults['pass']) ? $defaults['pass'] : null;
        }
        $config['method'] = strtoupper($method);
        return new static($config + $defaults);
    }
889752
def create_user(cls, username, password, name, email):
        """"""
        config = Config()
        payload = {"username": username,
                   "email": email,
                   "name": name,
                   "password": password, }
        user_creation_resp = requests.post("https://users.{}/users/".format(config.host),
                                           json=payload)
        if user_creation_resp.status_code != 201:
            raise errors.ResourceError("couldnt create user")