From cea124cfaa7a80cb008a5101ea772c003ec4dffd Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Thu, 4 Dec 2014 13:24:46 +0000 Subject: [PATCH] Login, forgot password and password reset. --- PHPCI/Controller/SessionController.php | 30 +++++++---------------- PHPCI/Helper/Lang.php | 1 - PHPCI/Languages/lang.en-gb.php | 32 +++++++++++++++++++++++++ PHPCI/View/Session.phtml | 3 ++- PHPCI/View/Session/forgotPassword.phtml | 9 +++---- PHPCI/View/Session/login.phtml | 7 ++++-- PHPCI/View/Session/resetPassword.phtml | 10 ++++---- PHPCI/View/layout.phtml | 4 +--- 8 files changed, 58 insertions(+), 38 deletions(-) diff --git a/PHPCI/Controller/SessionController.php b/PHPCI/Controller/SessionController.php index f7bfa982..e9305fad 100644 --- a/PHPCI/Controller/SessionController.php +++ b/PHPCI/Controller/SessionController.php @@ -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 = <<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(); } diff --git a/PHPCI/Helper/Lang.php b/PHPCI/Helper/Lang.php index 37e17e6f..f96109c2 100644 --- a/PHPCI/Helper/Lang.php +++ b/PHPCI/Helper/Lang.php @@ -10,7 +10,6 @@ namespace PHPCI\Helper; use b8\Config; -use PHPCI\Model\User; class Lang { diff --git a/PHPCI/Languages/lang.en-gb.php b/PHPCI/Languages/lang.en-gb.php index 3d96e19a..16059451 100644 --- a/PHPCI/Languages/lang.en-gb.php +++ b/PHPCI/Languages/lang.en-gb.php @@ -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' => 'Don\'t worry!
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', diff --git a/PHPCI/View/Session.phtml b/PHPCI/View/Session.phtml index ff84d46d..51bab094 100644 --- a/PHPCI/View/Session.phtml +++ b/PHPCI/View/Session.phtml @@ -1,7 +1,8 @@ + - Log in to PHPCI + <?php Lang::out('log_in_to_phpci'); ?> diff --git a/PHPCI/View/Session/forgotPassword.phtml b/PHPCI/View/Session/forgotPassword.phtml index 24875f05..43ff20d6 100644 --- a/PHPCI/View/Session/forgotPassword.phtml +++ b/PHPCI/View/Session/forgotPassword.phtml @@ -1,12 +1,13 @@ +

- We've emailed you a link to reset your password. +

- Don't worry!
Just enter your email address below and we'll email you a link to reset your password. +
@@ -18,12 +19,12 @@
- +
- +
diff --git a/PHPCI/View/Session/login.phtml b/PHPCI/View/Session/login.phtml index bc2f16e1..842c4c20 100644 --- a/PHPCI/View/Session/login.phtml +++ b/PHPCI/View/Session/login.phtml @@ -1,6 +1,9 @@ + -

Incorrect email address or password

+

-Forgotten your password? \ No newline at end of file + + + \ No newline at end of file diff --git a/PHPCI/View/Session/resetPassword.phtml b/PHPCI/View/Session/resetPassword.phtml index 51dc3444..71e81ab1 100644 --- a/PHPCI/View/Session/resetPassword.phtml +++ b/PHPCI/View/Session/resetPassword.phtml @@ -1,19 +1,19 @@ - - + +
- Please enter a new password +
- +
- +
diff --git a/PHPCI/View/layout.phtml b/PHPCI/View/layout.phtml index 4728468d..c21df90c 100644 --- a/PHPCI/View/layout.phtml +++ b/PHPCI/View/layout.phtml @@ -1,6 +1,4 @@ - +