2017-03-02 03:24:38 +01:00
|
|
|
<?php
|
|
|
|
|
2017-04-22 06:30:10 +02:00
|
|
|
namespace SilverStripe\Security\MemberAuthenticator;
|
2017-03-02 03:24:38 +01:00
|
|
|
|
|
|
|
use SilverStripe\Control\HTTPResponse;
|
|
|
|
use SilverStripe\Core\Convert;
|
2017-04-30 05:17:26 +02:00
|
|
|
use SilverStripe\Security\CMSSecurity;
|
|
|
|
use SilverStripe\Security\Security;
|
2017-03-02 03:24:38 +01:00
|
|
|
|
2017-04-22 06:30:10 +02:00
|
|
|
class CMSLoginHandler extends LoginHandler
|
2017-03-02 03:24:38 +01:00
|
|
|
{
|
2017-04-30 05:17:26 +02:00
|
|
|
private static $allowed_actions = [
|
|
|
|
'LoginForm'
|
|
|
|
];
|
|
|
|
|
2017-03-02 03:24:38 +01:00
|
|
|
/**
|
2017-04-30 05:17:26 +02:00
|
|
|
* Return the CMSMemberLoginForm form
|
2017-03-02 03:24:38 +01:00
|
|
|
*/
|
2017-04-30 05:17:26 +02:00
|
|
|
public function loginForm()
|
2017-03-02 03:24:38 +01:00
|
|
|
{
|
2017-04-30 05:17:26 +02:00
|
|
|
return CMSMemberLoginForm::create(
|
|
|
|
$this,
|
|
|
|
get_class($this->authenticator),
|
|
|
|
'LoginForm'
|
|
|
|
);
|
2017-03-02 03:24:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function redirectBackToForm()
|
|
|
|
{
|
|
|
|
// Redirect back to form
|
|
|
|
$url = $this->addBackURLParam(CMSSecurity::singleton()->Link('login'));
|
|
|
|
return $this->redirect($url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect the user to the change password form.
|
|
|
|
*
|
|
|
|
* @skipUpgrade
|
|
|
|
* @return HTTPResponse
|
|
|
|
*/
|
|
|
|
protected function redirectToChangePassword()
|
|
|
|
{
|
|
|
|
// Since this form is loaded via an iframe, this redirect must be performed via javascript
|
2017-06-15 07:25:23 +02:00
|
|
|
$changePasswordForm = ChangePasswordForm::create($this, 'ChangePasswordForm');
|
2017-03-02 03:24:38 +01:00
|
|
|
$changePasswordForm->sessionMessage(
|
2017-05-08 13:34:39 +02:00
|
|
|
_t('SilverStripe\\Security\\Member.PASSWORDEXPIRED', 'Your password has expired. Please choose a new one.'),
|
2017-03-02 03:24:38 +01:00
|
|
|
'good'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Get redirect url
|
|
|
|
$changePasswordURL = $this->addBackURLParam(Security::singleton()->Link('changepassword'));
|
|
|
|
$changePasswordURLATT = Convert::raw2att($changePasswordURL);
|
|
|
|
$changePasswordURLJS = Convert::raw2js($changePasswordURL);
|
|
|
|
$message = _t(
|
2017-05-08 13:34:39 +02:00
|
|
|
'SilverStripe\\Security\\CMSMemberLoginForm.PASSWORDEXPIRED',
|
2017-03-02 03:24:38 +01:00
|
|
|
'<p>Your password has expired. <a target="_top" href="{link}">Please choose a new one.</a></p>',
|
|
|
|
'Message displayed to user if their session cannot be restored',
|
|
|
|
array('link' => $changePasswordURLATT)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Redirect to change password page
|
|
|
|
$response = HTTPResponse::create()
|
|
|
|
->setBody(<<<PHP
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html><body>
|
|
|
|
$message
|
|
|
|
<script type="application/javascript">
|
|
|
|
setTimeout(function(){top.location.href = "$changePasswordURLJS";}, 0);
|
|
|
|
</script>
|
|
|
|
</body></html>
|
|
|
|
PHP
|
|
|
|
);
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send user to the right location after login
|
|
|
|
*
|
|
|
|
* @return HTTPResponse
|
|
|
|
*/
|
2017-04-30 05:17:26 +02:00
|
|
|
protected function redirectAfterSuccessfulLogin()
|
2017-03-02 03:24:38 +01:00
|
|
|
{
|
|
|
|
// Check password expiry
|
2017-05-20 06:32:25 +02:00
|
|
|
if (Security::getCurrentUser()->isPasswordExpired()) {
|
2017-03-02 03:24:38 +01:00
|
|
|
// Redirect the user to the external password change form if necessary
|
|
|
|
return $this->redirectToChangePassword();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link to success template
|
|
|
|
$url = CMSSecurity::singleton()->Link('success');
|
|
|
|
return $this->redirect($url);
|
|
|
|
}
|
|
|
|
}
|