当前位置: 首页>>代码示例>>PHP>>正文


PHP UserManager::create_user方法代码示例

本文整理汇总了PHP中UserManager::create_user方法的典型用法代码示例。如果您正苦于以下问题:PHP UserManager::create_user方法的具体用法?PHP UserManager::create_user怎么用?PHP UserManager::create_user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserManager的用法示例。


在下文中一共展示了UserManager::create_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fill_users

/**
 * Loads the data and injects it into the Chamilo database, using the Chamilo
 * internal functions.
 * @return  array  List of user IDs for the users that have just been inserted
 */
function fill_users()
{
    $eol = PHP_EOL;
    $users = array();
    //declare only to avoid parsing notice
    require_once 'data_users.php';
    //fill the $users array
    $output = array();
    $output[] = array('title' => 'Users Filling Report:');
    $i = 1;
    foreach ($users as $i => $user) {
        //first check that the first item doesn't exist already
        $output[$i]['line-init'] = $user['firstname'];
        $res = UserManager::create_user($user['firstname'], $user['lastname'], $user['status'], $user['email'], $user['username'], $user['pass'], null, null, null, null, $user['auth_source'], null, $user['active']);
        $output[$i]['line-info'] = $res ? get_lang('Inserted') : get_lang('NotInserted');
        $i++;
    }
    return $output;
}
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:24,代码来源:fill_users.php

示例2: finishInstallation

/**
 *
 * After the schema was created (table creation), the function adds
 * admin/platform information.
 *
 * @param EntityManager $manager
 * @param string $sysPath
 * @param string $encryptPassForm
 * @param string $passForm
 * @param string $adminLastName
 * @param string $adminFirstName
 * @param string $loginForm
 * @param string $emailForm
 * @param string $adminPhoneForm
 * @param string $languageForm
 * @param string $institutionForm
 * @param string $institutionUrlForm
 * @param string $siteName
 * @param string $allowSelfReg
 * @param string $allowSelfRegProf
 * @param string $installationProfile Installation profile, if any was provided
 */
function finishInstallation($manager, $sysPath, $encryptPassForm, $passForm, $adminLastName, $adminFirstName, $loginForm, $emailForm, $adminPhoneForm, $languageForm, $institutionForm, $institutionUrlForm, $siteName, $allowSelfReg, $allowSelfRegProf, $installationProfile = '')
{
    $sysPath = !empty($sysPath) ? $sysPath : api_get_path(SYS_PATH);
    // Inserting data
    $data = file_get_contents($sysPath . 'main/install/data.sql');
    $result = $manager->getConnection()->prepare($data);
    $result->execute();
    $result->closeCursor();
    UserManager::setPasswordEncryption($encryptPassForm);
    UserManager::create_user($adminFirstName, $adminLastName, 1, $emailForm, $loginForm, $passForm, 'ADMIN', $languageForm, $adminPhoneForm, '', PLATFORM_AUTH_SOURCE, '', 1, 0, null, '', false, true);
    UserManager::create_user('Joe', 'Anonymous', 6, 'anonymous@localhost', 'anon', 'anon', 'anonymous', $languageForm, '', '', PLATFORM_AUTH_SOURCE, '', 1, 0, null, '', false, false);
    // Set default language
    $sql = "UPDATE language SET available=1 WHERE dokeos_folder = '{$languageForm}'";
    Database::query($sql);
    // Install settings
    installSettings($institutionForm, $institutionUrlForm, $siteName, $emailForm, $adminLastName, $adminFirstName, $languageForm, $allowSelfReg, $allowSelfRegProf, $installationProfile);
    lockSettings();
    updateDirAndFilesPermissions();
}
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:41,代码来源:install.lib.php

示例3: save_data

/**
 * Save the imported data
 * @param   array   $users List of users
 * @return  void
 * @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in
 */
function save_data($users)
{
    global $inserted_in_course;
    // Not all scripts declare the $inserted_in_course array (although they should).
    if (!isset($inserted_in_course)) {
        $inserted_in_course = array();
    }
    $usergroup = new UserGroup();
    $send_mail = $_POST['sendMail'] ? true : false;
    if (is_array($users)) {
        foreach ($users as $user) {
            $user = complete_missing_data($user);
            $user['Status'] = api_status_key($user['Status']);
            $user_id = UserManager::create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], $user['language'], $user['PhoneNumber'], '', $user['AuthSource'], $user['ExpiryDate'], 1, 0, null, null, $send_mail);
            if (!is_array($user['Courses']) && !empty($user['Courses'])) {
                $user['Courses'] = array($user['Courses']);
            }
            if (is_array($user['Courses'])) {
                foreach ($user['Courses'] as $course) {
                    if (CourseManager::course_exists($course)) {
                        CourseManager::subscribe_user($user_id, $course, $user['Status']);
                        $course_info = CourseManager::get_course_information($course);
                        $inserted_in_course[$course] = $course_info['title'];
                    }
                }
            }
            if (!empty($user['ClassId'])) {
                $classId = explode('|', trim($user['ClassId']));
                foreach ($classId as $id) {
                    $usergroup->subscribe_users_to_usergroup($id, array($user_id), false);
                }
            }
            // Saving extra fields.
            global $extra_fields;
            // We are sure that the extra field exists.
            foreach ($extra_fields as $extras) {
                if (isset($user[$extras[1]])) {
                    $key = $extras[1];
                    $value = $user[$extras[1]];
                    UserManager::update_extra_field_value($user_id, $key, $value);
                }
            }
        }
    }
}
开发者ID:secuencia24,项目名称:chamilo-lms,代码行数:51,代码来源:user_import.php

示例4: ldap_add_user_by_array

function ldap_add_user_by_array($data, $update_if_exists = true)
{
    $lastname = api_convert_encoding($data['sn'][0], api_get_system_encoding(), 'UTF-8');
    $firstname = api_convert_encoding($data['cn'][0], api_get_system_encoding(), 'UTF-8');
    $email = $data['mail'][0];
    // Get uid from dn
    $dn_array = ldap_explode_dn($data['dn'], 1);
    $username = $dn_array[0];
    // uid is first key
    $outab[] = $data['edupersonprimaryaffiliation'][0];
    // Here, "student"
    //$val = ldap_get_values_len($ds, $entry, "userPassword");
    //$val = ldap_get_values_len($ds, $data, "userPassword");
    //$password = $val[0];
    // TODO the password, if encrypted at the source, will be encrypted twice, which makes it useless. Try to fix that.
    $password = $data['userPassword'][0];
    $structure = $data['edupersonprimaryorgunitdn'][0];
    $array_structure = explode(",", $structure);
    $array_val = explode("=", $array_structure[0]);
    $etape = $array_val[1];
    $array_val = explode("=", $array_structure[1]);
    $annee = $array_val[1];
    // To ease management, we add the step-year (etape-annee) code
    $official_code = $etape . "-" . $annee;
    $auth_source = 'ldap';
    // No expiration date for students (recover from LDAP's shadow expiry)
    $expiration_date = '0000-00-00 00:00:00';
    $active = 1;
    if (empty($status)) {
        $status = 5;
    }
    if (empty($phone)) {
        $phone = '';
    }
    if (empty($picture_uri)) {
        $picture_uri = '';
    }
    // Adding user
    $user_id = 0;
    if (UserManager::is_username_available($username)) {
        $user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, api_get_setting('platformLanguage'), $phone, $picture_uri, $auth_source, $expiration_date, $active);
    } else {
        if ($update_if_exists) {
            $user = UserManager::get_user_info($username);
            $user_id = $user['user_id'];
            UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active);
        }
    }
    return $user_id;
}
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:50,代码来源:authldap.php

示例5: save_data

 /**
  * Saves imported data.
  */
 public function save_data($users, $course_list, $id_session)
 {
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
     $id_session = intval($id_session);
     $sendMail = $_POST['sendMail'] ? 1 : 0;
     // Adding users to the platform.
     $new_users = array();
     foreach ($users as $index => $user) {
         $user = MySpace::complete_missing_data($user);
         // coach only will registered users
         $default_status = STUDENT;
         if ($user['create'] == COURSEMANAGER) {
             $user['id'] = UserManager::create_user($user['FirstName'], $user['LastName'], $default_status, $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('language.platform_language'), $user['PhoneNumber'], '');
             $user['added_at_platform'] = 1;
         } else {
             $user['id'] = $user['create'];
             $user['added_at_platform'] = 0;
         }
         $new_users[] = $user;
     }
     // Update user list.
     $users = $new_users;
     // Inserting users.
     $super_list = array();
     foreach ($course_list as $enreg_course) {
         $nbr_users = 0;
         $new_users = array();
         $enreg_course = Database::escape_string($enreg_course);
         foreach ($users as $index => $user) {
             $userid = intval($user['id']);
             $sql = "INSERT IGNORE INTO {$tbl_session_rel_course_rel_user}(session_id, c_id, user_id)\n                        VALUES('{$id_session}','{$enreg_course}','{$userid}')";
             $course_session = array('course' => $enreg_course, 'added' => 1);
             $result = Database::query($sql);
             if (Database::affected_rows($result)) {
                 $nbr_users++;
             }
             $new_users[] = $user;
         }
         $super_list[] = $new_users;
         //update the nbr_users field
         $sql_select = "SELECT COUNT(user_id) as nbUsers FROM {$tbl_session_rel_course_rel_user}\n                           WHERE session_id='{$id_session}' AND c_id='{$enreg_course}'";
         $rs = Database::query($sql_select);
         list($nbr_users) = Database::fetch_array($rs);
         $sql_update = "UPDATE {$tbl_session_rel_course} SET nbr_users={$nbr_users}\n                           WHERE session_id='{$id_session}' AND c_id='{$enreg_course}'";
         Database::query($sql_update);
         $sql_update = "UPDATE {$tbl_session} SET nbr_users= '{$nbr_users}' WHERE id='{$id_session}'";
         Database::query($sql_update);
     }
     $new_users = array();
     foreach ($users as $index => $user) {
         $userid = $user['id'];
         $sql_insert = "INSERT IGNORE INTO {$tbl_session_rel_user}(session_id, user_id, registered_at)\n                           VALUES ('{$id_session}','{$userid}', '" . api_get_utc_datetime() . "')";
         Database::query($sql_insert);
         $user['added_at_session'] = 1;
         $new_users[] = $user;
     }
     $users = $new_users;
     $registered_users = get_lang('FileImported') . '<br /> Import file results : <br />';
     // Sending emails.
     $addedto = '';
     if ($sendMail) {
         $i = 0;
         foreach ($users as $index => $user) {
             $emailsubject = '[' . api_get_setting('platform.site_name') . '] ' . get_lang('YourReg') . ' ' . api_get_setting('platform.site_name');
             $emailbody = get_lang('Dear') . ' ' . api_get_person_name($user['FirstName'], $user['LastName']) . ",\n\n" . get_lang('YouAreReg') . " " . api_get_setting('platform.site_name') . " " . get_lang('WithTheFollowingSettings') . "\n\n" . get_lang('Username') . " : {$user['UserName']}\n" . get_lang('Pass') . " : {$user['Password']}\n\n" . get_lang('Address') . " " . api_get_setting('platform.site_name') . " " . get_lang('Is') . " : " . api_get_path(WEB_PATH) . " \n\n" . get_lang('Problem') . "\n\n" . get_lang('SignatureFormula') . ",\n\n" . api_get_person_name(api_get_setting('admin.administrator_name'), api_get_setting('admin.administrator_surname')) . "\n" . get_lang('Manager') . " " . api_get_setting('platform.site_name') . "\nT. " . api_get_setting('admin.administrator_phone') . "\n" . get_lang('Email') . " : " . api_get_setting('admin.administrator_email');
             api_mail_html(api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS), $user['Email'], $emailsubject, $emailbody);
             $userInfo = api_get_user_info($user['id']);
             if ($user['added_at_platform'] == 1 && $user['added_at_session'] == 1 || $user['added_at_session'] == 1) {
                 if ($user['added_at_platform'] == 1) {
                     $addedto = get_lang('UserCreatedPlatform');
                 } else {
                     $addedto = '          ';
                 }
                 if ($user['added_at_session'] == 1) {
                     $addedto .= get_lang('UserInSession');
                 }
             } else {
                 $addedto = get_lang('UserNotAdded');
             }
             $registered_users .= UserManager::getUserProfileLink($userInfo) . " - " . $addedto . '<br />';
         }
     } else {
         $i = 0;
         foreach ($users as $index => $user) {
             $userInfo = api_get_user_info($user['id']);
             if ($user['added_at_platform'] == 1 && $user['added_at_session'] == 1 || $user['added_at_session'] == 1) {
                 if ($user['added_at_platform'] == 1) {
                     $addedto = get_lang('UserCreatedPlatform');
                 } else {
                     $addedto = '          ';
                 }
                 if ($user['added_at_session'] == 1) {
                     $addedto .= ' ' . get_lang('UserInSession');
                 }
//.........这里部分代码省略.........
开发者ID:feroli1000,项目名称:chamilo-lms,代码行数:101,代码来源:myspace.lib.php

示例6: testCreateUser5

 /**
  * Test language non-existence
  */
 public function testCreateUser5()
 {
     $this->assertSame(false, UserManager::create_user('Pippin', 'Tooky', null, null, 'jo', 'jo', null, 'spaniard'));
 }
开发者ID:ilosada,项目名称:chamilo-lms-icpna,代码行数:7,代码来源:UserManagerTest.lib.php

示例7: cas_is_authenticated

/**
* checks if the user already get a session
* @return the user login if the user already has a session ,false otherwise
**/
function cas_is_authenticated()
{
    global $cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri;
    global $PHPCAS_CLIENT;
    global $logout;
    if (!cas_configured()) {
        return;
    }
    if (!is_object($PHPCAS_CLIENT)) {
        phpCAS::client($cas_auth_ver, $cas_auth_server, $cas_auth_port, $cas_auth_uri);
        phpCAS::setNoCasServerValidation();
    }
    $auth = phpCAS::checkAuthentication();
    if ($auth) {
        $login = trim(phpCAS::getUser());
        /*
          Get user  attributes. Here are the attributes for crdp platform
          sn => name
          ENTPersonMailInterne => mail
          ENTPersonAlias => login
          ENTPersonProfils => profil
          givenName => first name
        */
        /*$user=phpCAS::getAttributes();
        		$firstName = trim($user['givenName']);
        		$lastName = trim($user['sn']);
        		$login = trim($user['ENTPersonAlias']);
        		$profil = trim($user['ENTPersonProfils']);
        		$email = trim($user['ENTPersonMailInterne']);
        		$satus=5;
        		switch ($profil){
        			case 'admin_etab':
        				$status=3; //Session admin
        				break;
        			case 'admin_sie':
        				$status=3; //Session admin
        				break;
        			case 'National_3':
        				$status=1; // Teacher
        				break;
        			case 'National_1':
        				$status=5; // Student
        				break;
        			default:
        				$status=5; // Student
        		}*/
        if (!$logout) {
            // get user info from username
            $tab_user_info = UserManager::get_user_info($login);
            // user found in the chamilo database
            if (is_array($tab_user_info)) {
                // if option is on we update user automatically from ldap server
                if (api_get_setting("update_user_info_cas_with_ldap") == "true") {
                    $ldapuser = extldap_authenticate($login, 'nopass', true);
                    if ($ldap_user !== false) {
                        $chamilo_user = extldap_get_chamilo_user($ldapuser);
                        $chamilo_user['user_id'] = $tab_user_info['user_id'];
                        $chamilo_user['status'] = $tab_user_info['status'];
                        UserManager::update_user($chamilo_user["user_id"], $chamilo_user["firstname"], $chamilo_user["lastname"], $login, null, null, $chamilo_user["email"], $chamilo_user["status"], '', '', '', '', 1, null, 0, null, '');
                    }
                }
                return $login;
            } else {
                // if option is on we can ADD user automatically from ldap server or by modify own profil
                $user_added = false;
                switch (api_get_setting("cas_add_user_activate")) {
                    case PLATFORM_AUTH_SOURCE:
                        // user will have to modify firstname, lastname, email in chamilo profil edit
                        $userdata = get_lang("EditInProfil");
                        UserManager::create_user($userdata, $userdata, '5', $userdata, $login, 'casplaceholder', '', '', '', '', CAS_AUTH_SOURCE);
                        $user_added = $login;
                        break;
                    case LDAP_AUTH_SOURCE:
                        // user info are read from ldap connexion
                        // get user info from ldap server
                        // user has already been authenticated by CAS
                        // If user not found in LDAP, user not created
                        $ldapuser = extldap_authenticate($login, 'nopass', true);
                        if ($ldap_user !== false) {
                            $chamilo_user = extldap_get_chamilo_user($ldapuser);
                            $chamilo_user['username'] = $login;
                            $chamilo_user['auth_source'] = CAS_AUTH_SOURCE;
                            $chamilo_uid = external_add_user($chamilo_user);
                            $user_added = $login;
                        }
                        break;
                    default:
                        break;
                }
                return $user_added;
            }
        }
        //		//If the user is in the dokeos database and we are ,not in a logout request, we upgrade his infomration by ldap
        //		if (! $logout){
        //			$user_table = Database::get_main_table(TABLE_MAIN_USER);
        //			$sql = "SELECT user_id, username, password, auth_source, active, expiration_date ".
//.........这里部分代码省略.........
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:101,代码来源:authcas.php

示例8: importStudents

 /**
  * @param string $file
  * @param bool $moveFile
  */
 private function importStudents($file, $moveFile = true)
 {
     $data = Import::csv_to_array($file);
     /*
     * Another users import.
             Unique identifier: official code and username . ok
             Password should never get updated. ok
             If an update should need to occur (because it changed in the .csv),
             we’ll want that logged. We will handle this manually in that case.
             All other fields should be updateable, though passwords should of course not get updated. ok
             If a user gets deleted (not there anymore),
             He should be set inactive one year after the current date.
             So I presume you’ll just update the expiration date.
             We want to grant access to courses up to a year after deletion.
     */
     if (!empty($data)) {
         $language = $this->defaultLanguage;
         $this->logger->addInfo(count($data) . " records found.");
         foreach ($data as $row) {
             $row = $this->cleanUserRow($row);
             $user_id = UserManager::get_user_id_from_original_id($row['extra_' . $this->extraFieldIdNameList['user']], $this->extraFieldIdNameList['user']);
             $userInfo = array();
             $userInfoByOfficialCode = null;
             if (!empty($user_id)) {
                 $userInfo = api_get_user_info($user_id);
                 $userInfoByOfficialCode = api_get_user_info_from_official_code($row['official_code']);
             }
             $expirationDate = api_get_utc_datetime(strtotime("+" . intval($this->expirationDateInUserCreation) . "years"));
             if (empty($userInfo) && empty($userInfoByOfficialCode)) {
                 // Create user
                 $result = UserManager::create_user($row['firstname'], $row['lastname'], STUDENT, $row['email'], $row['username'], $row['password'], $row['official_code'], $language, $row['phone'], null, $row['auth_source'], $expirationDate, 1, 0, null, null, false);
                 if ($result) {
                     foreach ($row as $key => $value) {
                         if (substr($key, 0, 6) == 'extra_') {
                             //an extra field
                             UserManager::update_extra_field_value($result, substr($key, 6), $value);
                         }
                     }
                     $this->logger->addInfo("Students - User created: " . $row['username']);
                 } else {
                     $this->logger->addError("Students - User NOT created: " . $row['username'] . " " . $row['firstname'] . " " . $row['lastname']);
                 }
             } else {
                 if (empty($userInfo)) {
                     $this->logger->addError("Students - Can't update user :" . $row['username']);
                     continue;
                 }
                 if ($row['action'] == 'delete') {
                     // Inactive one year later
                     $userInfo['expiration_date'] = api_get_utc_datetime(api_strtotime(time() + 365 * 24 * 60 * 60));
                 }
                 $password = $row['password'];
                 // change password
                 $email = $row['email'];
                 // change email
                 $resetPassword = 2;
                 // allow password change
                 // Conditions that disables the update of password and email:
                 if (isset($this->conditions['importStudents'])) {
                     if (isset($this->conditions['importStudents']['update']) && isset($this->conditions['importStudents']['update']['avoid'])) {
                         // Blocking email update -
                         // 1. Condition
                         $avoidUsersWithEmail = $this->conditions['importStudents']['update']['avoid']['email'];
                         if ($userInfo['email'] != $row['email'] && in_array($row['email'], $avoidUsersWithEmail)) {
                             $this->logger->addInfo("Students - User email is not updated : " . $row['username'] . " because the avoid conditions (email).");
                             // Do not change email keep the old email.
                             $email = $userInfo['email'];
                         }
                         // 2. Condition
                         if (!in_array($userInfo['email'], $avoidUsersWithEmail) && !in_array($row['email'], $avoidUsersWithEmail)) {
                             $email = $userInfo['email'];
                         }
                         // 3. Condition
                         if (in_array($userInfo['email'], $avoidUsersWithEmail) && !in_array($row['email'], $avoidUsersWithEmail)) {
                             $email = $row['email'];
                         }
                         // Blocking password update
                         $avoidUsersWithPassword = $this->conditions['importStudents']['update']['avoid']['password'];
                         if ($userInfo['password'] != api_get_encrypted_password($row['password']) && in_array($row['password'], $avoidUsersWithPassword)) {
                             $this->logger->addInfo("Students - User password is not updated: " . $row['username'] . " because the avoid conditions (password).");
                             $password = null;
                             $resetPassword = 0;
                             // disallow password change
                         }
                     }
                 }
                 $expirationDate = api_get_utc_datetime(strtotime("+" . intval($this->expirationDateInUserUpdate) . "years"));
                 // Update user
                 $result = UserManager::update_user($userInfo['user_id'], $row['firstname'], $row['lastname'], $row['username'], $password, $row['auth_source'], $email, STUDENT, $userInfo['official_code'], $userInfo['phone'], $userInfo['picture_uri'], $expirationDate, $userInfo['active'], null, 0, null, null, null, false, $resetPassword);
                 if ($result) {
                     if ($row['username'] != $userInfo['username']) {
                         $this->logger->addInfo("Students - Username was changes from '" . $userInfo['username'] . "' to '" . $row['username'] . "' ");
                     }
                     foreach ($row as $key => $value) {
                         if (substr($key, 0, 6) == 'extra_') {
                             //an extra field
//.........这里部分代码省略.........
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:101,代码来源:import_csv.php

示例9: extldap_add_user_by_array

/**
 * Insert users from an array of user fields
 */
function extldap_add_user_by_array($data, $update_if_exists = true)
{
    global $extldap_user_correspondance;
    $lastname = api_convert_encoding($data[$extldap_user_correspondance['lastname']][0], api_get_system_encoding(), 'UTF-8');
    $firstname = api_convert_encoding($data[$extldap_user_correspondance['firstname']][0], api_get_system_encoding(), 'UTF-8');
    $email = $data[$extldap_user_correspondance['email']][0];
    $username = $data[$extldap_user_correspondance['username']][0];
    // TODO the password, if encrypted at the source, will be encrypted twice, which makes it useless. Try to fix that.
    $passwordKey = isset($extldap_user_correspondance['password']) ? $extldap_user_correspondance['password'] : 'userPassword';
    $password = $data[$passwordKey][0];
    // To ease management, we add the step-year (etape-annee) code
    //$official_code = $etape."-".$annee;
    $official_code = api_convert_encoding($data[$extldap_user_correspondance['official_code']][0], api_get_system_encoding(), 'UTF-8');
    $auth_source = 'ldap';
    // No expiration date for students (recover from LDAP's shadow expiry)
    $expiration_date = '0000-00-00 00:00:00';
    $active = 1;
    if (empty($status)) {
        $status = 5;
    }
    if (empty($phone)) {
        $phone = '';
    }
    if (empty($picture_uri)) {
        $picture_uri = '';
    }
    // Adding user
    $user_id = 0;
    if (UserManager::is_username_available($username)) {
        //echo "$username\n";
        $user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, api_get_setting('platformLanguage'), $phone, $picture_uri, $auth_source, $expiration_date, $active);
    } else {
        if ($update_if_exists) {
            $user = UserManager::get_user_info($username);
            $user_id = $user['user_id'];
            //echo "$username\n";
            UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active);
        }
    }
    return $user_id;
}
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:44,代码来源:ldap.inc.php

示例10: intval

    /**
     * Saves imported data.
     */
    function save_data($users, $course_list, $id_session) {
        $tbl_session                        = Database::get_main_table(TABLE_MAIN_SESSION);
        $tbl_session_rel_course             = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
        $tbl_session_rel_course_rel_user    = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
        $tbl_session_rel_user               = Database::get_main_table(TABLE_MAIN_SESSION_USER);

        $id_session = intval($id_session);
        $sendMail = $_POST['sendMail'] ? 1 : 0;

        // Adding users to the platform.
        $new_users = array();
        foreach ($users as $index => $user) {
            $user = MySpace::complete_missing_data($user);
            // coach only will registered users
            $default_status = '5';
            if ($user['create'] == '1') {
                $user['id'] = UserManager :: create_user($user['FirstName'], $user['LastName'], $default_status, $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '');
                $user['added_at_platform'] = 1;
            } else {
                $user['id'] = $user['create'];
                $user['added_at_platform'] = 0;
            }
            $new_users[] = $user;
        }
        // Update user list.
        $users = $new_users;

        // Inserting users.
        $super_list = array();
        foreach ($course_list as $enreg_course) {
            $nbr_users = 0;
            $new_users = array();
            $enreg_course = Database::escape_string($enreg_course);
            foreach ($users as $index => $user) {
                $userid = intval($user['id']);
                $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$userid')";
                $course_session = array('course' => $enreg_course, 'added' => 1);
                //$user['added_at_session'] = $course_session;
                Database::query($sql);
                if (Database::affected_rows()) {
                    $nbr_users++;
                }
                $new_users[] = $user;
            }
            $super_list[] = $new_users;

            //update the nbr_users field
            $sql_select = "SELECT COUNT(id_user) as nbUsers FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='$enreg_course'";
            $rs = Database::query($sql_select);
            list($nbr_users) = Database::fetch_array($rs);
            $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users WHERE id_session='$id_session' AND course_code='$enreg_course'";
            Database::query($sql_update);

            $sql_update = "UPDATE $tbl_session SET nbr_users= '$nbr_users' WHERE id='$id_session'";
            Database::query($sql_update);
        }
        // We don't delete the users (thoughts while dreaming)
        //$sql_delete = "DELETE FROM $tbl_session_rel_user WHERE id_session = '$id_session'";
        //Database::query($sql_delete);

        $new_users = array();
        foreach ($users as $index => $user) {
            $userid = $user['id'];
            $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_user(id_session, id_user) VALUES('$id_session','$userid')";
            Database::query($sql_insert);
            $user['added_at_session'] = 1;
            $new_users[] = $user;
        }

        $users = $new_users;
        $registered_users = get_lang('FileImported').'<br /> Import file results : <br />';
        // Sending emails.
        $addedto = '';
        if ($sendMail) {
            $i = 0;
            foreach ($users as $index => $user) {
                $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
                $emailbody = get_lang('Dear').' '.api_get_person_name($user['FirstName'], $user['LastName']).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : $user[UserName]\n".get_lang('Pass')." : $user[Password]\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path(WEB_PATH)." \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')."";

                api_mail_html(
                    api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS),
                    $user['Email'],
                    $emailsubject,
                    $emailbody
                );

                if (($user['added_at_platform'] == 1  && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) {
                    if ($user['added_at_platform'] == 1) {
                        $addedto = get_lang('UserCreatedPlatform');
                    } else  {
                        $addedto = '          ';
                    }

                    if ($user['added_at_session'] == 1) {
                        $addedto .= get_lang('UserInSession');
                    }
                    $registered_users .= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".api_get_person_name($user['FirstName'], $user['LastName'])."</a> - ".$addedto.'<br />';
//.........这里部分代码省略.........
开发者ID:annickvdp,项目名称:Chamilo1.9.10,代码行数:101,代码来源:myspace.lib.php

示例11: save_data

/**
 * Save the imported data
 */
function save_data($users)
{
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    if (is_array($users)) {
        foreach ($users as $index => $user) {
            $user = complete_missing_data($user);
            $user['Status'] = api_status_key($user['Status']);
            $user_id = UserManager::create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
            foreach ($user['Courses'] as $index => $course) {
                if (CourseManager::course_exists($course)) {
                    CourseManager::subscribe_user($user_id, $course, $user['Status']);
                }
            }
            if (strlen($user['ClassName']) > 0) {
                $class_id = ClassManager::get_class_id($user['ClassName']);
                ClassManager::add_user($user_id, $class_id);
            }
            // TODO: Hard-coded French texts.
            // Qualite
            if (!empty($user['Qualite'])) {
                UserManager::update_extra_field_value($user_id, 'qualite', $user['Qualite']);
            }
            // Categorie
            if (!empty($user['Categorie'])) {
                UserManager::update_extra_field_value($user_id, 'categorie', $user['Categorie']);
            }
            // Etat
            if (!empty($user['Etat'])) {
                UserManager::update_extra_field_value($user_id, 'etat', $user['Etat']);
            }
            // Niveau
            if (!empty($user['Niveau'])) {
                UserManager::update_extra_field_value($user_id, 'niveau', $user['Niveau']);
            }
        }
    }
}
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:40,代码来源:import.lib.php

示例12: external_add_user

/**
 * Return an array with all user info
 * @param associative array with at least thes fields setted :
  firstname, lastname, status, email, login, password
 * @return mixed   new user id - if the new user creation succeeds, false otherwise
 * */
function external_add_user($u)
{
    //Setting default
    if (empty($u['password'])) {
        $u['password'] = null;
    }
    if (empty($u['status'])) {
        $u['status'] = 5;
    }
    if (!isset($u['official_code'])) {
        $u['official_code'] = '';
    }
    if (!isset($u['language'])) {
        $u['language'] = '';
    }
    if (!isset($u['phone'])) {
        $u['phone'] = '';
    }
    if (!isset($u['picture_uri'])) {
        $u['picture_uri'] = '';
    }
    if (!isset($u['auth_source'])) {
        $u['auth_source'] = PLATFORM_AUTH_SOURCE;
    }
    if (!isset($u['expiration_date'])) {
        $u['expiration_date'] = '0000-00-00 00:00:00';
    }
    if (!isset($u['active'])) {
        $u['active'] = 1;
    }
    if (!isset($u['hr_dept_id'])) {
        $u['hr_dept_id'] = 0;
    }
    //id of responsible HR
    if (!isset($u['extra'])) {
        $u['extra'] = null;
    }
    if (!isset($u['encrypt_method'])) {
        $u['encrypt_method'] = '';
    }
    $chamilo_uid = UserManager::create_user($u['firstname'], $u['lastname'], $u['status'], $u['email'], $u['username'], $u['password'], $u['official_code'], $u['language'], $u['phone'], $u['picture_uri'], $u['auth_source'], $u['expiration_date'], $u['active'], $u['hr_dept_id'], $u['extra'], $u['encrypt_method']);
    return $chamilo_uid;
}
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:49,代码来源:functions.inc.php

示例13: get_lang

        $preview = LegalManager::show_last_condition($term_preview);
        $form->addElement('label', null, $preview);
    }
}
$form->addElement('button', 'submit', get_lang('RegisterUser'), array('class' => 'btn btn-primary btn-large'));
if ($form->validate()) {
    $values = $form->exportValues();
    $values['username'] = api_substr($values['username'], 0, USERNAME_MAX_LENGTH);
    //make *sure* the login isn't too long
    $values['status'] = STUDENT;
    $values['official_code'] = api_strtoupper($values['username']);
    if (api_get_setting('login_is_email') == 'true') {
        $values['username'] = $values['email'];
    }
    // Creates a new user
    $user_id = UserManager::create_user($values['firstname'], $values['lastname'], $values['status'], $values['email'], $values['username'], $values['pass1'], $values['official_code'], $values['language'], $values['phone'], $picture_uri, PLATFORM_AUTH_SOURCE, null, 1, 0, null, null, true);
    // Register extra fields
    $extras = array();
    foreach ($values as $key => $value) {
        if (substr($key, 0, 6) == 'extra_') {
            //an extra field
            $extras[substr($key, 6)] = $value;
        }
    }
    //update the extra fields
    $count_extra_field = count($extras);
    if ($count_extra_field > 0) {
        foreach ($extras as $key => $value) {
            UserManager::update_extra_field_value($user_id, $key, $value);
        }
    }
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:31,代码来源:inscription.php

示例14: redirect

<?php

require_once 'inc/shortcuts.php';
require_once 'inc/db.php';
require_once 'models/UserManager.php';
require_once 'models/SessionManager.php';
$result = null;
if ($form = is_form_submitted(['login', 'password', 'first_name', 'last_name'])) {
    try {
        if (UserManager::create_user($form['login'], $form['password'], $form['first_name'], $form['last_name']) && SessionManager::try_authenticate($form['login'], $form['password'])) {
            redirect('/');
        } else {
            $result = 'Bad :-(';
        }
    } catch (DbException $e) {
        if ($e instanceof DbConstraintsException) {
            $result = 'This login is already registered, please select another one';
        } else {
            $result = $e->getMessage();
        }
    }
}
render('signup', ['result' => $result]);
开发者ID:JJjie,项目名称:RuCTF-2015,代码行数:23,代码来源:signup.php

示例15: createUserHelper

 /**
  * Creates a user (helper method)
  *
  * @param string User first name
  * @param string User last name
  * @param int User status
  * @param string Login name
  * @param string Password (encrypted or not)
  * @param string Encrypt method. Leave blank if you are passing the password in clear text, set to the encrypt method used to encrypt the password otherwise. Remember
  * to include the salt in the extra fields if you are encrypting the password
  * @param string User id field name. Use "chamilo_user_id" as the field name if you want to use the internal user_id
  * @param string User id value. Leave blank if you are using the internal user_id
  * @param int Visibility.
  * @param string User email.
  * @param string Language.
  * @param string Phone.
  * @param string Expiration date
  * @param array Extra fields. An array with elements of the form ('field_name' => 'name_of_the_field', 'field_value' => 'value_of_the_field').
  * @return mixed New user id generated by the system, WSError otherwise
  */
 protected function createUserHelper($firstname, $lastname, $status, $login, $password, $encrypt_method, $user_id_field_name, $user_id_value, $visibility, $email, $language, $phone, $expiration_date, $extras = array())
 {
     global $api_failureList;
     // Add the original user id field name and value to the extra fields if needed
     $extras_associative = array();
     if ($user_id_field_name != "chamilo_user_id") {
         $extras_associative[$user_id_field_name] = $user_id_value;
     }
     if (!empty($extras)) {
         foreach ($extras as $extra) {
             $extras_associative[$extra['field_name']] = $extra['field_value'];
         }
     }
     $result = UserManager::create_user($firstname, $lastname, $status, $email, $login, $password, '', $language, $phone, '', PLATFORM_AUTH_SOURCE, $expiration_date, $visibility, 0, $extras_associative, $encrypt_method);
     if (!$result) {
         $failure = $api_failureList[0];
         if ($failure == 'login-pass already taken') {
             return new WSError(102, 'This username is already taken');
         } else {
             if ($failure == 'encrypt_method invalid') {
                 return new WSError(103, 'The encryption of the password is invalid');
             } else {
                 return new WSError(104, 'There was an error creating the user');
             }
         }
     } else {
         return $result;
     }
 }
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:49,代码来源:webservice_user.php


注:本文中的UserManager::create_user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。