Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * Test get_user_by_username method.
  */
 public function test_get_user_by_username()
 {
     $record = array();
     $record['username'] = '******';
     $record['email'] = '*****@*****.**';
     $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'));
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }