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


PHP core_user::get_user_by_username方法代码示例

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


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

示例1: i_force_a_password_change_for_user

 /**
  * Force a password change for a specific user.
  *
  * @Given /^I force a password change for user "([^"]*)"$/
  * @param string $username The username of the user whose password will expire
  */
 public function i_force_a_password_change_for_user($username)
 {
     $user = core_user::get_user_by_username($username, 'id', null, MUST_EXIST);
     set_user_preference("auth_forcepasswordchange", true, $user);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:11,代码来源:behat_login.php

示例2: password_expire

 /**
  * Return number of days to user password expires.
  *
  * If user password does not expire, it should return 0 or a positive value.
  * If user password is already expired, it should return negative value.
  *
  * @param mixed $username username (with system magic quotes)
  * @return integer
  */
 public function password_expire($username)
 {
     $result = 0;
     if (!empty($this->config->expirationtime)) {
         $user = core_user::get_user_by_username($username, 'id,timecreated');
         $lastpasswordupdatetime = get_user_preferences('auth_manual_passwordupdatetime', $user->timecreated, $user->id);
         $expiretime = $lastpasswordupdatetime + $this->config->expirationtime * DAYSECS;
         $now = time();
         $result = ($expiretime - $now) / DAYSECS;
         if ($expiretime > $now) {
             $result = ceil($result);
         } else {
             $result = floor($result);
         }
     }
     return $result;
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:26,代码来源:auth.php

示例3: test_get_user_by_username

 /**
  * Test get_user_by_username method.
  */
 public function test_get_user_by_username()
 {
     $record = array();
     $record['username'] = 'johndoe';
     $record['email'] = 'johndoe@example.com';
     $record['timecreated'] = time();
     // Create a default user for the test.
     $userexpected = $this->getDataGenerator()->create_user($record);
     // Assert that the returned user is the espected one.
     $this->assertEquals($userexpected, core_user::get_user_by_username('johndoe'));
     // Assert that a subset of fields is correctly returned.
     $this->assertEquals((object) $record, core_user::get_user_by_username('johndoe', 'username,email,timecreated'));
     // Assert that a user with a different mnethostid will no be returned.
     $this->assertFalse(core_user::get_user_by_username('johndoe', 'username,email,timecreated', 2));
     // Create a new user from a different host.
     $record['mnethostid'] = 2;
     $userexpected2 = $this->getDataGenerator()->create_user($record);
     // Assert that the new user is returned when specified the correct mnethostid.
     $this->assertEquals($userexpected2, core_user::get_user_by_username('johndoe', '*', 2));
     // Assert that a user not in the db return false.
     $this->assertFalse(core_user::get_user_by_username('janedoe'));
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:25,代码来源:user_test.php

示例4: get_recipient_users

 /**
  * Returns list of recipient users.
  *
  * @param stdClass $data
  * @return array user objects
  */
 protected function get_recipient_users($data, $context)
 {
     $recipients = array();
     // Admin.
     if (!empty($data->recipient['admin'])) {
         $user = get_admin();
         $recipients[$user->id] = $user;
     }
     // Support.
     if (!empty($data->recipient['support'])) {
         if ($user = \core_user::get_support_user()) {
             $recipients[$user->id] = $user;
         }
     }
     // Author.
     if (!empty($data->recipient['author'])) {
         $recipients[$data->recipient['author']] = \core_user::get_user($data->recipient['author']);
     }
     // Username.
     if (!empty($data->recipient['username'])) {
         $usernames = explode(',', $data->recipient['username']);
         foreach ($usernames as $username) {
             if ($user = \core_user::get_user_by_username($username)) {
                 $recipients[$user->id] = $user;
             }
         }
     }
     // Notification roles.
     if (!empty($config->recipient['role'])) {
         if ($users = get_users_by_capability($context, 'mod/dataform:notification')) {
             foreach ($users as $userid => $user) {
                 $recipients[$userid] = $user;
             }
         }
     }
     return $recipients;
 }
开发者ID:parksandwildlife,项目名称:learning,代码行数:43,代码来源:notification.php


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