Merge branch 'wip-MDL-46247-master' of https://github.com/mackensen/moodle
authorSam Hemelryk <sam@moodle.com>
Sun, 13 Jul 2014 23:55:02 +0000 (11:55 +1200)
committerSam Hemelryk <sam@moodle.com>
Sun, 13 Jul 2014 23:55:02 +0000 (11:55 +1200)
1  2 
lib/moodlelib.php

diff --combined lib/moodlelib.php
@@@ -4426,20 -4426,6 +4426,6 @@@ function authenticate_user_login($usern
              return false;
          }
  
-         // Do not try to authenticate non-existent accounts when user creation is disabled.
-         if (!empty($CFG->authpreventaccountcreation)) {
-             $failurereason = AUTH_LOGIN_NOUSER;
-             // Trigger login failed event.
-             $event = \core\event\user_login_failed::create(array('other' => array('username' => $username,
-                     'reason' => $failurereason)));
-             $event->trigger();
-             error_log('[client '.getremoteaddr()."]  $CFG->wwwroot  Unknown user, can not create new accounts:  $username  ".
-                     $_SERVER['HTTP_USER_AGENT']);
-             return false;
-         }
          // User does not exist.
          $auths = $authsenabled;
          $user = new stdClass();
                  $user = update_user_record_by_id($user->id);
              }
          } else {
-             // Create account, we verified above that user creation is allowed.
-             $user = create_user_record($username, $password, $auth);
+             // The user is authenticated but user creation may be disabled.
+             if (!empty($CFG->authpreventaccountcreation)) {
+                 $failurereason = AUTH_LOGIN_UNAUTHORISED;
+                 // Trigger login failed event.
+                 $event = \core\event\user_login_failed::create(array('other' => array('username' => $username,
+                         'reason' => $failurereason)));
+                 $event->trigger();
+                 error_log('[client '.getremoteaddr()."]  $CFG->wwwroot  Unknown user, can not create new accounts:  $username  ".
+                         $_SERVER['HTTP_USER_AGENT']);
+                 return false;
+             } else {
+                 $user = create_user_record($username, $password, $auth);
+             }
          }
  
          $authplugin->sync_roles($user);
@@@ -8778,7 -8777,43 +8777,7 @@@ function message_popup_window() 
      // If we have new messages to notify the user about.
      if (!empty($messageusers)) {
  
 -        $strmessages = '';
 -        if (count($messageusers)>1) {
 -            $strmessages = get_string('unreadnewmessages', 'message', count($messageusers));
 -        } else {
 -            $messageusers = reset($messageusers);
 -
 -            // Show who the message is from if its not a notification.
 -            if (!$messageusers->notification) {
 -                $strmessages = get_string('unreadnewmessage', 'message', fullname($messageusers) );
 -            }
 -
 -            // Try to display the small version of the message.
 -            $smallmessage = null;
 -            if (!empty($messageusers->smallmessage)) {
 -                // Display the first 200 chars of the message in the popup.
 -                $smallmessage = null;
 -                if (core_text::strlen($messageusers->smallmessage) > 200) {
 -                    $smallmessage = core_text::substr($messageusers->smallmessage, 0, 200).'...';
 -                } else {
 -                    $smallmessage = $messageusers->smallmessage;
 -                }
 -
 -                // Prevent html symbols being displayed.
 -                if ($messageusers->fullmessageformat == FORMAT_HTML) {
 -                    $smallmessage = html_to_text($smallmessage);
 -                } else {
 -                    $smallmessage = s($smallmessage);
 -                }
 -            } else if ($messageusers->notification) {
 -                // Its a notification with no smallmessage so just say they have a notification.
 -                $smallmessage = get_string('unreadnewnotification', 'message');
 -            }
 -            if (!empty($smallmessage)) {
 -                $strmessages .= '<div id="usermessage">'.s($smallmessage).'</div>';
 -            }
 -        }
 -
 +        $strmessages = get_string('unreadnewmessages', 'message', count($messageusers));
          $strgomessage = get_string('gotomessages', 'message');
          $strstaymessage = get_string('ignore', 'admin');