public function readParameters() {
parent::readParameters();
- $userId = WCF::getSession()->getVar('__changeUserAfterMultifactor__');
- if (!$userId) {
- throw new PermissionDeniedException();
- }
- $this->user = new User($userId);
- if (!$this->user->userID) {
+ $this->user = WCF::getSession()->getPendingUserChange();
+ if (!$this->user) {
throw new PermissionDeniedException();
}
private const GUEST_SESSION_LIFETIME = 7200;
private const USER_SESSION_LIFETIME = 86400 * 14;
+ private const CHANGE_USER_AFTER_MULTIFACTOR_KEY = '__changeUserAfterMultifactor__';
+
/**
* Provides access to session data.
*
*/
public function changeUserAfterMultifactor(User $user): bool {
if ($user->multifactorActive) {
- $this->register('__changeUserAfterMultifactor__', $user->userID);
+ $this->register(self::CHANGE_USER_AFTER_MULTIFACTOR_KEY, $user->userID);
return true;
}
}
}
+ /**
+ * Returns the pending user change initiated by changeUserAfterMultifactor().
+ */
+ public function getPendingUserChange(): ?User {
+ $userId = WCF::getSession()->getVar(self::CHANGE_USER_AFTER_MULTIFACTOR_KEY);
+ if (!$userId) {
+ return null;
+ }
+
+ $user = new User($userId);
+
+ if (!$user->userID) {
+ return null;
+ }
+
+ return $user;
+ }
+
/**
* Stores a new user object in this session, e.g. a user was guest because not
* logged in, after the login his old session is used to store his full data.