From 885cdbe47ad19414d2ea207a4dd59bd68d935b48 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 24 Jul 2022 23:04:43 +0200 Subject: [PATCH] app/controllers/backend/UserController.php: Adding newAction() --- app/controllers/backend/UserController.php | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/controllers/backend/UserController.php b/app/controllers/backend/UserController.php index 8a17e3b..d77cbd8 100644 --- a/app/controllers/backend/UserController.php +++ b/app/controllers/backend/UserController.php @@ -23,6 +23,36 @@ class UserController extends \Phalcon\Mvc\Controller $this->view->page = $paginator->getPaginate(); } + public function newAction() + { + $user = new User; + $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); + } + + $form->initialize(); + + $this->flash->message('success', 'User created!'); + $this->response->redirect(['for' => 'backend-user-list']); + return; + } + + $this->flash->message('error', 'Could not create user'); + } + + $this->view->user = $user; + $this->view->form = $form; + $this->view->pick('user/form'); + } + public function editAction($id) { $user = User::findFirstById($id);