MDL-65856 session: UX review of session timeout

Add new setting 'sessiontimeoutwarning', gives logged in user ability to extend session when there is no activity.
This commit is contained in:
Heena Agheda
2020-12-21 08:43:21 +11:00
parent 4ec279a2f0
commit 9c5dc8fc7d
9 changed files with 151 additions and 55 deletions
+38
View File
@@ -3814,6 +3814,8 @@ class admin_setting_configduration extends admin_setting {
/** @var int default duration unit */
protected $defaultunit;
/** @var callable|null Validation function */
protected $validatefunction = null;
/**
* Constructor
@@ -3837,6 +3839,36 @@ class admin_setting_configduration extends admin_setting {
parent::__construct($name, $visiblename, $description, $defaultsetting);
}
/**
* Sets a validate function.
*
* The callback will be passed one parameter, the new setting value, and should return either
* an empty string '' if the value is OK, or an error message if not.
*
* @param callable|null $validatefunction Validate function or null to clear
* @since Moodle 3.10
*/
public function set_validate_function(?callable $validatefunction = null) {
$this->validatefunction = $validatefunction;
}
/**
* Validate the setting. This uses the callback function if provided; subclasses could override
* to carry out validation directly in the class.
*
* @param int $data New value being set
* @return string Empty string if valid, or error message text
* @since Moodle 3.10
*/
protected function validate_setting(int $data): string {
// If validation function is specified, call it now.
if ($this->validatefunction) {
return call_user_func($this->validatefunction, $data);
} else {
return '';
}
}
/**
* Returns selectable units.
* @static
@@ -3922,6 +3954,12 @@ class admin_setting_configduration extends admin_setting {
return get_string('errorsetting', 'admin');
}
// Validate the new setting.
$error = $this->validate_setting($seconds);
if ($error) {
return $error;
}
$result = $this->config_write($this->name, $seconds);
return ($result ? '' : get_string('errorsetting', 'admin'));
}