2014-10-06 05:01:33 +02:00
|
|
|
<?php
|
|
|
|
|
2017-04-30 05:17:26 +02:00
|
|
|
namespace SilverStripe\Security\MemberAuthenticator;
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
2017-04-30 05:17:26 +02:00
|
|
|
use SilverStripe\Control\RequestHandler;
|
2017-05-31 07:48:16 +02:00
|
|
|
use SilverStripe\Core\Convert;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Forms\CheckboxField;
|
2017-04-17 05:07:28 +02:00
|
|
|
use SilverStripe\Forms\FieldList;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Forms\FormAction;
|
2017-04-17 05:07:28 +02:00
|
|
|
use SilverStripe\Forms\HiddenField;
|
|
|
|
use SilverStripe\Forms\LiteralField;
|
|
|
|
use SilverStripe\Forms\PasswordField;
|
2017-05-31 07:48:16 +02:00
|
|
|
use SilverStripe\Security\RememberLoginHash;
|
2017-04-30 05:17:26 +02:00
|
|
|
use SilverStripe\Security\Security;
|
2016-06-23 01:37:22 +02:00
|
|
|
|
2014-10-06 05:01:33 +02:00
|
|
|
/**
|
|
|
|
* Provides the in-cms session re-authentication form for the "member" authenticator
|
|
|
|
*/
|
2017-05-30 09:42:00 +02:00
|
|
|
class CMSMemberLoginForm extends MemberLoginForm
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
|
|
|
|
2017-04-17 05:07:28 +02:00
|
|
|
/**
|
|
|
|
* CMSMemberLoginForm constructor.
|
2017-04-30 05:17:26 +02:00
|
|
|
* @param RequestHandler $controller
|
2017-04-17 05:07:28 +02:00
|
|
|
* @param string $authenticatorClass
|
|
|
|
* @param FieldList $name
|
|
|
|
*/
|
2017-04-30 05:17:26 +02:00
|
|
|
public function __construct(RequestHandler $controller, $authenticatorClass, $name)
|
2017-04-17 05:07:28 +02:00
|
|
|
{
|
|
|
|
$this->controller = $controller;
|
|
|
|
|
2018-11-05 13:47:47 +01:00
|
|
|
$this->setAuthenticatorClass($authenticatorClass);
|
2017-04-17 05:07:28 +02:00
|
|
|
|
|
|
|
$fields = $this->getFormFields();
|
|
|
|
|
|
|
|
$actions = $this->getFormActions();
|
|
|
|
|
2017-04-30 05:17:26 +02:00
|
|
|
parent::__construct($controller, $authenticatorClass, $name, $fields, $actions);
|
2017-05-31 07:48:16 +02:00
|
|
|
|
|
|
|
$this->addExtraClass('form--no-dividers');
|
2017-04-17 05:07:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getFormFields()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
|
|
|
// Set default fields
|
2017-04-30 05:17:26 +02:00
|
|
|
$fields = FieldList::create([
|
2018-11-05 13:47:47 +01:00
|
|
|
HiddenField::create("AuthenticationMethod", null, $this->getAuthenticatorClass(), $this),
|
2017-04-17 05:07:28 +02:00
|
|
|
HiddenField::create('tempid', null, $this->controller->getRequest()->requestVar('tempid')),
|
2017-05-31 07:48:16 +02:00
|
|
|
PasswordField::create("Password", _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
|
2017-04-30 05:17:26 +02:00
|
|
|
]);
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-04-30 05:17:26 +02:00
|
|
|
if (Security::config()->get('autologin_enabled')) {
|
2017-05-31 07:48:16 +02:00
|
|
|
$fields->insertAfter(
|
|
|
|
'Password',
|
|
|
|
CheckboxField::create(
|
|
|
|
"Remember",
|
|
|
|
_t(
|
2021-06-17 23:50:13 +02:00
|
|
|
'SilverStripe\\Security\\Member.KEEP_ME_SIGNED_IN',
|
|
|
|
'Keep me signed in for {count} days',
|
2017-05-31 07:48:16 +02:00
|
|
|
[ 'count' => RememberLoginHash::config()->uninherited('token_expiry_days') ]
|
|
|
|
)
|
|
|
|
)
|
2021-04-08 02:32:12 +02:00
|
|
|
->setAttribute(
|
|
|
|
'title',
|
|
|
|
_t(
|
|
|
|
'SilverStripe\\Security\\Member.KEEP_ME_SIGNED_IN_TOOLTIP',
|
2021-06-17 23:50:13 +02:00
|
|
|
'You will remain authenticated on this device for {count} days. Only use this feature if you trust the device you are using.',
|
2021-04-08 02:32:12 +02:00
|
|
|
['count' => RememberLoginHash::config()->uninherited('token_expiry_days')]
|
|
|
|
)
|
|
|
|
)
|
2017-05-31 07:48:16 +02:00
|
|
|
);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2017-04-17 05:07:28 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getFormActions()
|
|
|
|
{
|
2016-11-29 00:31:16 +01:00
|
|
|
// Determine returnurl to redirect to parent page
|
|
|
|
$logoutLink = $this->getExternalLink('logout');
|
2017-04-17 05:07:28 +02:00
|
|
|
if ($returnURL = $this->controller->getRequest()->requestVar('BackURL')) {
|
|
|
|
$logoutLink = Controller::join_links($logoutLink, '?BackURL=' . urlencode($returnURL));
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make actions
|
2017-04-30 05:17:26 +02:00
|
|
|
$actions = FieldList::create([
|
2018-01-16 19:39:30 +01:00
|
|
|
FormAction::create('doLogin', _t(__CLASS__ . '.BUTTONLOGIN', "Let me back in"))
|
2017-05-31 07:48:16 +02:00
|
|
|
->addExtraClass('btn-primary'),
|
2016-11-29 00:31:16 +01:00
|
|
|
LiteralField::create(
|
|
|
|
'doLogout',
|
|
|
|
sprintf(
|
2017-05-31 07:48:16 +02:00
|
|
|
'<a class="btn btn-secondary" href="%s" target="_top">%s</a>',
|
|
|
|
Convert::raw2att($logoutLink),
|
2018-01-16 19:39:30 +01:00
|
|
|
_t(__CLASS__ . '.BUTTONLOGOUT', "Log out")
|
2017-05-31 07:48:16 +02:00
|
|
|
)
|
|
|
|
),
|
|
|
|
LiteralField::create(
|
|
|
|
'forgotPassword',
|
|
|
|
sprintf(
|
2017-09-12 05:23:36 +02:00
|
|
|
'<a href="%s" class="cms-security__container__form__forgotPassword btn btn-secondary" target="_top">%s</a>',
|
2017-05-31 07:48:16 +02:00
|
|
|
$this->getExternalLink('lostpassword'),
|
2018-01-16 19:39:30 +01:00
|
|
|
_t(__CLASS__ . '.BUTTONFORGOTPASSWORD', "Forgot password")
|
2016-11-29 00:31:16 +01:00
|
|
|
)
|
|
|
|
)
|
2017-04-30 05:17:26 +02:00
|
|
|
]);
|
2016-11-29 00:31:16 +01:00
|
|
|
|
2017-04-17 05:07:28 +02:00
|
|
|
return $actions;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2017-04-30 05:17:26 +02:00
|
|
|
/**
|
|
|
|
* Get link to use for external security actions
|
|
|
|
*
|
|
|
|
* @param string $action Action
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getExternalLink($action = null)
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-04-30 05:17:26 +02:00
|
|
|
return Security::singleton()->Link($action);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-04-14 05:30:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAuthenticatorName()
|
|
|
|
{
|
2018-01-16 19:39:30 +01:00
|
|
|
return _t(__CLASS__ . '.AUTHENTICATORNAME', 'CMS Member Login Form');
|
2017-04-14 05:30:55 +02:00
|
|
|
}
|
2014-10-06 05:01:33 +02:00
|
|
|
}
|