CC-3416 : Create password reset form
This commit is contained in:
parent
2c4df4853a
commit
102bcb1d46
|
@ -144,7 +144,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
|||
'password-change',
|
||||
new Zend_Controller_Router_Route('password-change/:user_id/:token', array(
|
||||
'module' => 'default',
|
||||
'controller' => 'auth',
|
||||
'controller' => 'login',
|
||||
'action' => 'password-change',
|
||||
)));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ $ccAcl->add(new Zend_Acl_Resource('library'))
|
|||
->add(new Zend_Acl_Resource('dashboard'))
|
||||
->add(new Zend_Acl_Resource('preference'))
|
||||
->add(new Zend_Acl_Resource('showbuilder'))
|
||||
->add(new Zend_Acl_Resource('auth'))
|
||||
->add(new Zend_Acl_Resource('playouthistory'))
|
||||
->add(new Zend_Acl_Resource('usersettings'))
|
||||
->add(new Zend_Acl_Resource('audiopreview'));
|
||||
|
@ -33,7 +32,6 @@ $ccAcl->allow('G', 'index')
|
|||
->allow('G', 'error')
|
||||
->allow('G', 'showbuilder')
|
||||
->allow('G', 'api')
|
||||
->allow('G', 'auth')
|
||||
->allow('G', 'schedule')
|
||||
->allow('G', 'dashboard')
|
||||
->allow('H', 'usersettings')
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
|
||||
class AuthController extends Zend_Controller_Action
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function passwordRestoreAction()
|
||||
{
|
||||
//uses separate layout without a navigation.
|
||||
$this->_helper->layout->setLayout('bare');
|
||||
|
||||
$form = new Application_Form_PasswordRestore();
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request->isPost() && $form->isValid($request->getPost())) {
|
||||
$user = CcSubjsQuery::create()
|
||||
->filterByDbEmail($form->email->getValue())
|
||||
->findOne();
|
||||
|
||||
if (!empty($user)) {
|
||||
$auth = new Application_Model_Auth();
|
||||
|
||||
$auth->sendPasswordRestoreLink($user, $this->view);
|
||||
$this->_helper->redirector('password-restore-after', 'auth');
|
||||
}
|
||||
else {
|
||||
$form->email->addError($this->view->translate("Given email not found."));
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function passwordRestoreAfterAction()
|
||||
{
|
||||
//uses separate layout without a navigation.
|
||||
$this->_helper->layout->setLayout('bare');
|
||||
}
|
||||
|
||||
public function passwordChangeAction()
|
||||
{
|
||||
//uses separate layout without a navigation.
|
||||
$this->_helper->layout->setLayout('bare');
|
||||
|
||||
$request = $this->getRequest();
|
||||
$token = $request->getParam("token", false);
|
||||
$user_id = $request->getParam("user_id", 0);
|
||||
|
||||
$form = new Application_Form_PasswordChange();
|
||||
$auth = new Application_Model_Auth();
|
||||
$user = CcSubjsQuery::create()->findPK($user_id);
|
||||
|
||||
//check validity of token
|
||||
if (!$auth->checkToken($user_id, $token, 'password.restore')) {
|
||||
echo "token not valid";
|
||||
$this->_helper->redirector('index', 'login');
|
||||
}
|
||||
|
||||
if ($request->isPost() && $form->isValid($request->getPost())) {
|
||||
|
||||
$user->setDbPass(md5($form->password->getValue()));
|
||||
$user->save();
|
||||
|
||||
$auth->invalidateTokens($user, 'password.restore');
|
||||
|
||||
$zend_auth = Zend_Auth::getInstance();
|
||||
$zend_auth->clearIdentity();
|
||||
|
||||
$authAdapter = Application_Model_Auth::getAuthAdapter();
|
||||
$authAdapter->setIdentity($user->getDbLogin())
|
||||
->setCredential($form->password->getValue());
|
||||
|
||||
$result = $zend_auth->authenticate($authAdapter);
|
||||
|
||||
//all info about this user from the login table omit only the password
|
||||
$userInfo = $authAdapter->getResultRowObject(null, 'password');
|
||||
|
||||
//the default storage is a session with namespace Zend_Auth
|
||||
$authStorage = $zend_auth->getStorage();
|
||||
$authStorage->write($userInfo);
|
||||
|
||||
$this->_helper->redirector('index', 'showbuilder');
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
|
@ -12,9 +12,9 @@ class LoginController extends Zend_Controller_Action
|
|||
{
|
||||
global $CC_CONFIG;
|
||||
|
||||
if(Zend_Auth::getInstance()->hasIdentity())
|
||||
if (Zend_Auth::getInstance()->hasIdentity())
|
||||
{
|
||||
$this->_redirect('Nowplaying');
|
||||
$this->_redirect('Showbuilder');
|
||||
}
|
||||
|
||||
//uses separate layout without a navigation.
|
||||
|
@ -97,6 +97,87 @@ class LoginController extends Zend_Controller_Action
|
|||
Zend_Auth::getInstance()->clearIdentity();
|
||||
$this->_redirect('showbuilder/index');
|
||||
}
|
||||
|
||||
public function passwordRestoreAction()
|
||||
{
|
||||
//uses separate layout without a navigation.
|
||||
$this->_helper->layout->setLayout('login');
|
||||
|
||||
$form = new Application_Form_PasswordRestore();
|
||||
|
||||
$request = $this->getRequest();
|
||||
if ($request->isPost() && $form->isValid($request->getPost())) {
|
||||
$user = CcSubjsQuery::create()
|
||||
->filterByDbEmail($form->email->getValue())
|
||||
->findOne();
|
||||
|
||||
if (!empty($user)) {
|
||||
$auth = new Application_Model_Auth();
|
||||
|
||||
$auth->sendPasswordRestoreLink($user, $this->view);
|
||||
$this->_helper->redirector('password-restore-after', 'auth');
|
||||
}
|
||||
else {
|
||||
$form->email->addError($this->view->translate("Given email not found."));
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function passwordRestoreAfterAction()
|
||||
{
|
||||
//uses separate layout without a navigation.
|
||||
$this->_helper->layout->setLayout('login');
|
||||
}
|
||||
|
||||
public function passwordChangeAction()
|
||||
{
|
||||
//uses separate layout without a navigation.
|
||||
$this->_helper->layout->setLayout('login');
|
||||
|
||||
$request = $this->getRequest();
|
||||
$token = $request->getParam("token", false);
|
||||
$user_id = $request->getParam("user_id", 0);
|
||||
|
||||
$form = new Application_Form_PasswordChange();
|
||||
$auth = new Application_Model_Auth();
|
||||
$user = CcSubjsQuery::create()->findPK($user_id);
|
||||
|
||||
//check validity of token
|
||||
if (!$auth->checkToken($user_id, $token, 'password.restore')) {
|
||||
echo "token not valid";
|
||||
$this->_helper->redirector('index', 'login');
|
||||
}
|
||||
|
||||
if ($request->isPost() && $form->isValid($request->getPost())) {
|
||||
|
||||
$user->setDbPass(md5($form->password->getValue()));
|
||||
$user->save();
|
||||
|
||||
$auth->invalidateTokens($user, 'password.restore');
|
||||
|
||||
$zend_auth = Zend_Auth::getInstance();
|
||||
$zend_auth->clearIdentity();
|
||||
|
||||
$authAdapter = Application_Model_Auth::getAuthAdapter();
|
||||
$authAdapter->setIdentity($user->getDbLogin())
|
||||
->setCredential($form->password->getValue());
|
||||
|
||||
$result = $zend_auth->authenticate($authAdapter);
|
||||
|
||||
//all info about this user from the login table omit only the password
|
||||
$userInfo = $authAdapter->getResultRowObject(null, 'password');
|
||||
|
||||
//the default storage is a session with namespace Zend_Auth
|
||||
$authStorage = $zend_auth->getStorage();
|
||||
$authStorage->write($userInfo);
|
||||
|
||||
$this->_helper->redirector('index', 'showbuilder');
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,10 @@ class Application_Form_Login extends Zend_Form
|
|||
|
||||
// Set the method for the display form to POST
|
||||
$this->setMethod('post');
|
||||
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/login.phtml'))
|
||||
));
|
||||
|
||||
// Add username element
|
||||
$this->addElement('text', 'username', array(
|
||||
|
@ -19,9 +23,12 @@ class Application_Form_Login extends Zend_Form
|
|||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// Add password element
|
||||
$this->addElement('password', 'password', array(
|
||||
'label' => 'Password:',
|
||||
|
@ -31,6 +38,9 @@ class Application_Form_Login extends Zend_Form
|
|||
'filters' => array('StringTrim'),
|
||||
'validators' => array(
|
||||
'NotEmpty',
|
||||
),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
|
@ -47,7 +57,10 @@ class Application_Form_Login extends Zend_Form
|
|||
$this->addElement('submit', 'submit', array(
|
||||
'ignore' => true,
|
||||
'label' => 'Login',
|
||||
'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center'
|
||||
'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,10 @@ class Application_Form_PasswordChange extends Zend_Form
|
|||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/password-change.phtml'))
|
||||
));
|
||||
|
||||
$this->addElement('password', 'password', array(
|
||||
'label' => 'Password',
|
||||
'required' => true,
|
||||
|
@ -13,10 +17,13 @@ class Application_Form_PasswordChange extends Zend_Form
|
|||
'validators' => array(
|
||||
array('stringLength', false, array(6, 80)),
|
||||
),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('password', 'password_confirm', array(
|
||||
'label' => 'Password Confirmation',
|
||||
'label' => 'Confirm new password',
|
||||
'required' => true,
|
||||
'filters' => array('stringTrim'),
|
||||
'validators' => array(
|
||||
|
@ -25,11 +32,18 @@ class Application_Form_PasswordChange extends Zend_Form
|
|||
}),
|
||||
),
|
||||
'errorMessages' => array("Password confirmation does not match your password."),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('submit', 'submit', array(
|
||||
'label' => 'Set password',
|
||||
'label' => 'Get new password',
|
||||
'ignore' => true,
|
||||
'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,18 +6,28 @@ class Application_Form_PasswordRestore extends Zend_Form
|
|||
{
|
||||
public function init()
|
||||
{
|
||||
$this->setDecorators(array(
|
||||
array('ViewScript', array('viewScript' => 'form/password-restore.phtml'))
|
||||
));
|
||||
|
||||
$this->addElement('text', 'email', array(
|
||||
'label' => 'E-mail',
|
||||
'required' => true,
|
||||
'filters' => array(
|
||||
'stringTrim',
|
||||
),
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
|
||||
$this->addElement('submit', 'submit', array(
|
||||
'label' => 'Restore password',
|
||||
'ignore' => true,
|
||||
'class' => 'ui-button ui-state-default'
|
||||
'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center',
|
||||
'decorators' => array(
|
||||
'ViewHelper'
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
|
@ -9,7 +9,13 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
<div id="login-page"><?php echo $this->layout()->content ?></div>
|
||||
<div id="login-page">
|
||||
<?php echo $this->layout()->content ?>
|
||||
</div>
|
||||
<div class="footer">
|
||||
Airtime <?php echo $this->airtimeVersion ?> Copyright © Sourcefabric o.p.s <?php echo $this->airtimeCopyright ?>. All rights reserved.<br/>
|
||||
Maintained and distributed under GNU GPL v.3 by <a href="http://www.sourcefabric.org"> Sourcefabric o.p.s </a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
<div><?php echo $this->form ?></div>
|
|
@ -1 +0,0 @@
|
|||
<div>Email sent</div>
|
|
@ -1 +0,0 @@
|
|||
<div><?php echo $this->form ?></div>
|
|
@ -0,0 +1,33 @@
|
|||
<form enctype="application/x-www-form-urlencoded" method="post" action="">
|
||||
<dl class="zend_form">
|
||||
|
||||
<dt id="username-label">
|
||||
<label for="username" class="required">
|
||||
<?php echo $this->element->getElement('username')->getLabel() ?>
|
||||
</label>
|
||||
</dt>
|
||||
<dd id="username-element">
|
||||
<?php echo $this->element->getElement('username') ?>
|
||||
</dd>
|
||||
|
||||
<dt id="password-label">
|
||||
<label for="password" class="required">
|
||||
<?php echo $this->element->getElement('password')->getLabel() ?>
|
||||
</label>
|
||||
</dt>
|
||||
<dd id="password-element">
|
||||
<?php echo $this->element->getElement('password') ?>
|
||||
</dd>
|
||||
|
||||
<dt id="reset-label" class="hidden"> </dt>
|
||||
<dd id="reset-element" class="text-right">
|
||||
<a href="<?php echo $this->baseUrl('login/password-restore'); ?>" class="link reset">Reset password</a>
|
||||
</dd>
|
||||
|
||||
<dt id="submit-label"> </dt>
|
||||
<dd id="submit-element">
|
||||
<?php echo $this->element->getElement('submit') ?>
|
||||
</dd>
|
||||
|
||||
</dl>
|
||||
</form>
|
|
@ -0,0 +1,25 @@
|
|||
<form enctype="application/x-www-form-urlencoded" method="post" action="">
|
||||
<dl class="zend_form">
|
||||
<dt id="new-password-label">
|
||||
<label for="new-password" class="required">
|
||||
<?php echo $this->element->getElement('password')->getLabel() ?>
|
||||
</label>
|
||||
</dt>
|
||||
<dd id="new-password-element">
|
||||
<?php echo $this->element->getElement('password') ?>
|
||||
</dd>
|
||||
<dt id="confirm-password-label">
|
||||
<label for="confirm-password" class="required">
|
||||
<?php echo $this->element->getElement('password_confirm')->getLabel() ?>
|
||||
</label>
|
||||
</dt>
|
||||
<dd id="confirm-password-element">
|
||||
<?php echo $this->element->getElement('password_confirm') ?>
|
||||
</dd>
|
||||
|
||||
<dt id="submit-label"> </dt>
|
||||
<dd id="submit-element">
|
||||
<?php echo $this->element->getElement('submit') ?>
|
||||
</dd>
|
||||
</dl>
|
||||
</form>
|
|
@ -0,0 +1,18 @@
|
|||
<form enctype="application/x-www-form-urlencoded" method="post" action="">
|
||||
<dl class="zend_form">
|
||||
<dt id="username-label">
|
||||
<label for="username" class="required">
|
||||
<?php echo $this->element->getElement('email')->getLabel() ?>
|
||||
</label>
|
||||
</dt>
|
||||
<dd id="username-element">
|
||||
<?php echo $this->element->getElement('email') ?>
|
||||
</dd>
|
||||
|
||||
|
||||
<dt id="submit-label"> </dt>
|
||||
<dd id="submit-element">
|
||||
<?php echo $this->element->getElement('submit') ?>
|
||||
</dd>
|
||||
</dl>
|
||||
</form>
|
|
@ -9,5 +9,3 @@
|
|||
<?php echo $this->form; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer"> Airtime <?php echo $this->airtimeVersion ?> Copyright © Sourcefabric o.p.s <?php echo $this->airtimeCopyright ?>. All rights reserved.<br/>
|
||||
Maintained and distributed under GNU GPL v.3 by <a href="http://www.sourcefabric.org"> Sourcefabric o.p.s </a> </div>
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<div class="login_box">
|
||||
<div class="logobox"> </div>
|
||||
<h2>New password</h2>
|
||||
|
||||
<div id="login" class="login-content clearfix">
|
||||
<p class="light">Please enter and confirm your new password in the fields below.</p>
|
||||
<?php echo $this->form; ?>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,8 @@
|
|||
<div class="login_box">
|
||||
<div class="logobox"> </div>
|
||||
<h2>Email sent</h2>
|
||||
|
||||
<div id="login" class="login-content clearfix">
|
||||
<p class="light">An email has been sent to <?php $this->form->email->getValue() ?></p>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,9 @@
|
|||
<div class="login_box">
|
||||
<div class="logobox"> </div>
|
||||
<h2>Reset password</h2>
|
||||
|
||||
<div id="login" class="login-content clearfix">
|
||||
<p class="light">Please enter your account e-mail address. You will recieve a link to create a new password via e-mail.</p>
|
||||
<?php echo $this->form; ?>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue