-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add password edit page on admin side
- Loading branch information
Showing
7 changed files
with
262 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,16 @@ | |
use Module\User\Form\CompoundForm; | ||
use Module\User\Form\EditUserFilter; | ||
use Module\User\Form\EditUserForm; | ||
use Module\User\Form\EditPasswordFilter; | ||
use Module\User\Form\EditPasswordForm; | ||
use Pi; | ||
use Pi\Mvc\Controller\ActionController; | ||
|
||
/** | ||
* Edit user controller | ||
* | ||
* @author Liu Chuang <[email protected]> | ||
* @author Hossein Azizabadi <[email protected]> | ||
*/ | ||
class EditController extends ActionController | ||
{ | ||
|
@@ -31,7 +34,7 @@ public function indexAction() | |
$user = $this->getUser($uid); | ||
|
||
// Get available edit fields | ||
list($fields, $formFields, $formFilters) = $this->getEditField(); | ||
[$fields, $formFields, $formFilters] = $this->getEditField(); | ||
|
||
// Add other elements | ||
$formFields[] = [ | ||
|
@@ -61,11 +64,7 @@ public function indexAction() | |
// Update user | ||
$values = $form->getData(); | ||
$values['last_modified'] = time(); | ||
if (isset($values['credential']) | ||
&& !$values['credential'] | ||
) { | ||
unset($values['credential']); | ||
} | ||
unset($values['credential']); | ||
unset($values['id']); | ||
|
||
// Check if email is empty | ||
|
@@ -158,6 +157,68 @@ public function avatarAction() | |
$this->view()->setTemplate('edit-user'); | ||
} | ||
|
||
/** | ||
* Display user avatar and delete | ||
*/ | ||
public function passwordAction() | ||
{ | ||
$uid = _get('uid'); | ||
|
||
// Get user basic information and user data | ||
$user = $this->getUser($uid); | ||
|
||
// Set option | ||
$option = []; | ||
|
||
// Set form | ||
$form = new EditPasswordForm('password', $option); | ||
if ($this->request->isPost()) { | ||
|
||
// Set result | ||
$result = [ | ||
'status' => 0, | ||
'message' => _a('User password update failed.'), | ||
]; | ||
|
||
$form->setData($this->request->getPost()); | ||
$form->setInputFilter(new EditPasswordFilter($option)); | ||
if ($form->isValid()) { | ||
|
||
// Update user | ||
$values = $form->getData(); | ||
|
||
// Set update values | ||
$updateValues = [ | ||
'credential' => $values['credential-new'], | ||
'last_modified' => time(), | ||
]; | ||
|
||
// Delete user avatar | ||
$status = Pi::api('user', 'user')->updateUser($uid, $updateValues); | ||
|
||
// Check status | ||
if ($status) { | ||
$result = [ | ||
'status' => 1, | ||
'message' => _a('User password change successful.'), | ||
]; | ||
Pi::service('event')->trigger('user_update', $uid); | ||
} | ||
$this->view()->assign('result', $result); | ||
} | ||
} | ||
|
||
$this->view()->assign( | ||
[ | ||
'user' => $user, | ||
'nav' => $this->getNav($uid), | ||
'name' => 'password', | ||
'form' => $form, | ||
] | ||
); | ||
$this->view()->setTemplate('edit-user'); | ||
} | ||
|
||
/** | ||
* Edit user compound | ||
* | ||
|
@@ -308,7 +369,10 @@ protected function getEditField() | |
$elements = []; | ||
$filters = []; | ||
|
||
$meta = Pi::registry('field', 'user')->read(); | ||
// Get meta | ||
$meta = Pi::registry('field', 'user')->read(); | ||
unset($meta['credential']); | ||
|
||
$editFields = []; | ||
foreach ($meta as $row) { | ||
if ($row['edit'] && $row['type'] != 'compound') { | ||
|
@@ -357,17 +421,31 @@ protected function getNav($uid) | |
'link' => $this->url('', ['controller' => 'edit', 'uid' => $uid]), | ||
]; | ||
|
||
// Password | ||
$result[] = [ | ||
'name' => 'password', | ||
'title' => _a('Password'), | ||
'link' => $this->url( | ||
'', | ||
[ | ||
'controller' => 'edit', | ||
'action' => 'password', | ||
'uid' => $uid, | ||
] | ||
), | ||
]; | ||
|
||
// Avatar | ||
$result[] = [ | ||
'name' => 'avatar', | ||
'title' => _a('Avatar'), | ||
'link' => $this->url( | ||
'', | ||
[ | ||
'controller' => 'edit', | ||
'action' => 'avatar', | ||
'uid' => $uid, | ||
] | ||
'controller' => 'edit', | ||
'action' => 'avatar', | ||
'uid' => $uid, | ||
] | ||
), | ||
]; | ||
|
||
|
@@ -387,11 +465,11 @@ protected function getNav($uid) | |
'link' => $this->url( | ||
'', | ||
[ | ||
'controller' => 'edit', | ||
'action' => 'compound', | ||
'uid' => $uid, | ||
'name' => $row['name'], | ||
] | ||
'controller' => 'edit', | ||
'action' => 'compound', | ||
'uid' => $uid, | ||
'name' => $row['name'], | ||
] | ||
), | ||
]; | ||
} | ||
|
@@ -403,10 +481,10 @@ protected function getNav($uid) | |
'link' => $this->url( | ||
'', | ||
[ | ||
'controller' => 'View', | ||
'action' => 'index', | ||
'uid' => $uid, | ||
] | ||
'controller' => 'view', | ||
'action' => 'index', | ||
'uid' => $uid, | ||
] | ||
), | ||
]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Pi Engine (http://piengine.org) | ||
* | ||
* @link http://code.piengine.org for the Pi Engine source repository | ||
* @copyright Copyright (c) Pi Engine http://piengine.org | ||
* @license http://piengine.org/license.txt New BSD License | ||
*/ | ||
|
||
/** | ||
* @author Hossein Azizabadi <[email protected]> | ||
*/ | ||
|
||
namespace Module\User\Form; | ||
|
||
use Zend\InputFilter\InputFilter; | ||
use Module\System\Validator\UserEmail as UserEmailValidator; | ||
|
||
class EditPasswordFilter extends InputFilter | ||
{ | ||
public function __construct($option = []) | ||
{ | ||
$this->add( | ||
[ | ||
'name' => 'credential-new', | ||
'required' => true, | ||
'filters' => [ | ||
[ | ||
'name' => 'StringTrim', | ||
], | ||
], | ||
'validators' => [ | ||
[ | ||
'name' => 'Module\User\Validator\Password', | ||
], | ||
], | ||
] | ||
); | ||
|
||
$this->add( | ||
[ | ||
'name' => 'credential-confirm', | ||
'required' => true, | ||
'filters' => [ | ||
[ | ||
'name' => 'StringTrim', | ||
], | ||
], | ||
'validators' => [ | ||
[ | ||
'name' => 'Identical', | ||
'options' => [ | ||
'token' => 'credential-new', | ||
'strict' => true, | ||
], | ||
], | ||
], | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* Pi Engine (http://piengine.org) | ||
* | ||
* @link http://code.piengine.org for the Pi Engine source repository | ||
* @copyright Copyright (c) Pi Engine http://piengine.org | ||
* @license http://piengine.org/license.txt New BSD License | ||
*/ | ||
|
||
/** | ||
* @author Hossein Azizabadi <[email protected]> | ||
*/ | ||
|
||
namespace Module\User\Form; | ||
|
||
use Pi\Form\Form as BaseForm; | ||
|
||
class EditPasswordForm extends BaseForm | ||
{ | ||
public function __construct($name = null, $option = []) | ||
{ | ||
$this->option = $option; | ||
parent::__construct($name); | ||
} | ||
|
||
public function getInputFilter() | ||
{ | ||
if (!$this->filter) { | ||
$this->filter = new EditPasswordFilter($this->option); | ||
} | ||
return $this->filter; | ||
} | ||
|
||
public function init() | ||
{ | ||
$this->add( | ||
[ | ||
'name' => 'credential-new', | ||
'options' => [ | ||
'label' => __('New password'), | ||
], | ||
'attributes' => [ | ||
'type' => 'password', | ||
], | ||
] | ||
); | ||
|
||
$this->add( | ||
[ | ||
'name' => 'credential-confirm', | ||
'options' => [ | ||
'label' => __('Confirm password'), | ||
], | ||
'attributes' => [ | ||
'type' => 'password', | ||
], | ||
] | ||
); | ||
|
||
$this->add( | ||
[ | ||
'name' => 'security', | ||
'type' => 'csrf', | ||
] | ||
); | ||
|
||
$this->add( | ||
[ | ||
'name' => 'submit', | ||
'type' => 'submit', | ||
'attributes' => [ | ||
'value' => __('Submit'), | ||
], | ||
] | ||
); | ||
} | ||
} |
Oops, something went wrong.