Skip to content
Snippets Groups Projects
Commit 4a3f9528 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

relocate relevant code from Seminar_Auth to Seminar_Register_Auth, fixes #1275

Closes #1275

Merge request studip/studip!781
parent 89512696
No related branches found
No related tags found
No related merge requests found
...@@ -30,12 +30,6 @@ class Seminar_Auth ...@@ -30,12 +30,6 @@ class Seminar_Auth
*/ */
protected $persistent_slots = ["auth", "classname"]; protected $persistent_slots = ["auth", "classname"];
/**
* @var string
*/
protected $mode = "log"; ## "log" for login only systems,
## "reg" for user self registration
/** /**
* @var bool * @var bool
*/ */
...@@ -74,22 +68,20 @@ class Seminar_Auth ...@@ -74,22 +68,20 @@ class Seminar_Auth
} }
} }
/** /**
* @return bool * Check current auth state. Should be one of
* @throws RuntimeException * 1) Not logged in (no valid auth info or auth expired)
* 2) Logged in (valid auth info)
* 3) Login in progress (if $this->cancel_login, revert to state 1)
* @return int
*/ */
function start() protected function getState(): int
{ {
global $sess;
# Check current auth state. Should be one of
# 1) Not logged in (no valid auth info or auth expired)
# 2) Logged in (valid auth info)
# 3) Login in progress (if $this->cancel_login, revert to state 1)
if ($this->is_authenticated()) { if ($this->is_authenticated()) {
$uid = $this->auth["uid"]; $uid = $this->auth['uid'];
switch ($uid) { switch ($uid) {
case "form": case 'form':
# Login in progress # Login in progress
if (Request::option($this->cancel_login)) { if (Request::option($this->cancel_login)) {
# If $this->cancel_login is set, delete all auth info and set # If $this->cancel_login is set, delete all auth info and set
...@@ -113,7 +105,18 @@ class Seminar_Auth ...@@ -113,7 +105,18 @@ class Seminar_Auth
$state = 1; $state = 1;
} }
switch ($state) { return $state;
}
/**
* @return bool
* @throws RuntimeException
*/
public function start()
{
global $sess;
switch ($this->getState()) {
case 1: case 1:
# No valid auth info or auth is expired # No valid auth info or auth is expired
...@@ -126,10 +129,6 @@ class Seminar_Auth ...@@ -126,10 +129,6 @@ class Seminar_Auth
return true; return true;
} }
# Check for "log" vs. "reg" mode
switch ($this->mode) {
case "yes":
case "log":
if ($this->nobody) { if ($this->nobody) {
# Authenticate as nobody # Authenticate as nobody
$this->auth["uid"] = "nobody"; $this->auth["uid"] = "nobody";
...@@ -141,34 +140,14 @@ class Seminar_Auth ...@@ -141,34 +140,14 @@ class Seminar_Auth
$sess->freeze(); $sess->freeze();
exit; exit;
} }
break;
case "reg":
if ($this->nobody) {
# Authenticate as nobody
$this->auth["uid"] = "nobody";
return true;
} else {
# Show the registration form
$this->auth_registerform();
$this->auth["uid"] = "form";
exit;
}
break;
default:
# This should never happen. Complain.
throw new RuntimeException("Error in auth handling: no valid mode specified.");
}
break;
case 2: case 2:
# Valid auth info # Valid auth info
# do nothin # do nothin
break; break;
case 3: case 3:
# Login in progress, check results and act accordingly # Login in progress, check results and act accordingly
switch ($this->mode) { $uid = $this->auth_validatelogin();
case "yes": if ($uid) {
case "log":
if ($uid = $this->auth_validatelogin()) {
$this->auth["uid"] = $uid; $this->auth["uid"] = $uid;
$keep_session_vars = ['auth', 'forced_language', '_language', 'contrast']; $keep_session_vars = ['auth', 'forced_language', '_language', 'contrast'];
if ($this->auth['perm'] === 'root') { if ($this->auth['perm'] === 'root') {
...@@ -184,29 +163,9 @@ class Seminar_Auth ...@@ -184,29 +163,9 @@ class Seminar_Auth
$sess->freeze(); $sess->freeze();
exit; exit;
} }
break;
case "reg":
if ($uid = $this->auth_doregister()) {
$this->auth["uid"] = $uid;
$GLOBALS['user'] = new Seminar_User($this->auth['uid']);
return true;
} else {
$this->auth_registerform();
$this->auth["uid"] = "form";
$sess->freeze();
exit;
}
break;
default:
# This should never happen. Complain.
throw new RuntimeException("Error in auth handling: no valid mode specified.");
break;
}
break;
default: default:
# This should never happen. Complain. # This should never happen. Complain.
throw new RuntimeException("Error in auth handling: invalid state reached."); throw new RuntimeException("Error in auth handling: invalid state reached.");
break;
} }
return false; return false;
......
...@@ -15,16 +15,42 @@ ...@@ -15,16 +15,42 @@
*/ */
class Seminar_Register_Auth extends Seminar_Auth class Seminar_Register_Auth extends Seminar_Auth
{ {
/** public function start()
* @var string {
*/ global $sess;
protected $mode = 'reg';
public $error_msg = ''; switch ($this->getState()) {
# No valid auth info or auth is expired
case 1:
if ($this->nobody) {
# Authenticate as nobody
$this->auth['uid'] = 'nobody';
return true;
} else {
# Show the registration form
$this->auth_registerform();
$this->auth['uid'] = 'form';
exit;
}
# Login in progress, check results and act accordingly
case 3:
$uid = $this->auth_doregister();
if ($uid) {
$this->auth['uid'] = $uid;
$GLOBALS['user'] = new Seminar_User($this->auth['uid']);
return true;
} else {
$this->auth_registerform();
$this->auth['uid'] = 'form';
$sess->freeze();
exit;
}
}
return parent::start();
}
/**
*
*/
public function auth_registerform() public function auth_registerform()
{ {
$this->check_environment(); $this->check_environment();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment