Exemplo n.º 1
0
 public function init()
 {
     $CC_CONFIG = Config::getConfig();
     // Set the method for the display form to POST
     $this->setMethod('post');
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'form/login.phtml'))));
     // Add username element
     $this->addElement('text', 'username', array('label' => _('Username:'******'class' => 'input_text', 'required' => true, 'value' => isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1 ? 'admin' : '', 'filters' => array('StringTrim'), 'validators' => array('NotEmpty'), 'decorators' => array('ViewHelper')));
     // Add password element
     $this->addElement('password', 'password', array('label' => _('Password:'******'class' => 'input_text', 'required' => true, 'value' => isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1 ? 'admin' : '', 'filters' => array('StringTrim'), 'validators' => array('NotEmpty'), 'decorators' => array('ViewHelper')));
     $locale = new Zend_Form_Element_Select("locale");
     $locale->setLabel(_("Language:"));
     $locale->setMultiOptions(Application_Model_Locale::getLocales());
     $locale->setDecorators(array('ViewHelper'));
     $this->addElement($locale);
     $recaptchaNeeded = false;
     if (Application_Model_LoginAttempts::getAttempts($_SERVER['REMOTE_ADDR']) >= 3) {
         $recaptchaNeeded = true;
     }
     if ($recaptchaNeeded) {
         // recaptcha
         $this->addRecaptcha();
     }
     // Add the submit button
     $this->addElement('submit', 'submit', array('ignore' => true, 'label' => _('Login'), 'class' => 'ui-button ui-widget ui-state-default ui-button-text-only center', 'decorators' => array('ViewHelper')));
 }
Exemplo n.º 2
0
 public function indexAction()
 {
     global $CC_CONFIG;
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_redirect('Showbuilder');
     }
     //uses separate layout without a navigation.
     $this->_helper->layout->setLayout('login');
     $error = false;
     $request = $this->getRequest();
     $baseUrl = $request->getBaseUrl();
     $this->view->headScript()->appendFile($baseUrl . '/js/airtime/login/login.js?' . $CC_CONFIG['airtime_version'], 'text/javascript');
     $form = new Application_Form_Login();
     $message = "Please enter your user name and password";
     if ($request->isPost()) {
         // if the post contains recaptcha field, which means form had recaptcha field.
         // Hence add the element for validation.
         if (array_key_exists('recaptcha_response_field', $request->getPost())) {
             $form->addRecaptcha();
         }
         if ($form->isValid($request->getPost())) {
             //get the username and password from the form
             $username = $form->getValue('username');
             $password = $form->getValue('password');
             if (Application_Model_Subjects::getLoginAttempts($username) >= 3 && $form->getElement('captcha') == NULL) {
                 $form->addRecaptcha();
             } else {
                 $authAdapter = Application_Model_Auth::getAuthAdapter();
                 //pass to the adapter the submitted username and password
                 $authAdapter->setIdentity($username)->setCredential($password);
                 $auth = Zend_Auth::getInstance();
                 $result = $auth->authenticate($authAdapter);
                 if ($result->isValid()) {
                     //all info about this user from the login table omit only the password
                     $userInfo = $authAdapter->getResultRowObject(null, 'password');
                     //the default storage is a session with namespace Zend_Auth
                     $authStorage = $auth->getStorage();
                     $authStorage->write($userInfo);
                     Application_Model_LoginAttempts::resetAttempts($_SERVER['REMOTE_ADDR']);
                     Application_Model_Subjects::resetLoginAttempts($username);
                     $tempSess = new Zend_Session_Namespace("referrer");
                     $tempSess->referrer = 'login';
                     $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;
                 }
             }
         }
     }
     $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;
     if (isset($CC_CONFIG['demo'])) {
         $this->view->demo = $CC_CONFIG['demo'];
     }
 }