aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-07 17:28:56 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-07 17:28:56 +0200
commit99cdd2a0ad7d0c0bf8965ddac2661cfa4c57809d (patch)
treef8cd10a71e2def0c61934e8751012829e4349b1f /app/Controllers
parent530a1d4b6b043f6b6976bb7ad25b380c29d5b5a4 (diff)
parentdbf57266b297c3f831602ec4f451c27a5ad71e6b (diff)
Merge branch 'refactor-authentication' into dev
Diffstat (limited to 'app/Controllers')
-rw-r--r--app/Controllers/authController.php250
-rw-r--r--app/Controllers/categoryController.php2
-rwxr-xr-xapp/Controllers/configureController.php4
-rwxr-xr-xapp/Controllers/entryController.php2
-rwxr-xr-xapp/Controllers/feedController.php2
-rw-r--r--app/Controllers/importExportController.php2
-rwxr-xr-xapp/Controllers/indexController.php268
-rw-r--r--app/Controllers/statsController.php2
-rw-r--r--app/Controllers/subscriptionController.php2
-rw-r--r--app/Controllers/updateController.php2
-rw-r--r--app/Controllers/usersController.php10
11 files changed, 267 insertions, 279 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php
new file mode 100644
index 000000000..e30fa4b72
--- /dev/null
+++ b/app/Controllers/authController.php
@@ -0,0 +1,250 @@
+<?php
+
+/**
+ * This controller handles action about authentication.
+ */
+class FreshRSS_auth_Controller extends Minz_ActionController {
+ /**
+ * This action handles the login page.
+ *
+ * It forwards to the correct login page (form or Persona) or main page if
+ * the user is already connected.
+ */
+ public function loginAction() {
+ if (FreshRSS_Auth::hasAccess()) {
+ Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
+ }
+
+ $auth_type = Minz_Configuration::authType();
+ switch ($auth_type) {
+ case 'form':
+ Minz_Request::forward(array('c' => 'auth', 'a' => 'formLogin'));
+ break;
+ case 'persona':
+ Minz_Request::forward(array('c' => 'auth', 'a' => 'personaLogin'));
+ break;
+ case 'http_auth':
+ case 'none':
+ // It should not happened!
+ Minz_Error::error(404);
+ default:
+ // TODO load plugin instead
+ Minz_Error::error(404);
+ }
+ }
+
+ /**
+ * This action handles form login page.
+ *
+ * If this action is reached through a POST request, username and password
+ * are compared to login the current user.
+ *
+ * Parameters are:
+ * - nonce (default: false)
+ * - username (default: '')
+ * - challenge (default: '')
+ * - keep_logged_in (default: false)
+ */
+ public function formLoginAction() {
+ invalidateHttpCache();
+
+ $file_mtime = @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js');
+ Minz_View::appendScript(Minz_Url::display('/scripts/bcrypt.min.js?' . $file_mtime));
+
+ if (Minz_Request::isPost()) {
+ $nonce = Minz_Session::param('nonce');
+ $username = Minz_Request::param('username', '');
+ $challenge = Minz_Request::param('challenge', '');
+ try {
+ $conf = new FreshRSS_Configuration($username);
+ } catch(Minz_Exception $e) {
+ // $username is not a valid user, nor the configuration file!
+ Minz_Log::warning('Login failure: ' . $e->getMessage());
+ Minz_Request::bad(_t('invalid_login'),
+ array('c' => 'auth', 'a' => 'login'));
+ }
+
+ $ok = FreshRSS_FormAuth::checkCredentials(
+ $username, $conf->passwordHash, $nonce, $challenge
+ );
+ if ($ok) {
+ // Set session parameter to give access to the user.
+ Minz_Session::_param('currentUser', $username);
+ Minz_Session::_param('passwordHash', $conf->passwordHash);
+ FreshRSS_Auth::giveAccess();
+
+ // Set cookie parameter if nedded.
+ if (Minz_Request::param('keep_logged_in')) {
+ FreshRSS_FormAuth::makeCookie($username, $conf->passwordHash);
+ } else {
+ FreshRSS_FormAuth::deleteCookie();
+ }
+
+ // All is good, go back to the index.
+ Minz_Request::good(_t('login'),
+ array('c' => 'index', 'a' => 'index'));
+ } else {
+ Minz_Log::warning('Password mismatch for' .
+ ' user=' . $username .
+ ', nonce=' . $nonce .
+ ', c=' . $challenge);
+ Minz_Request::bad(_t('invalid_login'),
+ array('c' => 'auth', 'a' => 'login'));
+ }
+ }
+ }
+
+ /**
+ * This action handles Persona login page.
+ *
+ * If this action is reached through a POST request, assertion from Persona
+ * is verificated and user connected if all is ok.
+ *
+ * Parameter is:
+ * - assertion (default: false)
+ *
+ * @todo: Persona system should be moved to a plugin
+ */
+ public function personaLoginAction() {
+ $this->view->res = false;
+
+ if (Minz_Request::isPost()) {
+ $this->view->_useLayout(false);
+
+ $assert = Minz_Request::param('assertion');
+ $url = 'https://verifier.login.persona.org/verify';
+ $params = 'assertion=' . $assert . '&audience=' .
+ urlencode(Minz_Url::display(null, 'php', true));
+ $ch = curl_init();
+ $options = array(
+ CURLOPT_URL => $url,
+ CURLOPT_RETURNTRANSFER => TRUE,
+ CURLOPT_POST => 2,
+ CURLOPT_POSTFIELDS => $params
+ );
+ curl_setopt_array($ch, $options);
+ $result = curl_exec($ch);
+ curl_close($ch);
+
+ $res = json_decode($result, true);
+
+ $login_ok = false;
+ $reason = '';
+ if ($res['status'] === 'okay') {
+ $email = filter_var($res['email'], FILTER_VALIDATE_EMAIL);
+ if ($email != '') {
+ $persona_file = DATA_PATH . '/persona/' . $email . '.txt';
+ if (($current_user = @file_get_contents($persona_file)) !== false) {
+ $current_user = trim($current_user);
+ try {
+ $conf = new FreshRSS_Configuration($current_user);
+ $login_ok = strcasecmp($email, $conf->mail_login) === 0;
+ } catch (Minz_Exception $e) {
+ //Permission denied or conf file does not exist
+ $reason = 'Invalid configuration for user ' .
+ '[' . $current_user . '] ' . $e->getMessage();
+ }
+ }
+ } else {
+ $reason = 'Invalid email format [' . $res['email'] . ']';
+ }
+ } else {
+ $reason = $res['reason'];
+ }
+
+ if ($login_ok) {
+ Minz_Session::_param('currentUser', $current_user);
+ Minz_Session::_param('mail', $email);
+ FreshRSS_Auth::giveAccess();
+ invalidateHttpCache();
+ } else {
+ Minz_Log::error($reason);
+
+ $res = array();
+ $res['status'] = 'failure';
+ $res['reason'] = _t('invalid_login');
+ }
+
+ header('Content-Type: application/json; charset=UTF-8');
+ $this->view->res = $res;
+ }
+ }
+
+ /**
+ * This action removes all accesses of the current user.
+ */
+ public function logoutAction() {
+ invalidateHttpCache();
+ FreshRSS_Auth::removeAccess();
+ Minz_Request::good(_t('disconnected'),
+ array('c' => 'index', 'a' => 'index'));
+ }
+
+ /**
+ * This action resets the authentication system.
+ *
+ * After reseting, form auth is set by default.
+ */
+ public function resetAction() {
+ Minz_View::prependTitle(_t('auth_reset') . ' · ');
+
+ Minz_View::appendScript(Minz_Url::display(
+ '/scripts/bcrypt.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js')
+ ));
+
+ $this->view->no_form = false;
+ // Enable changement of auth only if Persona!
+ if (Minz_Configuration::authType() != 'persona') {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('auth_not_persona')
+ );
+ $this->view->no_form = true;
+ return;
+ }
+
+ $conf = new FreshRSS_Configuration(Minz_Configuration::defaultUser());
+ // Admin user must have set its master password.
+ if (!$conf->passwordHash) {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('damn'),
+ 'body' => _t('auth_no_password_set')
+ );
+ $this->view->no_form = true;
+ return;
+ }
+
+ invalidateHttpCache();
+
+ if (Minz_Request::isPost()) {
+ $nonce = Minz_Session::param('nonce');
+ $username = Minz_Request::param('username', '');
+ $challenge = Minz_Request::param('challenge', '');
+
+ $ok = FreshRSS_FormAuth::checkCredentials(
+ $username, $conf->passwordHash, $nonce, $challenge
+ );
+
+ if ($ok) {
+ Minz_Configuration::_authType('form');
+ $ok = Minz_Configuration::writeFile();
+
+ if ($ok) {
+ Minz_Request::good(_t('auth_form_set'));
+ } else {
+ Minz_Request::bad(_t('auth_form_not_set'),
+ array('c' => 'auth', 'a' => 'reset'));
+ }
+ } else {
+ Minz_Log::warning('Password mismatch for' .
+ ' user=' . $username .
+ ', nonce=' . $nonce .
+ ', c=' . $challenge);
+ Minz_Request::bad(_t('invalid_login'),
+ array('c' => 'auth', 'a' => 'reset'));
+ }
+ }
+ }
+}
diff --git a/app/Controllers/categoryController.php b/app/Controllers/categoryController.php
index c79f37fa4..537a2b210 100644
--- a/app/Controllers/categoryController.php
+++ b/app/Controllers/categoryController.php
@@ -12,7 +12,7 @@ class FreshRSS_category_Controller extends Minz_ActionController {
*
*/
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php
index 789e9dfb0..fb8c1466e 100755
--- a/app/Controllers/configureController.php
+++ b/app/Controllers/configureController.php
@@ -10,7 +10,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
* underlying framework.
*/
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
@@ -229,7 +229,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
$this->view->nb_total = $entryDAO->count();
$this->view->size_user = $entryDAO->size();
- if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
+ if (FreshRSS_Auth::hasAccess('admin')) {
$this->view->size_total = $entryDAO->size(true);
}
}
diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php
index c46fbf346..a1dfacb4d 100755
--- a/app/Controllers/entryController.php
+++ b/app/Controllers/entryController.php
@@ -10,7 +10,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
* underlying framework.
*/
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 18829d252..2a7238eaf 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -10,7 +10,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
* underlying framework.
*/
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
// Token is useful in the case that anonymous refresh is forbidden
// and CRON task cannot be used with php command so the user can
// set a CRON task to refresh his feeds by using token inside url
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
index 57759f277..aaac1b68b 100644
--- a/app/Controllers/importExportController.php
+++ b/app/Controllers/importExportController.php
@@ -10,7 +10,7 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
* underlying framework.
*/
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php
index 0d2eff700..5b490e672 100755
--- a/app/Controllers/indexController.php
+++ b/app/Controllers/indexController.php
@@ -8,7 +8,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
$token = $this->view->conf->token;
// check if user is logged in
- if (!$this->view->loginOk && !Minz_Configuration::allowAnonymous()) {
+ if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) {
$token_param = Minz_Request::param('token', '');
$token_is_ok = ($token != '' && $token === $token_param);
if ($output === 'rss' && !$token_is_ok) {
@@ -20,7 +20,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
} elseif ($output !== 'rss') {
// "hard" redirection is not required, just ask dispatcher to
// forward to the login form without 302 redirection
- Minz_Request::forward(array('c' => 'index', 'a' => 'formLogin'));
+ Minz_Request::forward(array('c' => 'auth', 'a' => 'login'));
return;
}
}
@@ -207,7 +207,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
}
public function logsAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
@@ -228,266 +228,4 @@ class FreshRSS_index_Controller extends Minz_ActionController {
$this->view->logsPaginator->_nbItemsPerPage(50);
$this->view->logsPaginator->_currentPage($page);
}
-
- public function loginAction() {
- $this->view->_useLayout(false);
-
- $url = 'https://verifier.login.persona.org/verify';
- $assert = Minz_Request::param('assertion');
- $params = 'assertion=' . $assert . '&audience=' .
- urlencode(Minz_Url::display(null, 'php', true));
- $ch = curl_init();
- $options = array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => TRUE,
- CURLOPT_POST => 2,
- CURLOPT_POSTFIELDS => $params
- );
- curl_setopt_array($ch, $options);
- $result = curl_exec($ch);
- curl_close($ch);
-
- $res = json_decode($result, true);
-
- $loginOk = false;
- $reason = '';
- if ($res['status'] === 'okay') {
- $email = filter_var($res['email'], FILTER_VALIDATE_EMAIL);
- if ($email != '') {
- $personaFile = DATA_PATH . '/persona/' . $email . '.txt';
- if (($currentUser = @file_get_contents($personaFile)) !== false) {
- $currentUser = trim($currentUser);
- if (ctype_alnum($currentUser)) {
- try {
- $this->conf = new FreshRSS_Configuration($currentUser);
- $loginOk = strcasecmp($email, $this->conf->mail_login) === 0;
- } catch (Minz_Exception $e) {
- $reason = 'Invalid configuration for user [' . $currentUser . ']! ' . $e->getMessage(); //Permission denied or conf file does not exist
- }
- } else {
- $reason = 'Invalid username format [' . $currentUser . ']!';
- }
- }
- } else {
- $reason = 'Invalid email format [' . $res['email'] . ']!';
- }
- }
- if ($loginOk) {
- Minz_Session::_param('currentUser', $currentUser);
- Minz_Session::_param('mail', $email);
- $this->view->loginOk = true;
- invalidateHttpCache();
- } else {
- $res = array();
- $res['status'] = 'failure';
- $res['reason'] = $reason == '' ? _t('invalid_login') : $reason;
- Minz_Log::warning('Persona: ' . $res['reason']);
- }
-
- header('Content-Type: application/json; charset=UTF-8');
- $this->view->res = json_encode($res);
- }
-
- public function logoutAction() {
- $this->view->_useLayout(false);
- invalidateHttpCache();
- Minz_Session::_param('currentUser');
- Minz_Session::_param('mail');
- Minz_Session::_param('passwordHash');
- }
-
- private static function makeLongTermCookie($username, $passwordHash) {
- do {
- $token = sha1(Minz_Configuration::salt() . $username . uniqid(mt_rand(), true));
- $tokenFile = DATA_PATH . '/tokens/' . $token . '.txt';
- } while (file_exists($tokenFile));
- if (@file_put_contents($tokenFile, $username . "\t" . $passwordHash) === false) {
- return false;
- }
- $expire = time() + 2629744; //1 month //TODO: Use a configuration instead
- Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire);
- Minz_Session::_param('token', $token);
- return $token;
- }
-
- private static function deleteLongTermCookie() {
- Minz_Session::deleteLongTermCookie('FreshRSS_login');
- $token = Minz_Session::param('token', null);
- if (ctype_alnum($token)) {
- @unlink(DATA_PATH . '/tokens/' . $token . '.txt');
- }
- Minz_Session::_param('token');
- if (rand(0, 10) === 1) {
- self::purgeTokens();
- }
- }
-
- private static function purgeTokens() {
- $oldest = time() - 2629744; //1 month //TODO: Use a configuration instead
- foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $fileInfo) {
- if ($fileInfo->getExtension() === 'txt' && $fileInfo->getMTime() < $oldest) {
- @unlink($fileInfo->getPathname());
- }
- }
- }
-
- public function formLoginAction() {
- if ($this->view->loginOk) {
- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
- }
-
- if (Minz_Request::isPost()) {
- $ok = false;
- $nonce = Minz_Session::param('nonce');
- $username = Minz_Request::param('username', '');
- $c = Minz_Request::param('challenge', '');
- if (ctype_alnum($username) && ctype_graph($c) && ctype_alnum($nonce)) {
- if (!function_exists('password_verify')) {
- include_once(LIB_PATH . '/password_compat.php');
- }
- try {
- $conf = new FreshRSS_Configuration($username);
- $s = $conf->passwordHash;
- $ok = password_verify($nonce . $s, $c);
- if ($ok) {
- Minz_Session::_param('currentUser', $username);
- Minz_Session::_param('passwordHash', $s);
- if (Minz_Request::param('keep_logged_in', false)) {
- self::makeLongTermCookie($username, $s);
- } else {
- self::deleteLongTermCookie();
- }
- } else {
- Minz_Log::warning('Password mismatch for user ' . $username . ', nonce=' . $nonce . ', c=' . $c);
- }
- } catch (Minz_Exception $me) {
- Minz_Log::warning('Login failure: ' . $me->getMessage());
- }
- } else {
- Minz_Log::debug('Invalid credential parameters: user=' . $username . ' challenge=' . $c . ' nonce=' . $nonce);
- }
- if (!$ok) {
- $notif = array(
- 'type' => 'bad',
- 'content' => _t('invalid_login')
- );
- Minz_Session::_param('notification', $notif);
- }
- $this->view->_useLayout(false);
- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
- } elseif (Minz_Configuration::unsafeAutologinEnabled() && isset($_GET['u']) && isset($_GET['p'])) {
- Minz_Session::_param('currentUser');
- Minz_Session::_param('mail');
- Minz_Session::_param('passwordHash');
- $username = ctype_alnum($_GET['u']) ? $_GET['u'] : '';
- $passwordPlain = $_GET['p'];
- Minz_Request::_param('p'); //Discard plain-text password ASAP
- $_GET['p'] = '';
- if (!function_exists('password_verify')) {
- include_once(LIB_PATH . '/password_compat.php');
- }
- try {
- $conf = new FreshRSS_Configuration($username);
- $s = $conf->passwordHash;
- $ok = password_verify($passwordPlain, $s);
- unset($passwordPlain);
- if ($ok) {
- Minz_Session::_param('currentUser', $username);
- Minz_Session::_param('passwordHash', $s);
- } else {
- Minz_Log::warning('Unsafe password mismatch for user ' . $username);
- }
- } catch (Minz_Exception $me) {
- Minz_Log::warning('Unsafe login failure: ' . $me->getMessage());
- }
- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
- } elseif (!Minz_Configuration::canLogIn()) {
- Minz_Error::error(
- 403,
- array('error' => array(_t('access_denied')))
- );
- }
- invalidateHttpCache();
- }
-
- public function formLogoutAction() {
- $this->view->_useLayout(false);
- invalidateHttpCache();
- Minz_Session::_param('currentUser');
- Minz_Session::_param('mail');
- Minz_Session::_param('passwordHash');
- self::deleteLongTermCookie();
- Minz_Request::forward(array('c' => 'index', 'a' => 'index'), true);
- }
-
- public function resetAuthAction() {
- Minz_View::prependTitle(_t('auth_reset') . ' · ');
- Minz_View::appendScript(Minz_Url::display(
- '/scripts/bcrypt.min.js?' . @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js')
- ));
-
- $this->view->no_form = false;
- // Enable changement of auth only if Persona!
- if (Minz_Configuration::authType() != 'persona') {
- $this->view->message = array(
- 'status' => 'bad',
- 'title' => _t('damn'),
- 'body' => _t('auth_not_persona')
- );
- $this->view->no_form = true;
- return;
- }
-
- $conf = new FreshRSS_Configuration(Minz_Configuration::defaultUser());
- // Admin user must have set its master password.
- if (!$conf->passwordHash) {
- $this->view->message = array(
- 'status' => 'bad',
- 'title' => _t('damn'),
- 'body' => _t('auth_no_password_set')
- );
- $this->view->no_form = true;
- return;
- }
-
- invalidateHttpCache();
-
- if (Minz_Request::isPost()) {
- $nonce = Minz_Session::param('nonce');
- $username = Minz_Request::param('username', '');
- $c = Minz_Request::param('challenge', '');
- if (!(ctype_alnum($username) && ctype_graph($c) && ctype_alnum($nonce))) {
- Minz_Log::debug('Invalid credential parameters:' .
- ' user=' . $username .
- ' challenge=' . $c .
- ' nonce=' . $nonce);
- Minz_Request::bad(_t('invalid_login'),
- array('c' => 'index', 'a' => 'resetAuth'));
- }
-
- if (!function_exists('password_verify')) {
- include_once(LIB_PATH . '/password_compat.php');
- }
-
- $s = $conf->passwordHash;
- $ok = password_verify($nonce . $s, $c);
- if ($ok) {
- Minz_Configuration::_authType('form');
- $ok = Minz_Configuration::writeFile();
-
- if ($ok) {
- Minz_Request::good(_t('auth_form_set'));
- } else {
- Minz_Request::bad(_t('auth_form_not_set'),
- array('c' => 'index', 'a' => 'resetAuth'));
- }
- } else {
- Minz_Log::debug('Password mismatch for user ' . $username .
- ', nonce=' . $nonce . ', c=' . $c);
-
- Minz_Request::bad(_t('invalid_login'),
- array('c' => 'index', 'a' => 'resetAuth'));
- }
- }
- }
}
diff --git a/app/Controllers/statsController.php b/app/Controllers/statsController.php
index 99c57c809..0e3430fcc 100644
--- a/app/Controllers/statsController.php
+++ b/app/Controllers/statsController.php
@@ -118,7 +118,7 @@ class FreshRSS_stats_Controller extends Minz_ActionController {
* underlying framework.
*/
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403, array('error' => array(_t('access_denied')))
);
diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.php
index 7cc8179a0..a89168eb3 100644
--- a/app/Controllers/subscriptionController.php
+++ b/app/Controllers/subscriptionController.php
@@ -10,7 +10,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
* underlying framework.
*/
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php
index da5bddc65..9d1e1ddf5 100644
--- a/app/Controllers/updateController.php
+++ b/app/Controllers/updateController.php
@@ -3,7 +3,7 @@
class FreshRSS_update_Controller extends Minz_ActionController {
public function firstAction() {
$current_user = Minz_Session::param('currentUser', '');
- if (!$this->view->loginOk && Minz_Configuration::isAdmin($current_user)) {
+ if (!FreshRSS_Auth::hasAccess('admin')) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
diff --git a/app/Controllers/usersController.php b/app/Controllers/usersController.php
index 7d0171bc7..11862ce27 100644
--- a/app/Controllers/usersController.php
+++ b/app/Controllers/usersController.php
@@ -5,7 +5,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
const BCRYPT_COST = 9; //Will also have to be computed client side on mobile devices, so do not use a too high cost
public function firstAction() {
- if (!$this->view->loginOk) {
+ if (!FreshRSS_Auth::hasAccess()) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
@@ -51,7 +51,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
$this->view->conf->_apiPasswordHash($passwordHash);
}
- if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
+ if (FreshRSS_Auth::hasAccess('admin')) {
$this->view->conf->_mail_login(Minz_Request::param('mail_login', '', true));
}
$email = $this->view->conf->mail_login;
@@ -65,7 +65,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
$ok &= (file_put_contents($personaFile, Minz_Session::param('currentUser', '_')) !== false);
}
- if (Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
+ if (FreshRSS_Auth::hasAccess('admin')) {
$current_token = $this->view->conf->token;
$token = Minz_Request::param('token', $current_token);
$this->view->conf->_token($token);
@@ -105,7 +105,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
}
public function createAction() {
- if (Minz_Request::isPost() && Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
+ if (Minz_Request::isPost() && FreshRSS_Auth::hasAccess('admin')) {
$db = Minz_Configuration::dataBase();
require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php');
@@ -177,7 +177,7 @@ class FreshRSS_users_Controller extends Minz_ActionController {
}
public function deleteAction() {
- if (Minz_Request::isPost() && Minz_Configuration::isAdmin(Minz_Session::param('currentUser', '_'))) {
+ if (Minz_Request::isPost() && FreshRSS_Auth::hasAccess('admin')) {
$db = Minz_Configuration::dataBase();
require_once(APP_PATH . '/SQL/install.sql.' . $db['type'] . '.php');