Login, forgot password and password reset.

This commit is contained in:
Dan Cryer 2014-12-04 13:24:46 +00:00
parent 4a03e01c3f
commit cea124cfaa
8 changed files with 58 additions and 38 deletions

View file

@ -11,6 +11,7 @@ namespace PHPCI\Controller;
use b8;
use PHPCI\Helper\Email;
use PHPCI\Helper\Lang;
/**
* Session Controller - Handles user login / logout.
@ -55,21 +56,21 @@ class SessionController extends \PHPCI\Controller
$form->setAction(PHPCI_URL.'session/login');
$email = new b8\Form\Element\Email('email');
$email->setLabel('Email Address');
$email->setLabel(Lang::get('email_address'));
$email->setRequired(true);
$email->setContainerClass('form-group');
$email->setClass('form-control');
$form->addField($email);
$pwd = new b8\Form\Element\Password('password');
$pwd->setLabel('Password');
$pwd->setLabel(Lang::get('password'));
$pwd->setRequired(true);
$pwd->setContainerClass('form-group');
$pwd->setClass('form-control');
$form->addField($pwd);
$pwd = new b8\Form\Element\Submit();
$pwd->setValue('Log in »');
$pwd->setValue(Lang::get('log_in'));
$pwd->setClass('btn-success');
$form->addField($pwd);
@ -99,33 +100,18 @@ class SessionController extends \PHPCI\Controller
$user = $this->userStore->getByEmail($email);
if (empty($user)) {
$this->view->error = 'No user exists with that email address, please try again.';
$this->view->error = Lang::get('reset_no_user_exists');
return $this->view->render();
}
$key = md5(date('Y-m-d') . $user->getHash());
$url = PHPCI_URL;
$name = $user->getName();
$userId = $user->getId();
$message = <<<MSG
Hi {$name},
You have received this email because you, or someone else, has requested a password reset for PHPCI.
If this was you, please click the following link to reset your password: {$url}session/reset-password/{$userId}/{$key}
Otherwise, please ignore this email and no action will be taken.
Thank you,
PHPCI
MSG;
$message = Lang::get('reset_email_body', $user->getName(), $url, $user->getId(), $key);
$email = new Email();
$email->setEmailTo($user->getEmail(), $user->getName());
$email->setSubject('Password reset');
$email->setSubject(Lang::get('reset_email_title', $user->getName()));
$email->setBody($message);
$email->send();
@ -141,7 +127,7 @@ MSG;
$userKey = md5(date('Y-m-d') . $user->getHash());
if (empty($user) || $key != $userKey) {
$this->view->error = 'Invalid password reset request.';
$this->view->error = Lang::get('reset_invalid');
return $this->view->render();
}

View file

@ -10,7 +10,6 @@
namespace PHPCI\Helper;
use b8\Config;
use PHPCI\Model\User;
class Lang
{

View file

@ -8,6 +8,38 @@
*/
$strings = array(
// Log in:
'log_in_to_phpci' => 'Log in to PHPCI',
'login_error' => 'Incorrect email address or password',
'forgotten_password_link' => 'Forgotten your password?',
'reset_emailed' => 'We\'ve emailed you a link to reset your password.',
'reset_header' => '<strong>Don\'t worry!</strong><br>Just enter your email address below and we\'ll email
you a link to reset your password.',
'reset_email_address' => 'Enter your email address:',
'reset_send_email' => 'Email password reset',
'reset_enter_password' => 'Please enter a new password',
'reset_new_password' => 'New password:',
'reset_change_password' => 'Change password',
'reset_no_user_exists' => 'No user exists with that email address, please try again.',
'reset_email_body' => 'Hi %s,
You have received this email because you, or someone else, has requested a password reset for PHPCI.
If this was you, please click the following link to reset your password: %ssession/reset-password/%d/%s
Otherwise, please ignore this email and no action will be taken.
Thank you,
PHPCI',
'reset_email_title' => 'PHPCI Password Reset for %s',
'reset_invalid' => 'Invalid password reset request.',
'email_address' => 'Email Address',
'password' => 'Password',
'log_in' => 'Log in',
// Top Nav
'toggle_navigation' => 'Toggle Navigation',
'n_builds_pending' => '%d builds pending',

View file

@ -1,7 +1,8 @@
<?php use PHPCI\Helper\Lang; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Log in to PHPCI</title>
<title><?php Lang::out('log_in_to_phpci'); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

View file

@ -1,12 +1,13 @@
<?php use PHPCI\Helper\Lang; ?>
<?php if (isset($emailed)): ?>
<p class="alert alert-success" style="margin-bottom: 0">
We've emailed you a link to reset your password.
<?php Lang::out('reset_emailed'); ?>
</p>
<?php else: ?>
<?php if (empty($error)): ?>
<div class="panel panel-success" style="margin-bottom: 0">
<div class="box-header">
<strong>Don't worry!</strong><br>Just enter your email address below and we'll email you a link to reset your password.
<?php Lang::out('reset_header'); ?>
</div>
<?php else: ?>
<div class="panel panel-danger" style="margin-bottom: 0">
@ -18,12 +19,12 @@
<div class="box-body">
<form class="form" action="<?php print PHPCI_URL; ?>session/forgot-password" method="POST">
<div class="form-group">
<label for="email">Enter your email address:</label>
<label for="email"><?php Lang::out('reset_email_address'); ?></label>
<input id="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<input class="btn btn-success" type="submit" value="Email password reset">
<input class="btn btn-success" type="submit" value="<?php Lang::out('reset_send_email'); ?>">
</div>
</form>
</div>

View file

@ -1,6 +1,9 @@
<?php use PHPCI\Helper\Lang; ?>
<?php if($failed): ?>
<p class="alert alert-danger">Incorrect email address or password</p>
<p class="alert alert-danger"><?php Lang::out('login_error'); ?></p>
<?php endif; ?>
<?php print $form; ?>
<a style="margin-top: -22px; font-size: 0.85em; color: #246" class="pull-right" href="<?php print PHPCI_URL; ?>session/forgot-password">Forgotten your password?</a>
<a style="margin-top: -22px; font-size: 0.85em; color: #246" class="pull-right" href="<?php print PHPCI_URL; ?>session/forgot-password">
<?php Lang::out('forgotten_password_link'); ?>
</a>

View file

@ -1,19 +1,19 @@
<?php if (empty($error)): ?>
<?php use PHPCI\Helper\Lang; ?>
<?php if (empty($error)): ?>
<div class="panel panel-success" style="margin-bottom: 0">
<div class="box-header">
Please enter a new password
<?php Lang::out('reset_enter_password'); ?>
</div>
<div class="box-body">
<form class="form" action="<?php print PHPCI_URL; ?>session/reset-password/<?php print $id; ?>/<?php print $key; ?>" method="POST">
<div class="form-group">
<label for="password">New password:</label>
<label for="password"><?php Lang::out('reset_new_password'); ?></label>
<input type="password" id="password" name="password" class="form-control" required>
</div>
<div class="form-group">
<input class="btn btn-success" type="submit" value="Change password">
<input class="btn btn-success" type="submit" value="<?php Lang::out('reset_change_password'); ?>">
</div>
</form>
</div>

View file

@ -1,6 +1,4 @@
<?php
use PHPCI\Helper\Lang;
?>
<?php use PHPCI\Helper\Lang; ?>
<!DOCTYPE html>
<html>
<head>