Merge branch 'wip-MDL-46247-master' of https://github.com/mackensen/moodle

This commit is contained in:
Sam Hemelryk
2014-07-14 11:55:02 +12:00
4 changed files with 25 additions and 19 deletions
+1
View File
@@ -1848,6 +1848,7 @@ $string['trackforumsyes'] = 'Yes: highlight new posts for me';
$string['trysearching'] = 'Try searching instead.';
$string['turneditingoff'] = 'Turn editing off';
$string['turneditingon'] = 'Turn editing on';
$string['unauthorisedlogin'] = 'The user account "{$a}" is not available on this site';
$string['undecided'] = 'Undecided';
$string['unfinished'] = 'Unfinished';
$string['unknowncategory'] = 'Unknown category';
+2
View File
@@ -76,6 +76,8 @@ define('AUTH_LOGIN_FAILED', 3);
/** Can not login because user is locked out. */
define('AUTH_LOGIN_LOCKOUT', 4);
/** Can not login becauser user is not authorised. */
define('AUTH_LOGIN_UNAUTHORISED', 5);
/**
* Abstract authentication plugin.
+15 -16
View File
@@ -4426,20 +4426,6 @@ function authenticate_user_login($username, $password, $ignorelockout=false, &$f
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();
@@ -4492,8 +4478,21 @@ function authenticate_user_login($username, $password, $ignorelockout=false, &$f
$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);
+7 -3
View File
@@ -137,7 +137,7 @@ if ($frm and isset($frm->username)) { // Login WITH
$frm = false;
} else {
if (empty($errormsg)) {
$user = authenticate_user_login($frm->username, $frm->password);
$user = authenticate_user_login($frm->username, $frm->password, false, $errorcode);
}
}
@@ -233,8 +233,12 @@ if ($frm and isset($frm->username)) { // Login WITH
} else {
if (empty($errormsg)) {
$errormsg = get_string("invalidlogin");
$errorcode = 3;
if ($errorcode == AUTH_LOGIN_UNAUTHORISED) {
$errormsg = get_string("unauthorisedlogin", "", $frm->username);
} else {
$errormsg = get_string("invalidlogin");
$errorcode = 3;
}
}
}
}