本文整理汇总了PHP中UserInfo::add方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInfo::add方法的具体用法?PHP UserInfo::add怎么用?PHP UserInfo::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserInfo
的用法示例。
在下文中一共展示了UserInfo::add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCreateLegacy
public function testCreateLegacy()
{
$ui = \UserInfo::add(array('uName' => 'andrew', 'uEmail' => 'andrew@concrete5.org'));
$this->assertEquals(1, $ui->getUserID());
$this->assertEquals('andrew', $ui->getUserName());
$this->assertEquals('andrew@concrete5.org', $ui->getUserEmail());
$ui = \Concrete\Core\User\UserInfo::add(array('uName' => 'andrew2', 'uEmail' => 'andrew2@concrete5.org'));
$this->assertEquals(2, $ui->getUserID());
$this->assertEquals('andrew2', $ui->getUserName());
$this->assertEquals('andrew2@concrete5.org', $ui->getUserEmail());
}
示例2: createUser
protected function createUser()
{
// Make sure that this extractor supports everything we need.
if (!$this->supportsEmail() && $this->supportsUniqueId()) {
throw new Exception('Email and unique ID support are required for user creation.');
}
// Make sure that email is verified if the extractor supports it.
if ($this->supportsVerifiedEmail() && !$this->isEmailVerified()) {
throw new Exception('Please verify your email with this service before attempting to log in.');
}
$email = $this->getEmail();
if (\UserInfo::getByEmail($email)) {
throw new Exception('Email is already in use.');
}
$first_name = "";
$last_name = "";
$name_support = array('full' => $this->supportsFullName(), 'first' => $this->supportsFirstName(), 'last' => $this->supportsLastName());
if ($name_support['first'] && $name_support['last']) {
$first_name = $this->getFirstName();
$last_name = $this->getLastName();
} elseif ($name_support['full']) {
$reversed_full_name = strrev($this->getFullName());
list($reversed_last_name, $reversed_first_name) = explode(' ', $reversed_full_name, 2);
$first_name = strrev($reversed_first_name);
$last_name = strrev($reversed_last_name);
}
$username = null;
if ($this->supportsUsername()) {
$username = $this->getUsername();
}
if ($username === null) {
if ($first_name || $last_name) {
$username = preg_replace('/[^a-z0-9\\_]/', '_', strtolower($first_name . ' ' . $last_name));
$username = trim(preg_replace('/_{2,}/', '_', $username), '_');
} else {
$username = preg_replace('/[^a-zA-Z0-9\\_]/i', '_', strtolower(substr($email, 0, strpos($email, '@'))));
$username = trim(preg_replace('/_{2,}/', '_', $username), '_');
}
}
$unique_username = $username;
$append = 1;
while (\UserInfo::getByUserName($unique_username)) {
// This is a heavy handed way to do this, but it must be done.
$unique_username = $username . '_' . $append++;
}
$username = $unique_username;
$data = array();
$data['uName'] = $username;
$data['uPassword'] = "";
$data['uEmail'] = $email;
$data['uIsValidated'] = 1;
$user_info = \UserInfo::add($data);
if (!$user_info) {
throw new Exception('Unable to create new account.');
}
if ($group_id = intval($this->registrationGroupID(), 10)) {
$group = \Group::getByID($group_id);
if ($group && is_object($group) && !$group->isError()) {
$user = \User::getByUserID($user_info->getUserID());
$user->enterGroup($group);
}
}
$key = \UserAttributeKey::getByHandle('first_name');
if ($key) {
$user_info->setAttribute($key, $first_name);
}
$key = \UserAttributeKey::getByHandle('last_name');
if ($key) {
$user_info->setAttribute($key, $last_name);
}
\User::loginByUserID($user_info->getUserID());
$this->bindUser($user = \User::getByUserID($user_info->getUserID()), $this->getUniqueId());
return $user;
}
示例3: t
foreach($aks as $uak) {
if ($uak->isAttributeKeyRequiredOnRegister()) {
$e1 = $uak->validateAttributeForm();
if ($e1 == false) {
$error[] = t('The field "%s" is required', $uak->getAttributeKeyName());
} else if ($e1 instanceof ValidationErrorHelper) {
$error[] = $e1->getList();
}
}
}
if (!$error) {
// do the registration
$data = array('uName' => $username, 'uPassword' => $password, 'uEmail' => $_POST['uEmail']);
$uo = UserInfo::add($data);
if (is_object($uo)) {
if (is_uploaded_file($_FILES['uAvatar']['tmp_name'])) {
$uHasAvatar = $av->updateUserAvatar($_FILES['uAvatar']['tmp_name'], $uo->getUserID());
}
foreach($aks as $uak) {
$uak->saveAttributeForm($uo);
}
$uo->updateGroups($_POST['gID']);
$uID = $uo->getUserID();
$this->controller->redirect('/dashboard/users/search?uID=' . $uID . '&user_created=1');
} else {
示例4: foreach
foreach ($e->getList() as $ei) {
print "ERROR: " . $ei . "\n";
}
exit(1);
} else {
$spl = StartingPointPackage::getClass($cliconfig['starting-point']);
require DIR_CONFIG_SITE . '/site_install.php';
require DIR_CONFIG_SITE . '/site_install_user.php';
$routines = $spl->getInstallRoutines();
try {
foreach ($routines as $r) {
print $r->getProgress() . '%: ' . $r->getText() . "\n";
call_user_func(array($spl, $r->getMethod()));
}
} catch (Exception $ex) {
print "ERROR: " . $ex->getMessage() . "\n";
$cnt->reset();
}
if ($cliconfig['default-locale']) {
\Config::save('concrete.locale', $cliconfig['default-locale']);
}
if ($cliconfig['demo-username']) {
print "Adding demo user\n";
UserInfo::add(array('uName' => $cliconfig['demo-username'], 'uEmail' => $cliconfig['demo-email'], 'uPassword' => $cliconfig['demo-password']))->getUserObject()->enterGroup(Group::getByID(ADMIN_GROUP_ID));
}
if (!isset($ex)) {
\Config::save('concrete.misc.seen_introduction', true);
print "Installation Complete!\n";
}
}
exit(0);
示例5: register
/**
* @param array $data
* @return UserInfo
*/
public function register($data) {
// slightly different than add. this is public facing
if (defined("USER_VALIDATE_EMAIL")) {
if (USER_VALIDATE_EMAIL > 0) {
$data['uIsValidated'] = 0;
}
}
$ui = UserInfo::add($data);
return $ui;
}
示例6: view
public function view()
{
$assignment = PermissionKey::getByHandle('edit_user_properties')->getMyAssignment();
$vals = Loader::helper('validation/strings');
$valt = Loader::helper('validation/token');
$valc = Loader::helper('concrete/validation');
if ($_POST['create']) {
$username = trim($_POST['uName']);
$username = preg_replace("/\\s+/", " ", $username);
$_POST['uName'] = $username;
$password = $_POST['uPassword'];
if (!$vals->email($_POST['uEmail'])) {
$this->error->add(t('Invalid email address provided.'));
} else {
if (!$valc->isUniqueEmail($_POST['uEmail'])) {
$this->error->add(t("The email address '%s' is already in use. Please choose another.", $_POST['uEmail']));
}
}
if (strlen($username) < USER_USERNAME_MINIMUM) {
$this->error->add(t('A username must be between at least %s characters long.', USER_USERNAME_MINIMUM));
}
if (strlen($username) > USER_USERNAME_MAXIMUM) {
$this->error->add(t('A username cannot be more than %s characters long.', USER_USERNAME_MAXIMUM));
}
if (strlen($username) >= USER_USERNAME_MINIMUM && !$valc->username($username)) {
if (USER_USERNAME_ALLOW_SPACES) {
$this->error->add(t('A username may only contain letters, numbers and spaces.'));
} else {
$this->error->add(t('A username may only contain letters or numbers.'));
}
}
if (!$valc->isUniqueUsername($username)) {
$this->error->add(t("The username '%s' already exists. Please choose another", $username));
}
if ($username == USER_SUPER) {
$this->error->add(t('Invalid Username'));
}
if (strlen($password) < USER_PASSWORD_MINIMUM || strlen($password) > USER_PASSWORD_MAXIMUM) {
$this->error->add(t('A password must be between %s and %s characters', USER_PASSWORD_MINIMUM, USER_PASSWORD_MAXIMUM));
}
if (strlen($password) >= USER_PASSWORD_MINIMUM && !$valc->password($password)) {
$this->error->add(t('A password may not contain ", \', >, <, or any spaces.'));
}
if (!$valt->validate('create_account')) {
$this->error->add($valt->getErrorMessage());
}
Loader::model("attribute/categories/user");
$aks = UserAttributeKey::getRegistrationList();
foreach ($aks as $uak) {
if ($uak->isAttributeKeyRequiredOnRegister()) {
$e1 = $uak->validateAttributeForm();
if ($e1 == false) {
$this->error->add(t('The field "%s" is required', $uak->getAttributeKeyName()));
} else {
if ($e1 instanceof ValidationErrorHelper) {
$this->error->add($e1->getList());
}
}
}
}
if (!$this->error->has()) {
// do the registration
$data = array('uName' => $username, 'uPassword' => $password, 'uEmail' => $_POST['uEmail'], 'uDefaultLanguage' => $_POST['uDefaultLanguage']);
$uo = UserInfo::add($data);
if (is_object($uo)) {
$av = Loader::helper('concrete/avatar');
if ($assignment->allowEditAvatar()) {
if (is_uploaded_file($_FILES['uAvatar']['tmp_name'])) {
$uHasAvatar = $av->updateUserAvatar($_FILES['uAvatar']['tmp_name'], $uo->getUserID());
}
}
foreach ($aks as $uak) {
if (in_array($uak->getAttributeKeyID(), $assignment->getAttributesAllowedArray())) {
$uak->saveAttributeForm($uo);
}
}
$gak = PermissionKey::getByHandle('assign_user_groups');
$gIDs = array();
if (is_array($_POST['gID'])) {
foreach ($_POST['gID'] as $gID) {
if ($gak->validate($gID)) {
$gIDs[] = $gID;
}
}
}
$uo->updateGroups($gIDs);
$uID = $uo->getUserID();
$this->redirect('/dashboard/users/search?uID=' . $uID . '&user_created=1');
} else {
$this->error->add(t('An error occurred while trying to create the account.'));
$this->set('error', $this->error);
}
} else {
$this->set('error', $this->error);
}
}
}
示例7: registerUser
public function registerUser($openID, $email)
{
$v = Loader::helper('validation/identifier');
$pass = $v->getString(10);
$data['uName'] = $this->createUserID($openID);
$data['uPassword'] = $pass;
$data['uEmail'] = $email;
$data['uIsValidated'] = 1;
$ui = UserInfo::add($data);
if (is_object($ui)) {
$this->linkUser($openID, $ui);
return $ui;
}
}
示例8: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$options = $input->getOptions();
if (isset($options['config'])) {
if (!is_file($options['config'])) {
throw new Exception('Unable to find the configuration file ' . $options['config']);
}
$configOptions = (include $options['config']);
if (!is_array($configOptions)) {
throw new Exception('The configuration file did not returned an array.');
}
foreach ($configOptions as $k => $v) {
if (!$input->hasParameterOption("--{$k}")) {
$options[$k] = $v;
}
}
}
if (file_exists(DIR_CONFIG_SITE . '/database.php')) {
throw new Exception('concrete5 is already installed.');
}
if (isset($options['default-locale'])) {
if ($options['default-locale'] === 'en_US') {
$options['default-locale'] = null;
} else {
$availableLocales = array_filter(scandir(DIR_BASE . '/application/languages'), function ($item) {
if (strpos($item, '.') === 0) {
return false;
}
$fullPath = DIR_BASE . '/application/languages/' . $item;
if (!is_dir($fullPath)) {
return false;
}
if (!is_file($fullPath . '/LC_MESSAGES/messages.mo')) {
return false;
}
return true;
});
if (!in_array($options['default-locale'], $availableLocales, true)) {
throw new Exception("'{$options['default-locale']}' is not a valid locale identifier.\nAvailable locales: " . ($availableLocales ? implode(', ', $availableLocales) : 'no locale found'));
}
}
}
Database::extend('install', function () use($options) {
return Database::getFactory()->createConnection(array('host' => $options['db-server'], 'user' => $options['db-username'], 'password' => $options['db-password'], 'database' => $options['db-database']));
});
Database::setDefaultConnection('install');
Config::set('database.connections.install', array());
$cnt = new \Concrete\Controller\Install();
$cnt->on_start();
$fileWriteErrors = clone $cnt->fileWriteErrors;
$e = Core::make('helper/validation/error');
/* @var $e \Concrete\Core\Error\Error */
if (!$cnt->get('imageTest')) {
$e->add('GD library must be enabled to install concrete5.');
}
if (!$cnt->get('mysqlTest')) {
$e->add($cnt->getDBErrorMsg());
}
if (!$cnt->get('xmlTest')) {
$e->add('SimpleXML and DOM must be enabled to install concrete5.');
}
if (!$cnt->get('phpVtest')) {
$e->add('concrete5 requires PHP ' . $cnt->getMinimumPhpVersion() . ' or greater.');
}
if (is_object($fileWriteErrors)) {
$e->add($fileWriteErrors);
}
if (!$e->has()) {
$_POST['DB_SERVER'] = $options['db-server'];
$_POST['DB_USERNAME'] = $options['db-username'];
$_POST['DB_PASSWORD'] = $options['db-password'];
$_POST['DB_DATABASE'] = $options['db-database'];
$_POST['SITE'] = $options['site'];
$_POST['SAMPLE_CONTENT'] = $options['starting-point'];
$_POST['uEmail'] = $options['admin-email'];
$_POST['uPasswordConfirm'] = $_POST['uPassword'] = $options['admin-password'];
$e = $cnt->configure();
}
if ($e->has()) {
throw new Exception(implode("\n", $e->getList()));
}
try {
$spl = StartingPointPackage::getClass($options['starting-point']);
require DIR_CONFIG_SITE . '/site_install.php';
require DIR_CONFIG_SITE . '/site_install_user.php';
$routines = $spl->getInstallRoutines();
foreach ($routines as $r) {
$output->writeln($r->getProgress() . '%: ' . $r->getText());
call_user_func(array($spl, $r->getMethod()));
}
} catch (Exception $ex) {
$cnt->reset();
throw $ex;
}
if (isset($options['default-locale'])) {
Config::save('concrete.locale', $options['default-locale']);
}
if (isset($options['demo-username']) && isset($options['demo-password']) && isset($options['demo-email']) && is_string($options['demo-username']) && is_string($options['demo-password']) && is_string($options['demo-email']) && $options['demo-username'] !== '' && $options['demo-password'] !== '' && $options['demo-email'] !== '') {
$output->write('Adding demo user... ');
\UserInfo::add(array('uName' => $options['demo-username'], 'uEmail' => $options['demo-email'], 'uPassword' => $options['demo-password']))->getUserObject()->enterGroup(\Group::getByID(ADMIN_GROUP_ID));
//.........这里部分代码省略.........
示例9: define
//causes dispatcher to skip the page rendering
define('C5_ENVIRONMENT_ONLY', true);
//prevents dispatcher from causing redirection to the base_url
define('REDIRECT_TO_BASE_URL', false);
//let's enable timezones
define('ENABLE_USER_TIMEZONES', true);
//since we can't define/redefine this for individual tests, we set to a value that's most likely to cause errors (vs '')
define('DIR_REL', '/blog');
// Force tests to start in en_US
define('SITE_LOCALE', 'en_US');
define('ACTIVE_LOCALE', 'en_US');
//this is where the magic happens
require DIR_BASE . '/concrete/dispatcher.php';
//add a user with Europe/Rome timezone
$uTest = UserInfo::getByUserName('testuser_it');
if (!is_object($uTest)) {
$uTest = UserInfo::add(array('uName' => 'testuser_it', 'uEmail' => 'testuser_it@concrete5.org', 'uPassword' => 'testpassword'));
}
$uTest->update(array('uTimezone' => 'Europe/Rome'));
define('TESTUSER_IT_ID', $uTest->getUserID());
$uTest = UserInfo::getByUserName('testuser_jp');
if (!is_object($uTest)) {
$uTest = UserInfo::add(array('uName' => 'testuser_jp', 'uEmail' => 'testuser_jp@concrete5.org', 'uPassword' => 'testpassword'));
}
$uTest->update(array('uTimezone' => 'Asia/Tokyo'));
define('TESTUSER_JP_ID', $uTest->getUserID());
// login the admin
User::getByUserID(USER_SUPER_ID, true);
Log::addEntry('bootsrapped', 'unit tests');
// include adodb-lib to avoid a PHPUnit problem with globals
include ADODB_DIR . '/adodb-lib.inc.php';
示例10: json_decode
<?php
$importArray = json_decode(file_get_contents(__DIR__ . '/walkexport.json'), true);
foreach ($importArray as $walk) {
$pl = new PageList();
$pl->filterByCollectionTypeHandle('country');
$pl->filterByName($walk['country']);
$country = $pl->get(1)[0];
if (!$country) {
$country = Page::getByID(1)->add(CollectionType::getByHandle('country'), ['cName' => $walk['country']]);
}
$pl = new PageList();
$pl->filterByCollectionTypeHandle('city');
$pl->filterByName($walk['city']);
$city = $pl->get(1)[0];
if (!$city) {
$city = $country->add(CollectionType::getByHandle('city'), ['cName' => $walk['city']]);
}
$ui = UserInfo::getByEmail($walk['owner']);
if (!$ui) {
$ui = UserInfo::add(['uName' => $walk['owner'], 'uEmail' => $walk['owner']]);
}
$walkPage = $city->add(CollectionType::getByHandle('walk'), ['cName' => $walk['title'], 'uID' => $ui->getUserID()]);
$walkController = Loader::controller($walkPage);
$walkController->setJson(json_encode($walk), true);
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$rc = 0;
try {
$app = Application::getFacadeApplication();
$options = $input->getOptions();
if (isset($options['config']) && $options['config'] && strtolower($options['config']) !== 'none') {
if (!is_file($options['config'])) {
throw new Exception('Unable to find the configuration file ' . $options['config']);
}
$configOptions = (include $options['config']);
if (!is_array($configOptions)) {
throw new Exception('The configuration file did not returned an array.');
}
foreach ($configOptions as $k => $v) {
if (!$input->hasParameterOption("--{$k}")) {
$options[$k] = $v;
}
}
}
if (file_exists(DIR_CONFIG_SITE . '/database.php')) {
throw new Exception('concrete5 is already installed.');
}
if (isset($options['site-locale'])) {
$locale = explode('_', $options['locale']);
$_POST['siteLocaleLanguage'] = $locale[0];
$_POST['siteLocaleCountry'] = $locale[1];
} else {
$_POST['siteLocaleLanguage'] = 'en';
$_POST['siteLocaleCountry'] = 'US';
}
if (isset($options['language'])) {
$_POST['locale'] = $options['language'];
}
Database::extend('install', function () use($options) {
return Database::getFactory()->createConnection(array('host' => $options['db-server'], 'user' => $options['db-username'], 'password' => $options['db-password'], 'database' => $options['db-database']));
});
Database::setDefaultConnection('install');
Config::set('database.connections.install', array());
$cnt = $app->make(\Concrete\Controller\Install::class);
$force_attach = $input->getOption('force-attach');
$auto_attach = $force_attach || $input->getOption('attach');
$cnt->setAutoAttach($auto_attach);
$cnt->on_start();
$fileWriteErrors = clone $cnt->fileWriteErrors;
$e = $app->make('helper/validation/error');
if (!$cnt->get('imageTest')) {
$e->add('GD library must be enabled to install concrete5.');
}
if (!$cnt->get('mysqlTest')) {
$e->add($cnt->getDBErrorMsg());
}
if (!$cnt->get('xmlTest')) {
$e->add('SimpleXML and DOM must be enabled to install concrete5.');
}
if (!$cnt->get('phpVtest')) {
$e->add('concrete5 requires PHP ' . $cnt->getMinimumPhpVersion() . ' or greater.');
}
if (is_object($fileWriteErrors)) {
$e->add($fileWriteErrors);
}
$spl = StartingPointPackage::getClass($options['starting-point']);
if ($spl === null) {
$e->add('Invalid starting-point: ' . $options['starting-point']);
}
if (!$e->has()) {
$_POST['DB_SERVER'] = $options['db-server'];
$_POST['DB_USERNAME'] = $options['db-username'];
$_POST['DB_PASSWORD'] = $options['db-password'];
$_POST['DB_DATABASE'] = $options['db-database'];
$_POST['SITE'] = $options['site'];
$_POST['SAMPLE_CONTENT'] = $options['starting-point'];
$_POST['uEmail'] = $options['admin-email'];
$_POST['uPasswordConfirm'] = $_POST['uPassword'] = $options['admin-password'];
if ($options['canonical-url']) {
$_POST['canonicalUrlChecked'] = '1';
$_POST['canonicalUrl'] = $options['canonical-url'];
}
if ($options['canonical-ssl-url']) {
$_POST['canonicalSSLUrlChecked'] = '1';
$_POST['canonicalSSLUrl'] = $options['canonical-ssl-url'];
}
$e = $cnt->configure();
}
if ($e->has()) {
throw new Exception(implode("\n", $e->getList()));
}
try {
$attach_mode = $force_attach;
if (!$force_attach && $cnt->isAutoAttachEnabled()) {
/** @var Connection $db */
$db = $app->make('database')->connection();
if ($db->query('show tables')->rowCount()) {
$attach_mode = true;
}
}
require DIR_CONFIG_SITE . '/site_install.php';
require DIR_CONFIG_SITE . '/site_install_user.php';
$routines = $spl->getInstallRoutines();
foreach ($routines as $r) {
//.........这里部分代码省略.........
示例12: createUser
protected function createUser($username, $email, $first_name = '', $last_name = '')
{
$data = array();
$data['uName'] = $username;
$data['uPassword'] = \Illuminate\Support\Str::random(256);
$data['uEmail'] = $email;
$data['uIsValidated'] = 1;
$user_info = \UserInfo::add($data);
if (!$user_info) {
throw new Exception('Unable to create new account.');
}
if ($group_id = intval($this->registrationGroupID(), 10)) {
$group = \Group::getByID($group_id);
if ($group && is_object($group) && !$group->isError()) {
$user = \User::getByUserID($user_info->getUserID());
$user->enterGroup($group);
}
}
$key = \UserAttributeKey::getByHandle('first_name');
if ($key) {
$user_info->setAttribute($key, $first_name);
}
$key = \UserAttributeKey::getByHandle('last_name');
if ($key) {
$user_info->setAttribute($key, $last_name);
}
$user = \User::loginByUserID($user_info->getUserID());
$this->mapUserByLdapUser($username, $user_info->getUserID());
return $user;
}