diff --git a/app/library/App/Controllers/UsersController.php b/app/library/App/Controllers/UsersController.php deleted file mode 100644 index 6816080..0000000 --- a/app/library/App/Controllers/UsersController.php +++ /dev/null @@ -1,245 +0,0 @@ -persistent->parameters = null; - } - - /** - * Searches for users - */ - public function searchAction() - { - $numberPage = 1; - if ($this->request->isPost()) { - $query = Criteria::fromInput($this->di, 'Users', $_POST); - $this->persistent->parameters = $query->getParams(); - } else { - $numberPage = $this->request->getQuery("page", "int"); - } - - $parameters = $this->persistent->parameters; - if (!is_array($parameters)) { - $parameters = []; - } - $parameters["order"] = "id"; - - $users = Users::find($parameters); - if (count($users) == 0) { - $this->flash->notice("The search did not find any users"); - - $this->dispatcher->forward([ - "controller" => "users", - "action" => "index" - ]); - - return; - } - - $paginator = new Paginator([ - 'data' => $users, - 'limit'=> 10, - 'page' => $numberPage - ]); - - $this->view->page = $paginator->getPaginate(); - } - - /** - * Displays the creation form - */ - public function newAction() - { - - } - - /** - * Edits a user - * - * @param string $id - */ - public function editAction($id) - { - if (!$this->request->isPost()) { - - $user = Users::findFirstByid($id); - if (!$user) { - $this->flash->error("user was not found"); - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'index' - ]); - - return; - } - - $this->view->id = $user->id; - - $this->tag->setDefault("id", $user->id); - $this->tag->setDefault("name", $user->name); - $this->tag->setDefault("pass", $user->pass); - $this->tag->setDefault("email", $user->email); - $this->tag->setDefault("role", $user->role); - $this->tag->setDefault("created_at", $user->created_at); - $this->tag->setDefault("updated_at", $user->updated_at); - - } - } - - /** - * Creates a new user - */ - public function createAction() - { - if (!$this->request->isPost()) { - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'index' - ]); - - return; - } - - $user = new Users(); - $user->name = $this->request->getPost("name"); - $user->pass = $this->request->getPost("pass"); - $user->email = $this->request->getPost("email", "email"); - $user->role = $this->request->getPost("role"); - $user->created_at = $this->request->getPost("created_at"); - $user->updated_at = $this->request->getPost("updated_at"); - - - if (!$user->save()) { - foreach ($user->getMessages() as $message) { - $this->flash->error($message); - } - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'new' - ]); - - return; - } - - $this->flash->success("user was created successfully"); - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'index' - ]); - } - - /** - * Saves a user edited - * - */ - public function saveAction() - { - - if (!$this->request->isPost()) { - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'index' - ]); - - return; - } - - $id = $this->request->getPost("id"); - $user = Users::findFirstByid($id); - - if (!$user) { - $this->flash->error("user does not exist " . $id); - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'index' - ]); - - return; - } - - $user->name = $this->request->getPost("name"); - $user->pass = $this->request->getPost("pass"); - $user->email = $this->request->getPost("email", "email"); - $user->role = $this->request->getPost("role"); - $user->created_at = $this->request->getPost("created_at"); - $user->updated_at = $this->request->getPost("updated_at"); - - - if (!$user->save()) { - - foreach ($user->getMessages() as $message) { - $this->flash->error($message); - } - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'edit', - 'params' => [$user->id] - ]); - - return; - } - - $this->flash->success("user was updated successfully"); - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'index' - ]); - } - - /** - * Deletes a user - * - * @param string $id - */ - public function deleteAction($id) - { - $user = Users::findFirstByid($id); - if (!$user) { - $this->flash->error("user was not found"); - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'index' - ]); - - return; - } - - if (!$user->delete()) { - - foreach ($user->getMessages() as $message) { - $this->flash->error($message); - } - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => 'search' - ]); - - return; - } - - $this->flash->success("user was deleted successfully"); - - $this->dispatcher->forward([ - 'controller' => "users", - 'action' => "index" - ]); - } - -} diff --git a/app/library/App/Model/Project.php b/app/library/App/Model/Project.php index 2254c2a..2f68714 100644 --- a/app/library/App/Model/Project.php +++ b/app/library/App/Model/Project.php @@ -33,9 +33,6 @@ class Project extends \App\Mvc\DateTrackingModel { $this->setSchema("public"); -// $this->belongsTo('user_id', User::class, 'id', [ -// 'alias' => 'User', -// ]); } } \ No newline at end of file diff --git a/app/library/App/Model/Projects.php b/app/library/App/Model/Projects.php deleted file mode 100644 index c024266..0000000 --- a/app/library/App/Model/Projects.php +++ /dev/null @@ -1,83 +0,0 @@ -setSchema("public"); - $this->belongsTo('user_id', '\User', 'id', ['alias' => 'User']); - } - - /** - * Returns table name mapped in the model. - * - * @return string - */ - public function getSource() - { - return 'projects'; - } - - /** - * Allows to query a set of records that match the specified conditions - * - * @param mixed $parameters - * @return Projects[]|Projects - */ - public static function find($parameters = null) - { - return parent::find($parameters); - } - - /** - * Allows to query the first record that match the specified conditions - * - * @param mixed $parameters - * @return Projects - */ - public static function findFirst($parameters = null) - { - return parent::findFirst($parameters); - } - -} diff --git a/app/library/App/Model/User.php b/app/library/App/Model/User.php index 4d0fae2..9bd18af 100755 --- a/app/library/App/Model/User.php +++ b/app/library/App/Model/User.php @@ -1,14 +1,15 @@ 'id', - 'username' => 'username', - 'password' => 'password', + 'name' => 'name', + 'pass' => 'pass', 'email' => 'email', 'role' => 'role' ]; } + + public function validation() + { + $validator = new Validation(); + + $validator->add( + 'email', + new EmailValidator( + [ + 'model' => $this, + 'message' => 'Please enter a correct email address', + ] + ) + ); + + return $this->validate($validator); + } } diff --git a/app/library/App/Model/Users.php b/app/library/App/Model/Users.php deleted file mode 100644 index c1df29b..0000000 --- a/app/library/App/Model/Users.php +++ /dev/null @@ -1,122 +0,0 @@ -add( - 'email', - new EmailValidator( - [ - 'model' => $this, - 'message' => 'Please enter a correct email address', - ] - ) - ); - - return $this->validate($validator); - } - - /** - * Initialize method for model. - */ - public function initialize() - { - $this->setSchema("public"); - } - - /** - * Returns table name mapped in the model. - * - * @return string - */ - public function getSource() - { - return 'users'; - } - - /** - * Allows to query a set of records that match the specified conditions - * - * @param mixed $parameters - * @return Users[]|Users - */ - public static function find($parameters = null) - { - return parent::find($parameters); - } - - /** - * Allows to query the first record that match the specified conditions - * - * @param mixed $parameters - * @return Users - */ - public static function findFirst($parameters = null) - { - return parent::findFirst($parameters); - } - -} -- libgit2 0.21.4