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


PHP setnew_password_and_mail函数代码示例

本文整理汇总了PHP中setnew_password_and_mail函数的典型用法代码示例。如果您正苦于以下问题:PHP setnew_password_and_mail函数的具体用法?PHP setnew_password_and_mail怎么用?PHP setnew_password_and_mail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: execute

 /**
  * Do the job.
  * Throw exceptions on errors (the job will be retried).
  */
 public function execute()
 {
     global $DB;
     // Generate new password emails for users - ppl expect these generated asap.
     if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
         mtrace('Creating passwords for new users...');
         $usernamefields = get_all_user_name_fields(true, 'u');
         $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.auth, u.deleted,\n                                                     u.suspended, u.emailstop, u.mnethostid, u.mailformat,\n                                                     {$usernamefields}, u.username, u.lang,\n                                                     p.id as prefid\n                                                FROM {user} u\n                                                JOIN {user_preferences} p ON u.id=p.userid\n                                               WHERE p.name='create_password' AND p.value='1' AND\n                                                     u.email !='' AND u.suspended = 0 AND\n                                                     u.auth != 'nologin' AND u.deleted = 0");
         // Note: we can not send emails to suspended accounts.
         foreach ($newusers as $newuser) {
             // Use a low cost factor when generating bcrypt hash otherwise
             // hashing would be slow when emailing lots of users. Hashes
             // will be automatically updated to a higher cost factor the first
             // time the user logs in.
             if (setnew_password_and_mail($newuser, true)) {
                 unset_user_preference('create_password', $newuser);
                 set_user_preference('auth_forcepasswordchange', 1, $newuser);
             } else {
                 trigger_error("Could not create and mail new user password!");
             }
         }
         $newusers->close();
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:28,代码来源:send_new_user_passwords_task.php

示例2: cron_run


//.........这里部分代码省略.........
    context_helper::create_instances();
    mtrace(' Created missing context instances');
    // Session gc.
    mtrace("Running session gc tasks...");
    \core\session\manager::gc();
    mtrace("...finished stale session cleanup");
    // Run the auth cron, if any before enrolments
    // because it might add users that will be needed in enrol plugins
    $auths = get_enabled_auth_plugins();
    mtrace("Running auth crons if required...");
    cron_trace_time_and_memory();
    foreach ($auths as $auth) {
        $authplugin = get_auth_plugin($auth);
        if (method_exists($authplugin, 'cron')) {
            mtrace("Running cron for auth/{$auth}...");
            $authplugin->cron();
            if (!empty($authplugin->log)) {
                mtrace($authplugin->log);
            }
        }
        unset($authplugin);
    }
    // Generate new password emails for users - ppl expect these generated asap
    if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
        mtrace('Creating passwords for new users...');
        $usernamefields = get_all_user_name_fields(true, 'u');
        $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email,\n                                                 {$usernamefields}, u.username, u.lang,\n                                                 p.id as prefid\n                                            FROM {user} u\n                                            JOIN {user_preferences} p ON u.id=p.userid\n                                           WHERE p.name='create_password' AND p.value='1' AND u.email !='' AND u.suspended = 0 AND u.auth != 'nologin' AND u.deleted = 0");
        // note: we can not send emails to suspended accounts
        foreach ($newusers as $newuser) {
            // Use a low cost factor when generating bcrypt hash otherwise
            // hashing would be slow when emailing lots of users. Hashes
            // will be automatically updated to a higher cost factor the first
            // time the user logs in.
            if (setnew_password_and_mail($newuser, true)) {
                unset_user_preference('create_password', $newuser);
                set_user_preference('auth_forcepasswordchange', 1, $newuser);
            } else {
                trigger_error("Could not create and mail new user password!");
            }
        }
        $newusers->close();
    }
    // It is very important to run enrol early
    // because other plugins depend on correct enrolment info.
    mtrace("Running enrol crons if required...");
    $enrols = enrol_get_plugins(true);
    foreach ($enrols as $ename => $enrol) {
        // do this for all plugins, disabled plugins might want to cleanup stuff such as roles
        if (!$enrol->is_cron_required()) {
            continue;
        }
        mtrace("Running cron for enrol_{$ename}...");
        cron_trace_time_and_memory();
        $enrol->cron();
        $enrol->set_config('lastcron', time());
    }
    // Run all cron jobs for each module
    mtrace("Starting activity modules");
    get_mailer('buffer');
    if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
        foreach ($mods as $mod) {
            $libfile = "{$CFG->dirroot}/mod/{$mod->name}/lib.php";
            if (file_exists($libfile)) {
                include_once $libfile;
                $cron_function = $mod->name . "_cron";
                if (function_exists($cron_function)) {
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:67,代码来源:cronlib.php

示例3: test_user_updated_event

 /**
  * Test user_updated event trigger by various apis.
  */
 public function test_user_updated_event()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $user = $this->getDataGenerator()->create_user();
     // Set config to allow email_to_user() to be called.
     $CFG->noemailever = false;
     // Update user password.
     $sink = $this->redirectEvents();
     $sink2 = $this->redirectEmails();
     // Make sure we are redirecting emails.
     setnew_password_and_mail($user);
     update_internal_user_password($user, 'randompass');
     $events = $sink->get_events();
     $sink->close();
     $sink2->close();
     // Test updated value.
     $dbuser = $DB->get_record('user', array('id' => $user->id));
     $this->assertSame($user->firstname, $dbuser->firstname);
     $this->assertNotSame('M00dLe@T', $dbuser->password);
     // Test event.
     foreach ($events as $event) {
         $this->assertInstanceOf('\\core\\event\\user_updated', $event);
         $this->assertSame($user->id, $event->objectid);
         $this->assertSame('user_updated', $event->get_legacy_eventname());
         $this->assertEventLegacyData($user, $event);
         $this->assertEquals(context_user::instance($user->id), $event->get_context());
         $expectedlogdata = array(SITEID, 'user', 'update', 'view.php?id=' . $user->id, '');
         $this->assertEventLegacyLogData($expectedlogdata, $event);
     }
 }
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:34,代码来源:moodlelib_test.php

示例4: useredit_update_interests

     useredit_update_interests($usernew, $usernew->interests);
 }
 // Update user picture.
 if (empty($USER->newadminuser)) {
     useredit_update_picture($usernew, $userform, $filemanageroptions);
 }
 // Update mail bounces.
 useredit_update_bounces($user, $usernew);
 // Update forum track preference.
 useredit_update_trackforums($user, $usernew);
 // Save custom profile fields data.
 profile_save_data($usernew);
 // Reload from db.
 $usernew = $DB->get_record('user', array('id' => $usernew->id));
 if ($createpassword) {
     setnew_password_and_mail($usernew);
     unset_user_preference('create_password', $usernew);
     set_user_preference('auth_forcepasswordchange', 1, $usernew);
 }
 // Trigger update/create event, after all fields are stored.
 if ($usercreated) {
     \core\event\user_created::create_from_userid($usernew->id)->trigger();
 } else {
     \core\event\user_updated::create_from_userid($usernew->id)->trigger();
 }
 if ($user->id == $USER->id) {
     // Override old $USER session variable.
     foreach ((array) $usernew as $variable => $value) {
         if ($variable === 'description' or $variable === 'password') {
             // These are not set for security nad perf reasons.
             continue;
开发者ID:alanaipe2015,项目名称:moodle,代码行数:31,代码来源:editadvanced.php

示例5: test_setnew_password_and_mail

 /**
  * Test setnew_password_and_mail.
  */
 public function test_setnew_password_and_mail()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     $user = $this->getDataGenerator()->create_user();
     // Update user password.
     $sink = $this->redirectEvents();
     $sink2 = $this->redirectEmails();
     // Make sure we are redirecting emails.
     setnew_password_and_mail($user);
     $events = $sink->get_events();
     $sink->close();
     $sink2->close();
     $event = array_pop($events);
     // Test updated value.
     $dbuser = $DB->get_record('user', array('id' => $user->id));
     $this->assertSame($user->firstname, $dbuser->firstname);
     $this->assertNotEmpty($dbuser->password);
     // Test event.
     $this->assertInstanceOf('\\core\\event\\user_password_updated', $event);
     $this->assertSame($user->id, $event->relateduserid);
     $this->assertEquals(context_user::instance($user->id), $event->get_context());
     $this->assertEventContextNotUsed($event);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:27,代码来源:moodlelib_test.php

示例6: create_users

 /**
  * Create one or more users.
  *
  * @throws invalid_parameter_exception
  * @param array $users An array of users to create.
  * @return array An array of arrays
  * @since Moodle 2.2
  */
 public static function create_users($users)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/lib/weblib.php";
     require_once $CFG->dirroot . "/user/lib.php";
     require_once $CFG->dirroot . "/user/profile/lib.php";
     // Required for customfields related function.
     // Ensure the current user is allowed to run this function.
     $context = context_system::instance();
     self::validate_context($context);
     require_capability('moodle/user:create', $context);
     // Do basic automatic PARAM checks on incoming data, using params description.
     // If any problems are found then exceptions are thrown with helpful error messages.
     $params = self::validate_parameters(self::create_users_parameters(), array('users' => $users));
     $availableauths = core_component::get_plugin_list('auth');
     unset($availableauths['mnet']);
     // These would need mnethostid too.
     unset($availableauths['webservice']);
     // We do not want new webservice users for now.
     $availablethemes = core_component::get_plugin_list('theme');
     $availablelangs = get_string_manager()->get_list_of_translations();
     $transaction = $DB->start_delegated_transaction();
     $userids = array();
     $createpassword = false;
     foreach ($params['users'] as $user) {
         // Make sure that the username doesn't already exist.
         if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
             throw new invalid_parameter_exception('Username already exists: ' . $user['username']);
         }
         // Make sure auth is valid.
         if (empty($availableauths[$user['auth']])) {
             throw new invalid_parameter_exception('Invalid authentication type: ' . $user['auth']);
         }
         // Make sure lang is valid.
         if (empty($availablelangs[$user['lang']])) {
             throw new invalid_parameter_exception('Invalid language code: ' . $user['lang']);
         }
         // Make sure lang is valid.
         if (!empty($user['theme']) && empty($availablethemes[$user['theme']])) {
             // Theme is VALUE_OPTIONAL,
             // so no default value
             // We need to test if the client sent it
             // => !empty($user['theme']).
             throw new invalid_parameter_exception('Invalid theme: ' . $user['theme']);
         }
         // Make sure we have a password or have to create one.
         if (empty($user['password']) && empty($user['createpassword'])) {
             throw new invalid_parameter_exception('Invalid password: you must provide a password, or set createpassword.');
         }
         $user['confirmed'] = true;
         $user['mnethostid'] = $CFG->mnet_localhost_id;
         // Start of user info validation.
         // Make sure we validate current user info as handled by current GUI. See user/editadvanced_form.php func validation().
         if (!validate_email($user['email'])) {
             throw new invalid_parameter_exception('Email address is invalid: ' . $user['email']);
         } else {
             if (empty($CFG->allowaccountssameemail) && $DB->record_exists('user', array('email' => $user['email'], 'mnethostid' => $CFG->mnet_localhost_id))) {
                 throw new invalid_parameter_exception('Email address already exists: ' . $user['email']);
             }
         }
         // End of user info validation.
         $createpassword = !empty($user['createpassword']);
         unset($user['createpassword']);
         if ($createpassword) {
             $user['password'] = '';
             $updatepassword = false;
         } else {
             $updatepassword = true;
         }
         // Create the user data now!
         $user['id'] = user_create_user($user, $updatepassword, false);
         // Custom fields.
         if (!empty($user['customfields'])) {
             foreach ($user['customfields'] as $customfield) {
                 // Profile_save_data() saves profile file it's expecting a user with the correct id,
                 // and custom field to be named profile_field_"shortname".
                 $user["profile_field_" . $customfield['type']] = $customfield['value'];
             }
             profile_save_data((object) $user);
         }
         if ($createpassword) {
             $userobject = (object) $user;
             setnew_password_and_mail($userobject);
             unset_user_preference('create_password', $userobject);
             set_user_preference('auth_forcepasswordchange', 1, $userobject);
         }
         // Trigger event.
         \core\event\user_created::create_from_userid($user['id'])->trigger();
         // Preferences.
         if (!empty($user['preferences'])) {
             foreach ($user['preferences'] as $preference) {
                 set_user_preference($preference['type'], $preference['value'], $user['id']);
//.........这里部分代码省略.........
开发者ID:wset,项目名称:moodle-local_extrauserlookups,代码行数:101,代码来源:externallib.php

示例7: cron_run


//.........这里部分代码省略.........
            // value in days
            $loglifetime = $timenow - $CFG->loglifetime * 3600 * 24;
            // Delete child records from backup_logs
            $DB->execute("DELETE FROM {backup_logs}\n                           WHERE EXISTS (\n                               SELECT 'x'\n                                 FROM {backup_controllers} bc\n                                WHERE bc.backupid = {backup_logs}.backupid\n                                  AND bc.timecreated < ?)", array($loglifetime));
            // Delete records from backup_controllers
            $DB->execute("DELETE FROM {backup_controllers}\n                          WHERE timecreated < ?", array($loglifetime));
            mtrace("Deleted old backup records");
        }
        flush();
        /// Delete old cached texts
        if (!empty($CFG->cachetext)) {
            // Defined in config.php
            $cachelifetime = time() - $CFG->cachetext - 60;
            // Add an extra minute to allow for really heavy sites
            if ($DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime))) {
                mtrace("Deleted old cache_text records");
            }
        }
        flush();
        if (!empty($CFG->notifyloginfailures)) {
            notify_login_failures();
            mtrace('Notified login failured');
        }
        flush();
        //
        // generate new password emails for users
        //
        mtrace('checking for create_password');
        if ($DB->count_records('user_preferences', array('name' => 'create_password', 'value' => '1'))) {
            mtrace('creating passwords for new users');
            $newusers = $DB->get_records_sql("SELECT u.id as id, u.email, u.firstname,\n                                                     u.lastname, u.username,\n                                                     p.id as prefid\n                                                FROM {user} u\n                                                JOIN {user_preferences} p ON u.id=p.userid\n                                               WHERE p.name='create_password' AND p.value='1' AND u.email !='' ");
            foreach ($newusers as $newuserid => $newuser) {
                // email user
                if (setnew_password_and_mail($newuser)) {
                    // remove user pref
                    $DB->delete_records('user_preferences', array('id' => $newuser->prefid));
                } else {
                    trigger_error("Could not create and mail new user password!");
                }
            }
        }
        if (!empty($CFG->usetags)) {
            require_once $CFG->dirroot . '/tag/lib.php';
            tag_cron();
            mtrace('Executed tag cron');
        }
        // Accesslib stuff
        cleanup_contexts();
        mtrace('Cleaned up contexts');
        gc_cache_flags();
        mtrace('Cleaned cache flags');
        // If you suspect that the context paths are somehow corrupt
        // replace the line below with: build_context_path(true);
        build_context_path();
        mtrace('Built context paths');
        if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
            $notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
            $DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime' => $notificationdeletetime));
            mtrace('Cleaned up read notifications');
        }
        mtrace("Finished clean-up tasks...");
    }
    // End of occasional clean-up tasks
    // Run automated backups if required.
    require_once $CFG->dirroot . '/backup/util/includes/backup_includes.php';
    require_once $CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php';
开发者ID:vuchannguyen,项目名称:web,代码行数:67,代码来源:cronlib.php


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