Source of file SAMLLoginForm.php
Size: 3,771 Bytes - Last Modified: 2021-12-23T10:27:14+00:00
/var/www/docs.ssmods.com/process/src/code/authenticators/SAMLLoginForm.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 | <?php /** * Class SAMLLoginForm * * This not very interesting in itself. It's pretty much boiler-plate code to access the authenticator. */ class SAMLLoginForm extends LoginForm { /** * This field is used in the "You are logged in as %s" message * @var string */ public $loggedInAsField = 'FirstName'; /** * @var string */ protected $authenticator_class = 'SAMLAuthenticator'; /** * Constructor * * @param Controller $controller * @param string $name method on the $controller * @param FieldList $fields * @param FieldList $actions * @param bool $checkCurrentUser - show logout button if logged in */ public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) { $backURL = Session::get('BackURL'); if (isset($_REQUEST['BackURL'])) { $backURL = $_REQUEST['BackURL']; } if ($checkCurrentUser && $this->shouldShowLogoutFields()) { $fields = new FieldList([ new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this) ]); $actions = new FieldList([ new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")) ]); } else { if (!$fields) { $fields = new FieldList([ new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this) ]); } if (!$actions) { $actions = new FieldList([ new FormAction('dologin', _t('Member.BUTTONLOGIN', "Log in")) ]); } } if ($backURL) { $fields->push(new HiddenField('BackURL', 'BackURL', $backURL)); } $this->setFormMethod('POST', true); parent::__construct($controller, $name, $fields, $actions); } /** * * * @return bool */ protected function shouldShowLogoutFields() { if (!Member::currentUser()) { return false; } if (!Member::logged_in_session_exists()) { return false; } return true; } /** * Get message from session */ protected function getMessageFromSession() { // The "MemberLoginForm.force_message session" is set in Security#permissionFailure() // and displays messages like "You don't have access to this page" // if force isn't set, it will just display "You're logged in as {name}" if (($member = Member::currentUser()) && !Session::get('MemberLoginForm.force_message')) { $this->message = _t( 'Member.LOGGEDINAS', "You're logged in as {name}.", ['name' => $member->{$this->loggedInAsField}] ); } Session::set('MemberLoginForm.force_message', false); parent::getMessageFromSession(); return $this->message; } /** * Login form handler method * * This method is called when the user clicks on "Log in" * * @param array $data Submitted data */ public function dologin($data) { call_user_func_array([$this->authenticator_class, 'authenticate'], [$data, $this]); } /** * Log out form handler method * * This method is called when the user clicks on "logout" on the form * created when the parameter <i>$checkCurrentUser</i> of the * {@link __construct constructor} was set to TRUE and the user was * currently logged in. */ public function logout() { $s = new Security(); $s->logout(false); } } |