app/controllers/backend/UserController.php: adding edit action.
This commit is contained in:
parent
e332e1a7e7
commit
b1212f5310
4 changed files with 110 additions and 2 deletions
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
namespace App\Controller\Backend;
|
||||
|
||||
use App\Model\Data\User;
|
||||
use App\Model\Data\User,
|
||||
App\Form\UserSettings as UserSettingsForm;
|
||||
|
||||
class UserController extends \Phalcon\Mvc\Controller
|
||||
{
|
||||
|
|
@ -21,4 +22,42 @@ class UserController extends \Phalcon\Mvc\Controller
|
|||
$this->view->pagination_url = '/admin/user/list/';
|
||||
$this->view->page = $paginator->getPaginate();
|
||||
}
|
||||
|
||||
public function editAction($id)
|
||||
{
|
||||
$user = User::findFirstById($id);
|
||||
$form = new UserSettingsForm($user, true);
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
if ($form->isValid($data)) {
|
||||
|
||||
$new_pw = $form->getValue('passwordNew');
|
||||
if (strlen($new_pw) > 0) {
|
||||
$hash = $this->security->hash($new_pw, 12);
|
||||
$user->setPassword($hash);
|
||||
}
|
||||
$user->save();
|
||||
$form->initialize();
|
||||
|
||||
$this->flash->message('success', 'User saved!');
|
||||
} else {
|
||||
$this->flash->message('error', 'Could not save user');
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->user = $user;
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function statusAction($id, $type)
|
||||
{
|
||||
$user = User::findFirstById($id);
|
||||
$user->setStatus(ucfirst($type));
|
||||
$user->save();
|
||||
|
||||
$this->flash->success('The account was: ' . $user->getStatus());
|
||||
$this->response->redirect('/admin');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue