From ac3e38359b420068b75cc848d89a3a6fc7b6e6c6 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Wed, 14 Feb 2018 22:15:34 +0100 Subject: Allow admin user to reset passwords (#1765) See #960 --- app/Controllers/userController.php | 56 ++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'app/Controllers/userController.php') diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 2a1d43d9e..820260a08 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -44,29 +44,54 @@ class FreshRSS_user_Controller extends Minz_ActionController { return preg_match('/^' . self::USERNAME_PATTERN . '$/', $username) === 1; } - public static function updateContextUser($passwordPlain, $apiPasswordPlain, $userConfigUpdated = array()) { + public static function updateUser($user, $passwordPlain, $apiPasswordPlain, $userConfigUpdated = array()) { + $userConfig = get_user_configuration($user); if ($passwordPlain != '') { $passwordHash = self::hashPassword($passwordPlain); - FreshRSS_Context::$user_conf->passwordHash = $passwordHash; + $userConfig->passwordHash = $passwordHash; } if ($apiPasswordPlain != '') { $apiPasswordHash = self::hashPassword($apiPasswordPlain); - FreshRSS_Context::$user_conf->apiPasswordHash = $apiPasswordHash; + $userConfig->apiPasswordHash = $apiPasswordHash; } if (is_array($userConfigUpdated)) { foreach ($userConfigUpdated as $configName => $configValue) { if ($configValue !== null) { - FreshRSS_Context::$user_conf->_param($configName, $configValue); + $userConfig->_param($configName, $configValue); } } } - $ok = FreshRSS_Context::$user_conf->save(); + $ok = $userConfig->save(); return $ok; } + public function updateAction() { + if (Minz_Request::isPost()) { + $passwordPlain = Minz_Request::param('newPasswordPlain', '', true); + Minz_Request::_param('newPasswordPlain'); //Discard plain-text password ASAP + $_POST['newPasswordPlain'] = ''; + + $apiPasswordPlain = Minz_Request::param('apiPasswordPlain', '', true); + + $username = Minz_Request::param('username'); + $ok = self::updateUser($username, $passwordPlain, $apiPasswordPlain, array( + 'token' => Minz_Request::param('token', null), + )); + + if ($ok) { + Minz_Request::good(_t('feedback.user.updated', $username), + array('c' => 'user', 'a' => 'manage')); + } else { + Minz_Request::bad(_t('feedback.user.updated.error', $username), + array('c' => 'user', 'a' => 'manage')); + } + + } + } + /** * This action displays the user profile page. */ @@ -84,7 +109,7 @@ class FreshRSS_user_Controller extends Minz_ActionController { $apiPasswordPlain = Minz_Request::param('apiPasswordPlain', '', true); - $ok = self::updateContextUser($passwordPlain, $apiPasswordPlain, array( + $ok = self::updateUser(Minz_Session::param('currentUser'), $passwordPlain, $apiPasswordPlain, array( 'token' => Minz_Request::param('token', null), )); @@ -110,19 +135,16 @@ class FreshRSS_user_Controller extends Minz_ActionController { Minz_View::prependTitle(_t('admin.user.title') . ' ยท '); - // Get the correct current user. - $username = Minz_Request::param('u', Minz_Session::param('currentUser')); - if (!FreshRSS_UserDAO::exist($username)) { - $username = Minz_Session::param('currentUser'); - } - $this->view->current_user = $username; + $this->view->current_user = Minz_Request::param('u'); - // Get information about the current user. - $entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user); - $this->view->nb_articles = $entryDAO->count(); + if ($this->view->current_user) { + // Get information about the current user. + $entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user); + $this->view->nb_articles = $entryDAO->count(); - $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); - $this->view->size_user = $databaseDAO->size(); + $databaseDAO = FreshRSS_Factory::createDatabaseDAO(); + $this->view->size_user = $databaseDAO->size(); + } } public static function createUser($new_user_name, $passwordPlain, $apiPasswordPlain, $userConfig = array(), $insertDefaultFeeds = true) { -- cgit v1.2.3 From 4be15d5b40ffed2d84d4b000591d74f44454ea8a Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Wed, 14 Feb 2018 22:31:15 +0100 Subject: Fix notice when managing user (#1785) See #1765 & #960 --- app/Controllers/userController.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/Controllers/userController.php') diff --git a/app/Controllers/userController.php b/app/Controllers/userController.php index 820260a08..2dad6a3f0 100644 --- a/app/Controllers/userController.php +++ b/app/Controllers/userController.php @@ -137,6 +137,8 @@ class FreshRSS_user_Controller extends Minz_ActionController { $this->view->current_user = Minz_Request::param('u'); + $this->view->nb_articles = 0; + $this->view->size_user = 0; if ($this->view->current_user) { // Get information about the current user. $entryDAO = FreshRSS_Factory::createEntryDao($this->view->current_user); -- cgit v1.2.3