2014-10-06 05:01:33 +02:00
|
|
|
<?php
|
|
|
|
|
2016-06-23 01:37:22 +02:00
|
|
|
namespace SilverStripe\Security;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
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;
|
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
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
class CMSMemberLoginForm extends LoginForm
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get link to use for external security actions
|
|
|
|
*
|
|
|
|
* @param string $action Action
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getExternalLink($action = null)
|
|
|
|
{
|
2017-03-02 03:24:38 +01:00
|
|
|
return Security::singleton()->Link($action);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2017-04-17 05:07:28 +02:00
|
|
|
/**
|
|
|
|
* CMSMemberLoginForm constructor.
|
|
|
|
* @param Controller $controller
|
|
|
|
* @param string $authenticatorClass
|
|
|
|
* @param FieldList $name
|
|
|
|
*/
|
|
|
|
public function __construct(Controller $controller, $authenticatorClass, $name)
|
|
|
|
{
|
|
|
|
$this->controller = $controller;
|
|
|
|
|
|
|
|
$this->authenticator_class = $authenticatorClass;
|
|
|
|
|
|
|
|
$fields = $this->getFormFields();
|
|
|
|
|
|
|
|
$actions = $this->getFormActions();
|
|
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getFormFields()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
|
|
|
// Set default fields
|
|
|
|
$fields = new FieldList(
|
|
|
|
HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this),
|
2017-04-17 05:07:28 +02:00
|
|
|
HiddenField::create('tempid', null, $this->controller->getRequest()->requestVar('tempid')),
|
2016-11-29 00:31:16 +01:00
|
|
|
PasswordField::create("Password", _t('Member.PASSWORD', 'Password')),
|
|
|
|
LiteralField::create(
|
|
|
|
'forgotPassword',
|
|
|
|
sprintf(
|
|
|
|
'<p id="ForgotPassword"><a href="%s" target="_top">%s</a></p>',
|
|
|
|
$this->getExternalLink('lostpassword'),
|
|
|
|
_t('CMSMemberLoginForm.BUTTONFORGOTPASSWORD', "Forgot password?")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (Security::config()->autologin_enabled) {
|
|
|
|
$fields->push(CheckboxField::create(
|
|
|
|
"Remember",
|
|
|
|
_t('Member.REMEMBERME', "Remember me next time?")
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
$actions = new FieldList(
|
|
|
|
FormAction::create('dologin', _t('CMSMemberLoginForm.BUTTONLOGIN', "Log back in")),
|
|
|
|
LiteralField::create(
|
|
|
|
'doLogout',
|
|
|
|
sprintf(
|
|
|
|
'<p id="doLogout"><a href="%s" target="_top">%s</a></p>',
|
|
|
|
$logoutLink,
|
|
|
|
_t('CMSMemberLoginForm.BUTTONLOGOUT', "Log out")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2017-04-17 05:07:28 +02:00
|
|
|
return $actions;
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
|
|
|
|
2017-03-02 03:24:38 +01:00
|
|
|
protected function buildRequestHandler()
|
2016-11-29 00:31:16 +01:00
|
|
|
{
|
2017-03-02 03:24:38 +01:00
|
|
|
return CMSMemberLoginHandler::create($this);
|
2016-11-29 00:31:16 +01:00
|
|
|
}
|
2017-04-14 05:30:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAuthenticatorName()
|
|
|
|
{
|
|
|
|
return _t('CMSMemberLoginForm.AUTHENTICATORNAME', 'CMS Member Login Form');
|
|
|
|
}
|
2014-10-06 05:01:33 +02:00
|
|
|
}
|