aboutsummaryrefslogtreecommitdiff
path: root/auth.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-12-03 20:06:04 +0300
committerValentin Popov <info@valentineus.link>2017-12-03 20:06:04 +0300
commitb38a8d69f311959bdca53fb156a23c5fef89e902 (patch)
treec6e54713151369b467beed174ffe014d2a82958b /auth.php
parentb062def50ab79f8bbf50f6af981d2837bd6f5452 (diff)
downloadauth_token-b38a8d69f311959bdca53fb156a23c5fef89e902.tar.xz
auth_token-b38a8d69f311959bdca53fb156a23c5fef89e902.zip
Adapt authorization for the new version of the plug-in
Diffstat (limited to 'auth.php')
-rw-r--r--auth.php49
1 files changed, 13 insertions, 36 deletions
diff --git a/auth.php b/auth.php
index 6e7bb97..06cbf41 100644
--- a/auth.php
+++ b/auth.php
@@ -138,25 +138,20 @@ class auth_plugin_token extends auth_plugin_base {
* This method is called from login/index.php page for all enabled auth plugins.
*/
public function loginpage_hook() {
+ global $USER;
+
if ($token = $this->definition_token()) {
- if ($user = $this->definition_user($token)) {
- complete_user_login($user);
- $this->additional_actions($token);
+ if (isloggedin()) {
+ tool_managertokens_perform_additional_action($token, $USER);
+ $this->redirect_user();
}
- }
- }
- /**
- * Executes additional conditions and redirects the user.
- *
- * @param object $token
- */
- private function additional_actions($token) {
- if ($token->extendedaction == "redirect") {
- $this->redirect_user($token->extendedoptions);
+ if ($user = tool_managertokens_definition_user($token)) {
+ complete_user_login($user);
+ tool_managertokens_perform_additional_action($token, $user);
+ $this->redirect_user();
+ }
}
-
- $this->redirect_user();
}
/**
@@ -171,35 +166,17 @@ class auth_plugin_token extends auth_plugin_base {
}
/**
- * Identifies the user who owns the token.
- *
- * @param object $token
- * @return object
- */
- private function definition_user($token) {
- $user = false;
-
- if ($token->targettype == "user") {
- $user = core_user::get_user($token->targetid);
- }
-
- return $user;
- }
-
- /**
* Redirects the user.
*
* @param string $url
*/
- private function redirect_user($url = "") {
+ private function redirect_user() {
global $CFG, $SESSION;
- $wantsurl = optional_param("wantsurl", "", PARAM_URL);
+ $wantsurl = optional_param("wantsurl", null, PARAM_URL);
$redirect = $CFG->wwwroot;
- if (!empty($url)) {
- $redirect = new moodle_url($url);
- } else if (isset($SESSION->wantsurl)) {
+ if (isset($SESSION->wantsurl)) {
$redirect = $SESSION->wantsurl;
} else if (!empty($wantsurl)) {
$redirect = $wantsurl;