Skip to content
Snippets Groups Projects
Select Git revision
  • 2ef95bc8701e430e217ad0d17f9e9278c4c0fdec
  • main default protected
  • Kelvinrr-patch-3
  • radius_update
  • revert-616-apollo_pan
  • vims
  • 0.10
  • Kelvinrr-patch-2
  • revert-563-minirf_fix
  • Kelvinrr-patch-1
  • 0.9
  • acpaquette-patch-3
  • acpaquette-patch-2
  • acpaquette-patch-1
  • spiceql
  • ci-coverage
  • 0.10.0
  • 0.9.1
  • 0.9.0
  • 0.8.7
  • 0.8.8
  • 0.8.6
  • 0.8.3
  • 0.8.4
  • 0.8.5
  • 0.8.2
  • 0.8.1
  • 0.8.0
  • 0.7.3
  • 0.7.2
  • 0.7.1
  • 0.7.0
  • 0.6.5
  • 0.6.4
  • 0.6.3
  • 0.6.2
36 results

test_formatter.py

Blame
  • SessionData.php 3.99 KiB
    <?php
    
    /* ----------------------------------------------------------------------------
     *               INAF - National Institute for Astrophysics
     *               IRA  - Radioastronomical Institute - Bologna
     *               OATS - Astronomical Observatory - Trieste
     * ----------------------------------------------------------------------------
     *
     * Copyright (C) 2016 Istituto Nazionale di Astrofisica
     *
     * This program is free software; you can redistribute it and/or modify it under
     * the terms of the GNU General Public License Version 3 as published by the
     * Free Software Foundation.
     *
     * This program is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     * details.
     *
     * You should have received a copy of the GNU General Public License along with
     * this program; if not, write to the Free Software Foundation, Inc., 51
     * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     */
    
    namespace RAP;
    
    /**
     * This class wraps various objects that need to be stored into the session in
     * order to provide an object oriented transparent session management.
     */
    class SessionData {
    
        const KEY = "SessionData";
    
        private $user;
        private $userToJoin;
        private $x509DataToRegister;
        private $oauth2RequestData;
        private $action;
        private $loginIdentityType;
        private $autojoin = false;
        private $joinRejected = false;
    
        public function setUser(?User $user): void {
            $this->user = $user;
            $this->save();
        }
    
        public function getUser(): ?User {
            return $this->user;
        }
    
        public function setUserToJoin(?User $userToJoin): void {
            $this->userToJoin = $userToJoin;
            $this->save();
        }
    
        public function getUserToJoin(): ?User {
            return $this->userToJoin;
        }
    
        public function setAutojoin(bool $autojoin): void {
            $this->autojoin = $autojoin;
            $this->save();
        }
    
        public function isAutojoin(): bool {
            return $this->autojoin;
        }
    
        public function setJoinRejected(bool $joinRejected): void {
            $this->joinRejected = $joinRejected;
            $this->save();
        }
    
        public function isJoinRejected(): bool {
            return $this->joinRejected;
        }
    
        /**
         * Used for logging the identity type chosen for the login at the end of the login process
         */
        public function setLoginIdentityType(string $loginIdentityType): void {
            $this->loginIdentityType = $loginIdentityType;
            $this->save();
        }
    
        public function getLoginIdentityType(): ?string {
            return $this->loginIdentityType;
        }
    
        /**
         * Update the user data model stored into the session after the primary
         * identity has changed, in order to avoid reading again the user data from
         * the database.
         * @param int $identityId
         */
        public function updatePrimaryIdentity($identityId): void {
            foreach ($this->user->identities as $identity) {
                $identity->primary = ($identity->id === $identityId);
            }
            $this->save();
        }
    
        public function setX509DataToRegister(?X509Data $x509DataToRegister): void {
            $this->x509DataToRegister = $x509DataToRegister;
            $this->save();
        }
    
        public function getX509DataToRegister(): ?X509Data {
            return $this->x509DataToRegister;
        }
    
        public function setOAuth2RequestData(?OAuth2RequestData $oauth2RequestData): void {
            $this->oauth2RequestData = $oauth2RequestData;
            $this->save();
        }
    
        public function getOAuth2RequestData(): ?OAuth2RequestData {
            return $this->oauth2RequestData;
        }
    
        public function setAction(?string $action): void {
            $this->action = $action;
            $this->save();
        }
    
        public function getAction(): ?string {
            return $this->action;
        }
    
        /**
         * Store the data into the $_SESSION PHP variable
         */
        public function save() {
            $_SESSION[SessionData::KEY] = $this;
        }
    
    }