本文整理汇总了PHP中UrlManager::add_user_to_url方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlManager::add_user_to_url方法的具体用法?PHP UrlManager::add_user_to_url怎么用?PHP UrlManager::add_user_to_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlManager
的用法示例。
在下文中一共展示了UrlManager::add_user_to_url方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_user
//.........这里部分代码省略.........
if (!empty($currentUserId)) {
$creator_id = $currentUserId;
} else {
$creator_id = '';
}
// First check wether the login already exists
if (!self::is_username_available($loginName)) {
return api_set_failure('login-pass already taken');
}
$currentDate = api_get_utc_datetime();
$now = new DateTime($currentDate);
if (empty($expirationDate)) {
// Default expiration date
// if there is a default duration of a valid account then
// we have to change the expiration_date accordingly
if (api_get_setting('account_valid_duration') != '') {
$expirationDate = new DateTime($currentDate);
$days = intval(api_get_setting('account_valid_duration'));
$expirationDate->modify('+' . $days . ' day');
}
} else {
$expirationDate = api_get_utc_datetime($expirationDate);
$expirationDate = new \DateTime($expirationDate, new DateTimeZone('UTC'));
}
$userManager = self::getManager();
/** @var User $user */
$user = $userManager->createUser();
$user->setLastname($lastName)->setFirstname($firstName)->setUsername($loginName)->setStatus($status)->setPlainPassword($password)->setEmail($email)->setOfficialCode($official_code)->setPictureUri($picture_uri)->setCreatorId($creator_id)->setAuthSource($auth_source)->setPhone($phone)->setLanguage($language)->setRegistrationDate($now)->setHrDeptId($hr_dept_id)->setActive($active);
if (!empty($expirationDate)) {
$user->setExpirationDate($expirationDate);
}
$userManager->updateUser($user, true);
$userId = $user->getId();
if (!empty($userId)) {
$return = $userId;
$sql = "UPDATE {$table_user} SET user_id = {$return} WHERE id = {$return}";
Database::query($sql);
if ($isAdmin) {
UserManager::add_user_as_admin($userId);
}
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($return, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($return, 1);
}
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstName, $lastName, null, PERSON_NAME_EMAIL_ADDRESS);
$tplSubject = new Template(null, false, false, false, false, false);
$layoutSubject = $tplSubject->get_template('mail/subject_registration_platform.tpl');
$emailSubject = $tplSubject->fetch($layoutSubject);
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
}
} else {
$url = $_configuration['root_web'];
}
$tplContent = new Template(null, false, false, false, false, false);
// variables for the default template
$tplContent->assign('complete_name', stripslashes(api_get_person_name($firstName, $lastName)));
$tplContent->assign('login_name', $loginName);
$tplContent->assign('original_password', stripslashes($original_password));
$tplContent->assign('mailWebPath', $url);
$layoutContent = $tplContent->get_template('mail/content_registration_platform.tpl');
$emailBody = $tplContent->fetch($layoutContent);
/* MANAGE EVENT WITH MAIL */
if (EventsMail::check_if_using_class('user_registration')) {
$values["about_user"] = $return;
$values["password"] = $original_password;
$values["send_to"] = array($return);
$values["prior_lang"] = null;
EventsDispatcher::events('user_registration', $values);
} else {
$phoneNumber = isset($extra['mobile_phone_number']) ? $extra['mobile_phone_number'] : null;
$additionalParameters = array('smsType' => SmsPlugin::WELCOME_LOGIN_PASSWORD, 'userId' => $return, 'mobilePhoneNumber' => $phoneNumber, 'password' => $original_password);
api_mail_html($recipient_name, $email, $emailSubject, $emailBody, $sender_name, $email_admin, null, null, null, $additionalParameters);
}
/* ENDS MANAGE EVENT WITH MAIL */
}
Event::addEvent(LOG_USER_CREATE, LOG_USER_ID, $return);
} else {
return api_set_failure('error inserting in Database');
}
if (is_array($extra) && count($extra) > 0) {
$res = true;
foreach ($extra as $fname => $fvalue) {
$res = $res && self::update_extra_field_value($return, $fname, $fvalue);
}
}
self::update_extra_field_value($return, 'already_logged_in', 'false');
if (!empty($hook)) {
$hook->setEventData(array('return' => $return, 'originalPassword' => $original_password));
$hook->notifyCreateUser(HOOK_EVENT_TYPE_POST);
}
return $return;
}
示例2: WSCreateUserPasswordCrypted
//.........这里部分代码省略.........
$expiration_date = $params['expiration_date'];
}
// Check whether x_user_id exists into user_field_values table.
$user_id = UserManager::get_user_id_from_original_id($original_user_id_value, $original_user_id_name);
if ($debug) {
error_log('Ready to create user');
}
if ($user_id > 0) {
if ($debug) {
error_log('User found with id: ' . $user_id);
}
// Check whether user is not active
//@todo why this condition exists??
$sql = "SELECT user_id FROM {$table_user}\n WHERE user_id ='" . $user_id . "' AND active= '0' ";
$resu = Database::query($sql);
$r_check_user = Database::fetch_row($resu);
$count_check_user = Database::num_rows($resu);
if ($count_check_user > 0) {
if ($debug) {
error_log('User id: ' . $user_id . ' exists and is NOT active. Updating user and setting setting active = 1');
}
$sql = "UPDATE {$table_user} SET\n lastname='" . Database::escape_string($lastName) . "',\n firstname='" . Database::escape_string($firstName) . "',\n username='" . Database::escape_string($loginName) . "',";
if (!is_null($auth_source)) {
$sql .= " auth_source='" . Database::escape_string($auth_source) . "',";
}
$sql .= "\n password='" . Database::escape_string($password) . "',\n email='" . Database::escape_string($email) . "',\n status='" . Database::escape_string($status) . "',\n official_code='" . Database::escape_string($official_code) . "',\n phone='" . Database::escape_string($phone) . "',\n expiration_date='" . Database::escape_string($expiration_date) . "',\n active='1',\n hr_dept_id=" . intval($hr_dept_id);
$sql .= " WHERE user_id='" . $r_check_user[0] . "'";
if ($debug) {
error_log($sql);
}
Database::query($sql);
if (is_array($extra_list) && count($extra_list) > 0) {
foreach ($extra_list as $extra) {
$extra_field_name = $extra['field_name'];
$extra_field_value = $extra['field_value'];
// Save the external system's id into user_field_value table.
UserManager::update_extra_field_value($r_check_user[0], $extra_field_name, $extra_field_value);
}
}
return $r_check_user[0];
} else {
if ($debug) {
error_log('User exists but is active. Cant be updated');
}
return 0;
}
} else {
if ($debug) {
error_log("User not found with original_id = {$original_user_id_value} and original_name = {$original_user_id_name}");
}
}
// Default language.
if (empty($language)) {
$language = api_get_setting('platformLanguage');
}
if (!empty($_user['user_id'])) {
$creator_id = $_user['user_id'];
} else {
$creator_id = '';
}
// First check wether the login already exists
if (!UserManager::is_username_available($loginName)) {
if ($debug) {
error_log("Username {$loginName} is not available");
}
return 0;
}
$sql = "INSERT INTO {$table_user} SET\n lastname = '" . Database::escape_string(trim($lastName)) . "',\n firstname = '" . Database::escape_string(trim($firstName)) . "',\n username = '" . Database::escape_string(trim($loginName)) . "',\n status = '" . Database::escape_string($status) . "',\n password = '" . Database::escape_string($password) . "',\n email = '" . Database::escape_string($email) . "',\n official_code = '" . Database::escape_string($official_code) . "',\n picture_uri = '" . Database::escape_string($picture_uri) . "',\n creator_id = '" . Database::escape_string($creator_id) . "',\n auth_source = '" . Database::escape_string($auth_source) . "',\n phone = '" . Database::escape_string($phone) . "',\n language = '" . Database::escape_string($language) . "',\n registration_date = '" . api_get_utc_datetime() . "',\n expiration_date = '" . Database::escape_string($expiration_date) . "',\n hr_dept_id = '" . Database::escape_string($hr_dept_id) . "',\n active = '" . Database::escape_string($active) . "'";
if ($debug) {
error_log($sql);
}
$result = Database::query($sql);
if ($result) {
$return = Database::insert_id();
$sql = "UPDATE {$table_user} SET user_id = id WHERE id = {$return}";
Database::query($sql);
$url_id = api_get_current_access_url_id();
UrlManager::add_user_to_url($return, $url_id);
if ($debug) {
error_log("Adding user_id = {$return} to URL id {$url_id} ");
}
// Save new fieldlabel into user_field table.
$field_id = UserManager::create_extra_field($original_user_id_name, 1, $original_user_id_name, '');
// Save the remote system's id into user_field_value table.
UserManager::update_extra_field_value($return, $original_user_id_name, $original_user_id_value);
if (is_array($extra_list) && count($extra_list) > 0) {
foreach ($extra_list as $extra) {
$extra_field_name = $extra['field_name'];
$extra_field_value = $extra['field_value'];
// save new fieldlabel into user_field table
$field_id = UserManager::create_extra_field($extra_field_name, 1, $extra_field_name, '');
// save the external system's id into user_field_value table'
UserManager::update_extra_field_value($return, $extra_field_name, $extra_field_value);
}
}
} else {
return 0;
}
return $return;
}
示例3: api_protect_admin_script
// setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
$tool_name = get_lang('SessionOverview');
$interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration'), 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
// Database Table Definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$url_id = api_get_current_access_url_id();
$action = $_GET['action'];
switch ($action) {
case 'add_user_to_url':
$user_id = $_REQUEST['user_id'];
$result = UrlManager::add_user_to_url($user_id, $url_id);
$user_info = api_get_user_info($user_id);
if ($result) {
$message = Display::return_message(get_lang('UserAdded') . ' ' . api_get_person_name($user_info['firstname'], $user_info['lastname']), 'confirm');
}
break;
}
Display::display_header($tool_name);
if (!empty($message)) {
echo $message;
}
$multiple_url_is_on = api_get_multiple_access_url();
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
$session_list = SessionManager::get_sessions_list();
$html = '';
$show_users_with_problems = isset($_REQUEST['show_users_with_problems']) && $_REQUEST['show_users_with_problems'] == 1 ? true : false;
示例4: array
if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array("url" => 'user_list.php', "name" => get_lang('UserList'));
$tool_name = get_lang('SearchUsers');
} else {
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$tool_name = get_lang('UserList');
}
$message = '';
if (!empty($action)) {
$check = Security::check_token('get');
if ($check) {
switch ($action) {
case 'add_user_to_my_url':
$user_id = $_REQUEST["user_id"];
$result = UrlManager::add_user_to_url($user_id, $current_access_url_id);
if ($result) {
$user_info = api_get_user_info($user_id);
$message = get_lang('UserAdded') . ' ' . $user_info['firstname'] . ' ' . $user_info['lastname'] . ' (' . $user_info['username'] . ')';
$message = Display::return_message($message, 'confirmation');
}
break;
case 'show_message':
if (!empty($_GET['warn'])) {
// to prevent too long messages
if ($_GET['warn'] == 'session_message') {
$_GET['warn'] = $_SESSION['session_message_import_users'];
}
if (isset($_GET['warn']) && !empty($_GET['warn'])) {
$message .= Display::return_message(Security::remove_XSS($_GET['warn']), 'warning', false);
}
示例5: WSAddUserToPortal
function WSAddUserToPortal($params)
{
if (!WSHelperVerifyKey($params['secret_key'])) {
return return_error(WS_ERROR_SECRET_KEY);
}
$userId = $params['user_id'];
$portalId = $params['portal_id'];
UrlManager::add_user_to_url($userId, $portalId);
$result = UrlManager::relation_url_user_exist($userId, $portalId);
if (!empty($result)) {
return 1;
}
return 0;
}
示例6: foreach
case 'lock':
UrlManager::set_url_status('lock', $url_id);
Display::display_normal_message(get_lang('URLInactive'));
break;
case 'unlock':
UrlManager::set_url_status('unlock', $url_id);
Display::display_normal_message(get_lang('URLActive'));
break;
case 'register':
// we are going to register the admin
if (api_is_platform_admin()) {
if ($current_access_url_id != -1) {
$url_str = '';
foreach ($url_list as $my_url) {
if (!in_array($my_url['id'], $my_user_url_list)) {
UrlManager::add_user_to_url(api_get_user_id(), $my_url['id']);
$url_str .= $my_url['url'] . ' <br />';
}
}
Display::display_normal_message(get_lang('AdminUserRegisteredToThisURL') . ': ' . $url_str . '<br />', false);
}
}
break;
}
}
Security::clear_token();
}
$parameters['sec_token'] = Security::get_token();
// checking if the admin is registered in all sites
$url_string = '';
$my_user_url_list = api_get_access_url_from_user(api_get_user_id());
示例7: update_urls_rel_user
/**
* Updates the access_url_rel_user table with a given user list
* @author Julio Montoya
* @param array user list
* @param int access_url_id
* */
public static function update_urls_rel_user($user_list, $access_url_id)
{
$table_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql = "SELECT user_id FROM {$table_url_rel_user} WHERE access_url_id = " . intval($access_url_id);
$result = Database::query($sql);
$existing_users = array();
//Getting all users
while ($row = Database::fetch_array($result)) {
$existing_users[] = $row['user_id'];
}
// Adding users
$users_added = array();
foreach ($user_list as $user_id_to_add) {
if (!in_array($user_id_to_add, $existing_users)) {
$result = UrlManager::add_user_to_url($user_id_to_add, $access_url_id);
if ($result) {
$users_added[] = $user_id_to_add;
}
}
}
$users_deleted = array();
// Deleting old users
foreach ($existing_users as $user_id_to_delete) {
if (!in_array($user_id_to_delete, $user_list)) {
$result = UrlManager::delete_url_rel_user($user_id_to_delete, $access_url_id);
if ($result) {
$users_deleted[] = $user_id_to_delete;
}
}
}
if (empty($users_added) && empty($users_deleted)) {
return false;
}
return array('users_added' => $users_added, 'users_deleted' => $users_deleted);
}
示例8: create_user
//.........这里部分代码省略.........
$user->setLastname($lastName)->setFirstname($firstName)->setUsername($loginName)->setStatus($status)->setPlainPassword($password)->setEmail($email)->setOfficialCode($official_code)->setPictureUri($picture_uri)->setCreatorId($creator_id)->setAuthSource($auth_source)->setPhone($phone)->setLanguage($language)->setRegistrationDate($now)->setHrDeptId($hr_dept_id)->setActive($active)->setEnabled($active);
$url = $em->getRepository('ChamiloCoreBundle:AccessUrl')->find(api_get_current_access_url_id());
$accessRelUser = new AccessUrlRelUser();
$accessRelUser->setUser($user);
$accessRelUser->setPortal($url);
$user->setPortal($accessRelUser);
if (!empty($expirationDate)) {
$user->setExpirationDate($expirationDate);
}
switch ($status) {
case STUDENT:
$group = 'student';
break;
case COURSEMANAGER:
$group = 'teacher';
break;
case DRH:
$group = 'drh';
break;
case SESSIONADMIN:
$group = 'session_manager';
break;
/*case QUESTION:
$group = 'question_manager';
break;*/
/*case QUESTION:
$group = 'question_manager';
break;*/
case STUDENT_BOSS:
$group = 'student_boss';
break;
case INVITEE:
$group = 'invitee';
break;
}
if ($isAdmin) {
$group = 'admin';
}
$criteria = ['code' => $group];
$group = $em->getRepository('ChamiloUserBundle:Group')->findOneBy($criteria);
$user->setGroups(array($group));
$userManager->updateUser($user, true);
$userId = $user->getId();
if (!empty($userId)) {
$return = $userId;
$sql = "UPDATE {$table_user} SET user_id = {$return} WHERE id = {$return}";
Database::query($sql);
if ($isAdmin) {
UserManager::add_user_as_admin($user);
}
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($return, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($return, 1);
}
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstName, $lastName, null, PERSON_NAME_EMAIL_ADDRESS);
$emailSubject = Container::getTemplating()->render('@template_style/mail/subject_registration_platform.html.twig');
$sender_name = api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('admin.administrator_email');
$url = api_get_path(WEB_PATH);
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
}
}
$emailBody = Container::getTemplating()->render('@template_style/mail/content_registration_platform.html.twig', ['complete_name' => stripslashes(api_get_person_name($firstName, $lastName)), 'login_name' => $loginName, 'original_password' => stripslashes($original_password), 'mail_web_path' => $url]);
/* MANAGE EVENT WITH MAIL */
if (EventsMail::check_if_using_class('user_registration')) {
$values["about_user"] = $return;
$values["password"] = $original_password;
$values["send_to"] = array($return);
$values["prior_lang"] = null;
EventsDispatcher::events('user_registration', $values);
} else {
$phoneNumber = isset($extra['mobile_phone_number']) ? $extra['mobile_phone_number'] : null;
$additionalParameters = array('smsType' => SmsPlugin::WELCOME_LOGIN_PASSWORD, 'userId' => $return, 'mobilePhoneNumber' => $phoneNumber, 'password' => $original_password);
api_mail_html($recipient_name, $email, $emailSubject, $emailBody, $sender_name, $email_admin, null, null, null, $additionalParameters);
}
/* ENDS MANAGE EVENT WITH MAIL */
}
Event::addEvent(LOG_USER_CREATE, LOG_USER_ID, $return);
} else {
throw new \Exception('error inserting in Database');
}
if (is_array($extra) && count($extra) > 0) {
$res = true;
foreach ($extra as $fname => $fvalue) {
$res = $res && self::update_extra_field_value($return, $fname, $fvalue);
}
}
self::update_extra_field_value($return, 'already_logged_in', 'false');
if (!empty($hook)) {
$hook->setEventData(array('return' => $return, 'originalPassword' => $original_password));
$hook->notifyCreateUser(HOOK_EVENT_TYPE_POST);
}
return $return;
}
示例9: create_user
/**
* Creates a new user for the platform
* @author Hugues Peeters <peeters@ipm.ucl.ac.be>,
* @author Roan Embrechts <roan_embrechts@yahoo.com>
* @param string Firstname
* @param string Lastname
* @param int Status (1 for course tutor, 5 for student, 6 for anonymous)
* @param string e-mail address
* @param string Login
* @param string Password
* @param string Any official code (optional)
* @param string User language (optional)
* @param string Phone number (optional)
* @param string Picture URI (optional)
* @param string Authentication source (optional, defaults to 'platform', dependind on constant)
* @param string Account expiration date (optional, defaults to '0000-00-00 00:00:00')
* @param int Whether the account is enabled or disabled by default
* @param int The department of HR in which the user is registered (optional, defaults to 0)
* @param array Extra fields
* @param string Encrypt method used if password is given encrypted. Set to an empty string by default
* @return mixed new user id - if the new user creation succeeds, false otherwise
* @desc The function tries to retrieve $_user['user_id'] from the global space. If it exists, $_user['user_id'] is the creator id. If a problem arises, it stores the error message in global $api_failureList
* @assert ('Sam','Gamegie',5,'sam@example.com','jo','jo') > 1
* @assert ('Pippin','Took',null,null,'jo','jo') === false
*/
public static function create_user($firstName, $lastName, $status, $email, $loginName, $password, $official_code = '', $language = '', $phone = '', $picture_uri = '', $auth_source = PLATFORM_AUTH_SOURCE, $expiration_date = '0000-00-00 00:00:00', $active = 1, $hr_dept_id = 0, $extra = null, $encrypt_method = '', $send_mail = false)
{
global $_configuration;
$original_password = $password;
$access_url_id = 1;
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
}
if (is_array($_configuration[$access_url_id]) && isset($_configuration[$access_url_id]['hosting_limit_users']) && $_configuration[$access_url_id]['hosting_limit_users'] > 0) {
$num = self::get_number_of_users();
if ($num >= $_configuration[$access_url_id]['hosting_limit_users']) {
return api_set_failure('portal users limit reached');
}
}
if ($status === 1 && is_array($_configuration[$access_url_id]) && isset($_configuration[$access_url_id]['hosting_limit_teachers']) && $_configuration[$access_url_id]['hosting_limit_teachers'] > 0) {
$num = self::get_number_of_users(1);
if ($num >= $_configuration[$access_url_id]['hosting_limit_teachers']) {
return api_set_failure('portal teachers limit reached');
}
}
$firstName = Security::remove_XSS($firstName);
$lastName = Security::remove_XSS($lastName);
$loginName = Security::remove_XSS($loginName);
$phone = Security::remove_XSS($phone);
// database table definition
$table_user = Database::get_main_table(TABLE_MAIN_USER);
//Checking the user language
$languages = api_get_languages();
if (!in_array($language, $languages['folder'])) {
$language = api_get_setting('platformLanguage');
}
$creator_id = api_get_user_id();
// First check wether the login already exists
if (!self::is_username_available($loginName)) {
return api_set_failure('login-pass already taken');
}
if (empty($encrypt_method)) {
$password = api_get_encrypted_password($password);
} else {
if ($_configuration['password_encryption'] === $encrypt_method) {
if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) {
return api_set_failure('encrypt_method invalid');
} else {
if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
return api_set_failure('encrypt_method invalid');
}
}
} else {
return api_set_failure('encrypt_method invalid');
}
}
//@todo replace this date with the api_get_utc_date function big problem with users that are already registered
$current_date = api_get_utc_datetime();
$sql = "INSERT INTO {$table_user} " . "SET lastname = '" . Database::escape_string(trim($lastName)) . "'," . "firstname = '" . Database::escape_string(trim($firstName)) . "'," . "username = '" . Database::escape_string(trim($loginName)) . "'," . "status = '" . Database::escape_string($status) . "'," . "password = '" . Database::escape_string($password) . "'," . "email = '" . Database::escape_string($email) . "'," . "official_code = '" . Database::escape_string($official_code) . "'," . "picture_uri = '" . Database::escape_string($picture_uri) . "'," . "creator_id = '" . Database::escape_string($creator_id) . "'," . "auth_source = '" . Database::escape_string($auth_source) . "'," . "phone = '" . Database::escape_string($phone) . "'," . "language = '" . Database::escape_string($language) . "'," . "registration_date = '" . $current_date . "'," . "expiration_date = '" . Database::escape_string($expiration_date) . "'," . "hr_dept_id = '" . Database::escape_string($hr_dept_id) . "'," . "active = '" . Database::escape_string($active) . "'";
$result = Database::query($sql);
if ($result) {
//echo "id returned";
$return = Database::insert_id();
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($return, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($return, 1);
}
// Adding user
/** @var Entity\User $user */
$em = self::$em;
$user = $em->getRepository('Entity\\User')->find($return);
$role = $em->getRepository('Entity\\Role')->find($status);
$user->getRolesObj()->add($role);
$em->persist($user);
$em->flush();
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstName, $lastName, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '[' . api_get_setting('siteName') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('siteName');
//.........这里部分代码省略.........
示例10: create_user
//.........这里部分代码省略.........
}
$creator_id = api_get_user_id();
// First check wether the login already exists
if (!self::is_username_available($loginName)) {
return api_set_failure('login-pass already taken');
}
if (empty($encrypt_method)) {
$password = api_get_encrypted_password($password);
} else {
if ($_configuration['password_encryption'] === $encrypt_method) {
if ($encrypt_method == 'md5' && !preg_match('/^[A-Fa-f0-9]{32}$/', $password)) {
return api_set_failure('encrypt_method invalid');
} else {
if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
return api_set_failure('encrypt_method invalid');
}
}
} else {
return api_set_failure('encrypt_method invalid');
}
}
//@todo replace this date with the api_get_utc_date function big problem with users that are already registered
$current_date = api_get_utc_datetime();
$em = Database::getManager();
$expirationDate = new \DateTime($expiration_date);
$user = new \Chamilo\UserBundle\Entity\User();
$user->setLastname($lastName)->setFirstname($firstName)->setUsername($loginName)->setPassword($password)->setEmail($email)->setOfficialCode($official_code)->setPictureUri($picture_uri)->setCreatorId($creator_id)->setAuthSource($auth_source)->setPhone($phone)->setLanguage($language)->setExpirationDate($expirationDate)->setHrDeptId($hr_dept_id)->setActive($active);
/*$sql = "INSERT INTO $table_user ".
"SET lastname = '".Database::escape_string(trim($lastName))."',".
"firstname = '".Database::escape_string(trim($firstName))."',".
"username = '".Database::escape_string(trim($loginName))."',".
"status = '".Database::escape_string($status)."',".
"password = '".Database::escape_string($password)."',".
"email = '".Database::escape_string($email)."',".
"official_code = '".Database::escape_string($official_code)."',".
"picture_uri = '".Database::escape_string($picture_uri)."',".
"creator_id = '".Database::escape_string($creator_id)."',".
"auth_source = '".Database::escape_string($auth_source)."',".
"phone = '".Database::escape_string($phone)."',".
"language = '".Database::escape_string($language)."',".
"registration_date = '".$current_date."',".
"expiration_date = '".Database::escape_string($expiration_date)."',".
"hr_dept_id = '".Database::escape_string($hr_dept_id)."',".
"active = '".Database::escape_string($active)."'";
$result = Database::query($sql);*/
$em->persist($user);
$em->flush();
if ($user) {
$userId = $user->getId();
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($userId, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($userId, 1);
}
$group = $em->getRepository('ChamiloUserBundle:Group')->find($status);
$user->addGroup($group);
//$user->addRole($roleName);
$em->persist($user);
$em->flush();
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstName, $lastName, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '[' . api_get_setting('platform.site_name') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('platform.site_name');
$sender_name = api_get_person_name(api_get_setting('platform.administrator_name'), api_get_setting('platform.administrator_surname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('platform.administrator_email');
$params = array('complete_user_name' => api_get_person_name($firstName, $lastName), 'login_name' => $loginName, 'password' => stripslashes($original_password));
$message = \Swift_Message::newInstance()->setSubject($emailsubject)->setFrom(array($email_admin => $sender_name))->setTo(array($email => $recipient_name))->setBody(Container::getTemplate()->render('ChamiloCoreBundle:Mailer:User/new_user.html.twig', $params), 'text/html')->addPart(Container::getTemplate()->render('ChamiloCoreBundle:Mailer:User/new_user.text.twig', $params), 'text/plain')->setEncoder(Swift_Encoding::get8BitEncoding());
$type = $message->getHeaders()->get('Content-Type');
$type->setValue('text/html');
$type->setParameter('charset', 'utf-8');
Container::getMailer()->send($message);
/* MANAGE EVENT WITH MAIL */
/*if (EventsMail::check_if_using_class('user_registration')) {
$values["about_user"] = $return;
$values["password"] = $original_password;
$values["send_to"] = array($return);
$values["prior_lang"] = null;
EventsDispatcher::events('user_registration', $values);
} else {
@api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}*/
/* ENDS MANAGE EVENT WITH MAIL */
}
// Add event to system log
$user_id_manager = api_get_user_id();
$user_info = api_get_user_info($userId);
Event::addEvent(LOG_USER_CREATE, LOG_USER_ID, $userId, api_get_utc_datetime(), $user_id_manager);
Event::addEvent(LOG_USER_CREATE, LOG_USER_OBJECT, $user_info, api_get_utc_datetime(), $user_id_manager);
} else {
return api_set_failure('error inserting in Database');
}
if (is_array($extra) && count($extra) > 0) {
$res = true;
foreach ($extra as $fname => $fvalue) {
$res = $res && self::update_extra_field_value($userId, $fname, $fvalue);
}
}
self::update_extra_field_value($userId, 'already_logged_in', 'false');
return $userId;
}
示例11: create_user
//.........这里部分代码省略.........
} else if ($encrypt_method == 'sha1' && !preg_match('/^[A-Fa-f0-9]{40}$/', $password)) {
return api_set_failure('encrypt_method invalid');
}
} else {
return api_set_failure('encrypt_method invalid');
}
}
$current_date = api_get_utc_datetime();
$sql = "INSERT INTO $table_user
SET lastname = '".Database::escape_string(trim($lastName))."',
firstname = '".Database::escape_string(trim($firstName))."',
username = '".Database::escape_string(trim($loginName))."',
status = '".Database::escape_string($status)."',
password = '".Database::escape_string($password)."',
email = '".Database::escape_string($email)."',
official_code = '".Database::escape_string($official_code)."',
picture_uri = '".Database::escape_string($picture_uri)."',
creator_id = '".Database::escape_string($creator_id)."',
auth_source = '".Database::escape_string($auth_source)."',
phone = '".Database::escape_string($phone)."',
language = '".Database::escape_string($language)."',
registration_date = '".$current_date."',
expiration_date = '".Database::escape_string($expiration_date)."',
hr_dept_id = '".Database::escape_string($hr_dept_id)."',
active = '".Database::escape_string($active)."'";
$result = Database::query($sql);
if ($result) {
//echo "id returned";
$return = Database::insert_id();
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($return, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($return, 1);
}
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstName, $lastName, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstName, $lastName)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ".$loginName."\n".get_lang('Pass')." : ".stripslashes($original_password)."\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".$url['url']."\n\n".get_lang('Problem')."\n\n".get_lang('SignatureFormula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator');
}
} else {
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstName, $lastName)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ".$loginName."\n".get_lang('Pass')." : ".stripslashes($original_password)."\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".$_configuration['root_web']."\n\n".get_lang('Problem')."\n\n".get_lang('SignatureFormula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator');
}
/* MANAGE EVENT WITH MAIL */
if (EventsMail::check_if_using_class('user_registration')) {
$values["about_user"] = $return;
$values["password"] = $original_password;
$values["send_to"] = array($return);
$values["prior_lang"] = null;
EventsDispatcher::events('user_registration', $values);
} else {
$phoneNumber = isset($extra['mobile_phone_number']) ? $extra['mobile_phone_number'] : null;
$additionalParameters = array(
'smsType' => ClockworksmsPlugin::WELCOME_LOGIN_PASSWORD,