public function put_index($id, $username, $email, $password = null, $id_group = null) { // Force to edit the current user if they don't have the proper permissions if (!$this->_currentUser->hasPermission(Model_Groups::PERM_MANAGE_USERS)) { $id = $this->_currentUser->getId(); } $user = Model_Users::getById($id); $propsUpdate = ['username' => $username, 'email' => $email]; if ($id_group !== null && !empty($id_group) && $this->_currentUser->hasPermission(Model_Groups::PERM_MANAGE_USERS)) { $group = Model_Groups::getById($id_group); $propsUpdate['usergroup'] = $group; } else { $user->load('usergroup'); } if ($password !== null && !empty($password)) { $propsUpdate['password'] = Library_String::hash(trim($password)); } $user->setProps($propsUpdate); Model_Users::update($user); // Disconnect the user if they changed their own profile if ($id === $this->_currentUser->getId()) { $this->response->redirect('../login/out', 200); } else { $this->response->redirect('../users', 200); } }
public function delete_index($id_user) { if ($this->_currentUser->getId() === $id_user) { $this->response->error('Vous ne pouvez pas vous supprimer vous-même !', 403); return; } $user = Model_Users::getById($id_user); if ($user) { $user->remove(); } $this->get_index(); }
protected function _showAuthor($id_author) { $author = Model_Users::getById($id_author); if (empty($author)) { $this->response->error('L\'utilisateur demandé n\'existe pas ou plus.', 404); return; } $canReadUnpublished = $this->_currentUser->hasPermission(Model_Groups::PERM_READ_UNPUBLISHED_ARTICLES); if ($canReadUnpublished) { $articles = $author->getArticles(); } else { $articles = $author->getPublishedArticles(); } if ($articles->count() === 0) { $tpl_articles = Eliya\Tpl::get('authors/no_articles'); } else { $tpl_articles = Eliya\Tpl::get('common/articles/list', ['articles' => $articles]); } $this->response->set(Eliya\Tpl::get('authors/details', ['author' => $author, 'tpl_articles' => $tpl_articles])); }