Add forgot password feature
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
|
||||
/**
|
||||
* Authentication controller
|
||||
*
|
||||
@@ -61,21 +59,6 @@ class Auth extends Base
|
||||
$this->response->redirect($this->helper->url->to('auth', 'login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display captcha image
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function captcha()
|
||||
{
|
||||
$this->response->contentType('image/jpeg');
|
||||
|
||||
$builder = new CaptchaBuilder;
|
||||
$builder->build();
|
||||
$this->sessionStorage->captcha = $builder->getPhrase();
|
||||
$builder->output();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the user after the authentication
|
||||
*
|
||||
|
||||
29
app/Controller/Captcha.php
Normal file
29
app/Controller/Captcha.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
use Gregwar\Captcha\CaptchaBuilder;
|
||||
|
||||
/**
|
||||
* Captcha Controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Captcha extends Base
|
||||
{
|
||||
/**
|
||||
* Display captcha image
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
$this->response->contentType('image/jpeg');
|
||||
|
||||
$builder = new CaptchaBuilder;
|
||||
$builder->build();
|
||||
$this->sessionStorage->captcha = $builder->getPhrase();
|
||||
$builder->output();
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,9 @@ class Config extends Base
|
||||
$values = $this->request->getValues();
|
||||
|
||||
switch ($redirect) {
|
||||
case 'application':
|
||||
$values += array('password_reset' => 0);
|
||||
break;
|
||||
case 'project':
|
||||
$values += array('subtask_restriction' => 0, 'subtask_time_tracking' => 0, 'cfd_include_closed_tasks' => 0);
|
||||
break;
|
||||
|
||||
120
app/Controller/PasswordReset.php
Normal file
120
app/Controller/PasswordReset.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
/**
|
||||
* Password Reset Controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class PasswordReset extends Base
|
||||
{
|
||||
/**
|
||||
* Show the form to reset the password
|
||||
*/
|
||||
public function create(array $values = array(), array $errors = array())
|
||||
{
|
||||
$this->checkActivation();
|
||||
|
||||
$this->response->html($this->template->layout('password_reset/create', array(
|
||||
'errors' => $errors,
|
||||
'values' => $values,
|
||||
'no_layout' => true,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate and send the email
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->checkActivation();
|
||||
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->passwordResetValidator->validateCreation($values);
|
||||
|
||||
if ($valid) {
|
||||
$this->sendEmail($values['username']);
|
||||
$this->response->redirect($this->helper->url->to('auth', 'login'));
|
||||
}
|
||||
|
||||
$this->create($values, $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form to set a new password
|
||||
*/
|
||||
public function change(array $values = array(), array $errors = array())
|
||||
{
|
||||
$this->checkActivation();
|
||||
|
||||
$token = $this->request->getStringParam('token');
|
||||
$user_id = $this->passwordReset->getUserIdByToken($token);
|
||||
|
||||
if ($user_id !== false) {
|
||||
$this->response->html($this->template->layout('password_reset/change', array(
|
||||
'token' => $token,
|
||||
'errors' => $errors,
|
||||
'values' => $values,
|
||||
'no_layout' => true,
|
||||
)));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('auth', 'login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the new password
|
||||
*/
|
||||
public function update(array $values = array(), array $errors = array())
|
||||
{
|
||||
$this->checkActivation();
|
||||
|
||||
$token = $this->request->getStringParam('token');
|
||||
$values = $this->request->getValues();
|
||||
list($valid, $errors) = $this->passwordResetValidator->validateModification($values);
|
||||
|
||||
if ($valid) {
|
||||
$user_id = $this->passwordReset->getUserIdByToken($token);
|
||||
|
||||
if ($user_id !== false) {
|
||||
$this->user->update(array('id' => $user_id, 'password' => $values['password']));
|
||||
$this->passwordReset->disable($user_id);
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('auth', 'login'));
|
||||
}
|
||||
|
||||
$this->change($values, $errors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the email
|
||||
*/
|
||||
private function sendEmail($username)
|
||||
{
|
||||
$token = $this->passwordReset->create($username);
|
||||
|
||||
if ($token !== false) {
|
||||
$user = $this->user->getByUsername($username);
|
||||
|
||||
$this->emailClient->send(
|
||||
$user['email'],
|
||||
$user['name'] ?: $user['username'],
|
||||
t('Password Reset for Kanboard'),
|
||||
$this->template->render('password_reset/email', array('token' => $token))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check feature availability
|
||||
*/
|
||||
private function checkActivation()
|
||||
{
|
||||
if ($this->config->get('password_reset', 0) == 0) {
|
||||
$this->response->redirect($this->helper->url->to('auth', 'login'));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,6 +172,20 @@ class User extends Base
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display last password reset
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function passwordReset()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$this->response->html($this->layout('user/password_reset', array(
|
||||
'tokens' => $this->passwordReset->getAll($user['id']),
|
||||
'user' => $user,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display last connections
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user