From 10532dc4e8b403b30e1a3c92a38028847362a3c2 Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Mon, 20 Feb 2017 23:12:25 +0100 Subject: [PATCH] Problem: Failed logins always try log in against legacy upstream Solution: Make the login fallback optional and deactivate it in the default config. I'm leaving the code in here mostly because I want to revisit it and make it modular so I can later on plug my own FreeIPA things :) --- airtime_mvc/application/configs/constants.php | 3 +- .../controllers/LoginController.php | 39 ++++++++++++------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index af84e69cb..9f9c4a709 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -106,7 +106,8 @@ define('UI_PLAYLISTCONTROLLER_OBJ_SESSNAME', 'PLAYLISTCONTROLLER_OBJ'); define('UI_BLOCK_SESSNAME', 'BLOCK');*/ //WHMCS integration -define("WHMCS_API_URL", "https://account.sourcefabric.com/includes/api.php"); +define("LIBRETIME_ENABLE_WHMCS", false); +define("WHMCS_API_URL", "https://account.example.org/includes/api.php"); define("SUBDOMAIN_WHMCS_CUSTOM_FIELD_NAME", "Choose your domain"); //Sentry error logging diff --git a/airtime_mvc/application/controllers/LoginController.php b/airtime_mvc/application/controllers/LoginController.php index bd3869919..6912f07c6 100644 --- a/airtime_mvc/application/controllers/LoginController.php +++ b/airtime_mvc/application/controllers/LoginController.php @@ -45,7 +45,7 @@ class LoginController extends Zend_Controller_Action //uses separate layout without a navigation. $this->_helper->layout->setLayout('login'); - $error = false; + $this->view->error = false; $baseUrl = Application_Common_OsPath::getBaseDir(); @@ -92,7 +92,7 @@ class LoginController extends Zend_Controller_Action Application_Model_Preference::SetUserLocale($locale); $this->_redirect('showbuilder'); - } else { + } elseif (LIBRETIME_ENABLE_WHMCS) { $email = $form->getValue('username'); $authAdapter = new WHMCS_Auth_Adapter("admin", $email, $password); $auth = Zend_Auth::getInstance(); @@ -105,23 +105,14 @@ class LoginController extends Zend_Controller_Action $this->_redirect('showbuilder'); } else { - $message = _("Wrong username or password provided. Please try again."); - Application_Model_Subjects::increaseLoginAttempts($username); - Application_Model_LoginAttempts::increaseAttempts($_SERVER['REMOTE_ADDR']); - $form = new Application_Form_Login(); - $error = true; - //Only show the captcha if you get your login wrong 4 times in a row. - if (Application_Model_Subjects::getLoginAttempts($username) > 3) - { - $form->addRecaptcha(); - } + $form = $this->loginError($username); } + } else { + $form = $this->loginError($username); } } } - $this->view->message = $message; - $this->view->error = $error; $this->view->form = $form; $this->view->airtimeVersion = Application_Model_Preference::GetAirtimeVersion(); $this->view->airtimeCopyright = AIRTIME_COPYRIGHT_DATE; @@ -260,4 +251,24 @@ class LoginController extends Zend_Controller_Action $this->view->form = $form; } + + /** + * populates view with results from a login error and adds a new form + * + * @param String $username user that failed to login + * @return new form + */ + private function loginError($username) + { + $this->view->message = _("Wrong username or password provided. Please try again."); + Application_Model_Subjects::increaseLoginAttempts($username); + Application_Model_LoginAttempts::increaseAttempts($_SERVER['REMOTE_ADDR']); + $form = new Application_Form_Login(); + $this->view->error = true; + //Only show the captcha if you get your login wrong 4 times in a row. + if (Application_Model_Subjects::getLoginAttempts($username) > 3) { + $form->addRecaptcha(); + } + return $form; + } }