Commit 0b3d89ce authored by Nigel McNie's avatar Nigel McNie

Allow admin users to skip the 'change password' page when logging in as someone else.

This at least gives admins the chance of doing this if they want to.
parent 05db7853
......@@ -25,6 +25,7 @@
*/
define('INTERNAL', 1);
define('NOCHECKPASSWORDCHANGE', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
if (param_integer('login_submitted', 0)) {
......
......@@ -755,7 +755,17 @@ function requiredfields_submit(Pieform $form, $values) {
*/
function auth_check_password_change() {
global $USER;
if (!$USER->get('passwordchange')) {
if (
!$USER->get('passwordchange') // User doesn't need to change their password
|| ($USER->get('parentuser') && $USER->get('loginanyway')) // User is masquerading and wants to log in anyway
|| defined('NOCHECKPASSWORDCHANGE') // The page wants to skip this hassle
) {
return;
}
// Check if the user wants to log in anyway
if ($USER->get('passwordchange') && $USER->get('parentuser') && isset($_GET['loginanyway'])) {
$USER->loginanyway = true;
return;
}
......@@ -810,6 +820,9 @@ function auth_check_password_change() {
$smarty = smarty();
$smarty->assign('change_password_form', pieform($form));
$smarty->assign('loginasoverridepasswordchange',
get_string('loginasoverridepasswordchange', 'admin',
'<a href="' . get_config('wwwroot') . '?loginanyway">', '</a>'));
$smarty->display('change_password.tpl');
exit;
}
......
......@@ -86,6 +86,7 @@ class User {
'admininstitutions' => array(),
'staffinstitutions' => array(),
'parentuser' => null,
'loginanyway' => false,
'sesskey' => ''
);
$this->attributes = array();
......@@ -665,7 +666,7 @@ class LiveUser extends User {
*/
public function get($key) {
if (!array_key_exists($key, $this->defaults)) {
throw new InvalidArgumentException($key);
throw new InvalidArgumentException("Invalid key: $key");
}
if (null !== ($value = $this->SESSION->get("user/$key"))) {
return $value;
......@@ -728,6 +729,7 @@ class LiveUser extends User {
$this->reloadLiveUser($olduser->id);
$this->set('parentuser', null);
$this->set('loginanyway', false);
return $id;
}
......
......@@ -312,6 +312,7 @@ $string['becomeadminagain'] = 'Become %s again';
$string['loginasdenied'] = 'Attempt to login as another user without permission';
$string['loginastwice'] = 'Attempt to login as another user when already logged in as another user';
$string['loginasrestorenodata'] = 'No user data to restore';
$string['loginasoverridepasswordchange'] = 'As you are masquerading as another user, you may choose to %slog in anyway%s, ignoring the password change screen.';
// Institutions
$string['admininstitutions'] = 'Admininster Institutions';
......
......@@ -5,7 +5,9 @@
<h2>{str tag="changepassword"}</h2>
<p>{str tag="changepasswordinfo"}</p>
<div class="message">{$loginasoverridepasswordchange}</div>
{$change_password_form}
</div>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment