Allow resetting password through email.

This also adopts the use of an Alert template for error and success messages.
This commit is contained in:
2016-09-02 11:17:10 +02:00
parent 3587447cc0
commit 7487068171
13 changed files with 456 additions and 20 deletions

24
templates/Alert.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
/*****************************************************************************
* Alert.php
* Defines the key template Alert.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class Alert extends SubTemplate
{
public function __construct($title = '', $message = '', $type = 'alert')
{
$this->_title = $title;
$this->_message = $message;
$this->_type = in_array($type, ['alert', 'error', 'success', 'info']) ? $type : 'alert';
}
protected function html_content()
{
echo '
<div class="alert', $this->_type != 'alert' ? ' alert-' . $this->_type : '', '">', (!empty($this->_title) ? '
<strong>' . $this->_title . '</strong><br>' : ''), $this->_message, '</div>';
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*****************************************************************************
* ForgotPasswordForm.php
* Contains the forget password form template.
*
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
*****************************************************************************/
class ForgotPasswordForm extends SubTemplate
{
protected function html_content()
{
echo '
<div class="boxed_content">
<h2>Password reset procedure</h2>';
foreach ($this->_subtemplates as $template)
$template->html_main();
echo '
<p>Please fill in the email address you used to sign up in the form below. You will be sent a reset link to your email address.</p>
<form class="form-horizontal" action="', BASEURL, '/resetpassword/?step=1" method="post">
<label class="control-label" for="field_emailaddress">E-mail address:</label><br>
<input type="text" id="field_emailaddress" name="emailaddress">
<button type="submit" class="btn btn-primary">Send mail</button>
</form>
</div>';
}
}

View File

@@ -8,15 +8,9 @@
class LogInForm extends SubTemplate
{
private $error_message = '';
private $redirect_url = '';
private $emailaddress = '';
public function setErrorMessage($message)
{
$this->error_message = $message;
}
public function setRedirectUrl($url)
{
$_SESSION['login_url'] = $url;
@@ -32,12 +26,10 @@ class LogInForm extends SubTemplate
{
echo '
<form action="', BASEURL, '/login/" method="post" id="login">
<h3>Admin login</h3>';
<h3>Log in</h3>';
// Invalid login? Show a message.
if (!empty($this->error_message))
echo '
<p style="color: red">', $this->error_message, '</p>';
foreach ($this->_subtemplates as $template)
$template->html_main();
echo '
<dl>
@@ -54,7 +46,10 @@ class LogInForm extends SubTemplate
<input type="hidden" name="redirect_url" value="', base64_encode($this->redirect_url), '">';
echo '
<div><button type="submit" class="btn btn-primary" id="field_login" name="login" tabindex="3">Log in</button></div>
<a href="', BASEURL, '/resetpassword/">Forgotten your password?</a>
<div class="buttonstrip">
<button type="submit" class="btn btn-primary" id="field_login" name="login" tabindex="3">Log in</button>
</div>
</form>';
}
}

View File

@@ -0,0 +1,46 @@
<?php
/*****************************************************************************
* PasswordResetForm.php
* Contains the password reset form template.
*
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
*****************************************************************************/
class PasswordResetForm extends SubTemplate
{
private $email;
private $key;
public function __construct($email, $key)
{
$this->email = $email;
$this->key = $key;
}
protected function html_content()
{
echo '
<div class="boxed_content">
<h2>Password reset procedure</h2>';
foreach ($this->_subtemplates as $template)
$template->html_main();
echo '
<p>You have successfully confirmed your identify. Please use the form below to set a new password.</p>
<form class="form-horizontal" action="', BASEURL, '/resetpassword/?step=2&amp;email=', rawurlencode($this->email), '&amp;key=', $this->key, '" method="post">
<p>
<label class="control-label" for="field_password1">New password:</label>
<input type="password" id="field_password1" name="password1">
</p>
<p>
<label class="control-label" for="field_password2">Repeat new password:</label>
<input type="password" id="field_password2" name="password2">
</p>
<button type="submit" class="btn btn-primary">Reset password</button>
</form>
</div>';
}
}