/**
  * This method logs in the user
  * Member login
  * @author Kashif Irshad
  * @param string $userName
  * @param string $password in md5 encryption
  * @return string return 'success' for successfully login and all other messages are error message 
  */
 public function login($userName, $password, $remember)
 {
     $userTable = new Application_Model_DbTable_User();
     $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
     $authAdapter->setTableName('users');
     $authAdapter->setIdentityColumn('username');
     $authAdapter->setCredentialColumn('password');
     $authAdapter->setIdentity($userName);
     $authAdapter->setCredential($password);
     $authAdapter->setAmbiguityIdentity(true);
     $auth = Zend_Auth::getInstance();
     $auth->setStorage(new Zend_Auth_Storage_Session('user'));
     $result = $auth->authenticate($authAdapter);
     if ($result->isValid()) {
         if ($remember > 0) {
             $oneMinute = 60;
             $oneHour = $oneMinute * 60;
             $oneDay = $oneHour * 24;
             $oneWeek = $oneDay * 7;
             $oneMonth = $oneDay * 30;
             Zend_Session::rememberMe($oneWeek);
         }
         return 'success';
     } else {
         $userRow = $userTable->fetchRow("username='******'");
         if (isset($userRow)) {
             return 'Invalid password';
         } else {
             return 'Invalid username or password';
         }
     }
 }
Exemple #2
0
 public function loginAction()
 {
     $form = new Form_AuthLogin();
     $form->setAction($this->_helper->url($this->getRequest()->getActionName()));
     $auth = $this->getHelper('Auth')->getAuth();
     if (!$auth->hasIdentity()) {
         if ($this->getRequest()->isPost()) {
             if ($form->isValid($this->getRequest()->getPost())) {
                 $auth = $this->getHelper('Auth')->getAuth();
                 $authAdapter = new Model_Auth_Adapter_User($form->getValue('username'), $form->getValue('password'));
                 $result = $auth->authenticate($authAdapter);
                 if ($result->isValid()) {
                     if ($form->getValue('rememberMe')) {
                         // can configure in config
                         // use resources.session.remember_me_seconds
                         Zend_Session::rememberMe();
                     }
                     $this->_redirect('/');
                 } else {
                     $form->addErrorMessage('authError');
                 }
             }
         }
         $this->view->form = $form;
     }
 }
 public function indexAction()
 {
     $this->view->login = false;
     // проверка не залогинен ли пользователь
     if (!Zend_Auth::getInstance()->getIdentity()) {
         // берем форму логина и закидываем во view
         $form = $this->_getLoginForm();
         $this->view->form = $form;
         // если форма была отправлена, мы должны еЄ проверить
         if ($this->_request->isPost()) {
             $formData = $this->_request->getPost();
             // провер¤ем форму
             if ($form->isValid($formData)) {
                 // провер¤ем входные данные
                 $result = $this->_authenticate($form->getValue('realm'), $form->getValue('username'), $form->getValue('password'));
                 if ($result->isValid()) {
                     // запомним пользовател¤ на 2 недели
                     if ($form->getValue('rememberMe')) {
                         Zend_Session::rememberMe(60 * 60 * 24 * 14);
                     }
                     // отправл¤ем на главную
                     $this->_redirect('/');
                 } else {
                     // failure: выводим сообщение о ошибке
                     $this->view->error = 'Authorization error. Please check login or/and password';
                 }
             } else {
                 $form->populate($formData);
             }
         }
     } else {
         $this->view->login = true;
         $this->view->username = Zend_Auth::getInstance()->getIdentity();
     }
 }
Exemple #4
0
 public function loginAction()
 {
     $this->_form = new Mybase_Form_Login();
     if (!$this->getRequest()->isPost()) {
         $this->view->form = $this->_form;
     } else {
         $form = $this->_form;
         if (!$form->isValid($_POST)) {
             $this->view->form = $form;
             $this->_flash('Všechna pole musí být vyplněna', 'error', false);
         } else {
             $values = $form->getValues();
             $auth = Zend_Auth::getInstance();
             $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table_Abstract::getDefaultAdapter(), 'user_login', 'username', 'password', 'MD5(?)');
             $modelAccount = new Model_Account();
             $idaccount = $modelAccount->getId($this->_request->account);
             $select = $authAdapter->getDbSelect();
             $select->where('idaccount = ' . $idaccount);
             $authAdapter->setIdentity($values['username']);
             $authAdapter->setCredential($values['password']);
             $result = $auth->authenticate($authAdapter);
             switch ($result->getCode()) {
                 case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
                     $this->view->form = $form;
                     $this->_flash('Špatné uživatelské jméno', 'error', false);
                     break;
                 case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
                     $this->view->form = $form;
                     $this->_flash('Špatné heslo', 'error', false);
                     break;
                 case Zend_Auth_Result::SUCCESS:
                     $storage = $auth->getStorage();
                     $storage->write($authAdapter->getResultRowObject(array('email', 'name', 'surname', 'username', 'iduser', 'owner', 'administrator')));
                     if ($form->getValue('remember') == 1) {
                         Zend_Session::rememberMe(60 * 60 * 24 * 14);
                     }
                     //$this->_redirect('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);
                     $this->_redirect('/');
                     break;
                 case Zend_Auth_Result::FAILURE:
                     $this->view->form = $form;
                     $this->_flash('Neznámá chyba (FAILURE)', 'error', false);
                     break;
                 case Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS:
                     $this->view->form = $form;
                     $this->_flash('"Nejednoznačné"', 'error', false);
                     break;
                 case Zend_Auth_Result::FAILURE_UNCATEGORIZED:
                     $this->view->form = $form;
                     $this->_flash('Neznámá chyba(FAILURE_UNCATEGORIZED)', 'error', false);
                     break;
                 default:
                     $this->view->form = $form;
                     $this->_flash('Neznámá chyba (default)', 'error', false);
                     break;
             }
         }
     }
     $this->_helper->layout->disableLayout();
 }
 /**
  * check if email or password exists in database
  * @param array post data
  */
 protected function _checkAccount($post)
 {
     $login = new User_Model_Login();
     $loginStatus = array();
     $emailStatus = false;
     $passwordStatus = false;
     $adapter = $this->_getAuthAdapter();
     $adapter->setIdentity($post['user-email'])->setCredential($post['password']);
     require_once APPLICATION_PATH . '/../library/Zend/Auth.php';
     $auth = Zend_auth::getInstance();
     $result = $auth->authenticate($adapter);
     if ($result->isValid()) {
         //login successful
         Zend_Session::start();
         $user = $adapter->getResultRowObject();
         $auth->getStorage()->write($user);
         $user_session = new Zend_Session_Namespace('Zend_Auth');
         $user_session->email = Zend_Auth::getInstance()->getStorage()->read()->email;
         Zend_Session::rememberMe();
         $this->redirect('index/index');
     } else {
         if ($result->getCode() == Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND) {
             $this->view->loginStatus = '帳號不存在';
         } else {
             if ($result->getCode() == Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID) {
                 $this->view->loginStatus = '密碼錯誤';
             } else {
                 $this->view->loginStatus = '請重新登入';
             }
         }
     }
 }
 /**
  * Perform login against OneLogin API
  */
 public function loginAction()
 {
     // Clear identity before logging in
     if (Zend_Auth::getInstance()->hasIdentity()) {
         Zend_Auth::getInstance()->clearIdentity();
         Zend_Session::destroy(true);
     }
     // Proceed to logging in
     if ($this->_request->isPost()) {
         $username = $this->_request->getPost('username');
         $password = $this->_request->getPost('password');
         try {
             // create instance
             $login = new OneLogin_Acl_Login();
             $login->login($username, $password);
             $expirationTime = 60 * 60 * 8;
             // 8 hours
             Zend_Session::rememberMe($expirationTime);
             $this->_helper->layout->enableLayout();
             return $this->_helper->redirector('ol', 'index', 'users');
         } catch (Exception $e) {
             //print_r($e);
             $msg = $e->getMessage();
             $this->view->message = $msg;
             $this->render('index');
         }
     } else {
         $this->_forward("index");
     }
 }
 public function loginAction()
 {
     $loginForm = new Form_Login();
     $resetForm = new Form_ResetPassword();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $loginForm->isValid($request->getPost());
         $adapter = new Infra_AuthAdapter($request->getPost('email'), $request->getPost('password'), $request->getPost('timezone_offset'));
         //$adapter = new Zend_Auth_Adapter_DbTable($zendDb);
         $auth = Infra_AuthHelper::getAuthInstance();
         $result = $auth->authenticate($adapter);
         if ($result->isValid()) {
             // Zend_Session::getSaveHandler()->write(uniqid(), $result->getIdentity());
             if ($request->getPost('remember_me')) {
                 Zend_Session::rememberMe(60 * 60 * 24 * 7);
             }
             // 1 week
             $nextUri = $this->_getParam('next_uri');
             KalturaLog::debug("next uri {$nextUri}");
             if ($nextUri && strlen($nextUri) > 1) {
                 $this->_helper->redirector->gotoUrl($nextUri);
             } else {
                 $this->_helper->redirector('list-by-user', 'partner');
             }
         } else {
             $loginForm->setDescription('invalid login');
         }
     }
     $loginForm->setDefault('next_uri', $this->_getParam('next_uri'));
     // set in Infra_AuthPlugin
     $this->view->loginForm = $loginForm;
     $this->view->resetForm = $resetForm;
     $this->render('login');
 }
 public static function signIn($userName, $password, $rememberMe = false, $md5 = true)
 {
     $retVal = false;
     // set ZendX_Doctrine_Auth_Adapter
     $auth = Zend_Auth::getInstance();
     $authAdapter = new ZendX_Doctrine_Auth_Adapter(Doctrine::getConnectionByTableName('Model_Entity_User'));
     $password = $md5 ? md5($password) : $password;
     $authAdapter->setTableName('Model_Entity_User u')->setIdentityColumn('userName')->setCredentialColumn('password')->setCredentialTreatment('? AND active = 1')->setIdentity($userName)->setCredential($password);
     // set Zend_Auth
     $result = $auth->authenticate($authAdapter);
     // Check Auth Validation
     if ($result->isValid()) {
         // Remove some fields which are secure!
         $omitColumns = array('password', 'activationKey', 'created_at', 'updated_at', 'deleted_at', 'created_by', 'updated_by');
         $identity = $authAdapter->getResultRowObject(null, $omitColumns);
         $identity->roles = Kebab_Model_User::getUserRoles($identity->id);
         $identity->acl = new Kebab_Access_Acl();
         $identity->stories = Kebab_Model_Story::getUserStoriesName($identity->roles);
         $auth->getStorage()->write($identity);
         if ($rememberMe) {
             Zend_Session::rememberMe(604800);
         }
         $retVal = true;
     }
     return $retVal;
 }
Exemple #9
0
 public function loginAction()
 {
     $loginForm = new Form_Login();
     $resetForm = new Form_ResetPassword();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $adapter = new Kaltura_AuthAdapter($request->getPost('email'), $request->getPost('password'));
         $auth = Zend_Auth::getInstance();
         $result = $auth->authenticate($adapter);
         if ($result->isValid()) {
             if ($request->getPost('remember_me')) {
                 Zend_Session::rememberMe(60 * 60 * 24 * 7);
             }
             // 1 week
             $nextUri = $this->_getParam('next_uri');
             if ($nextUri) {
                 $this->_helper->redirector->gotoUrl($nextUri);
             } else {
                 $this->_helper->redirector('list', 'partner');
             }
         } else {
             $loginForm->setDescription('login error');
         }
     }
     $loginForm->setDefault('next_uri', $this->_getParam('next_uri'));
     // set in Kaltura_AuthPlugin
     $this->view->loginForm = $loginForm;
     $this->view->resetForm = $resetForm;
     $this->render('login');
 }
Exemple #10
0
 public function indexAction()
 {
     $registry = Zend_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     $config = $registry->get("config");
     $sessionConfig = $config['resources']['session'];
     Ml_Model_AntiAttack::loadRules();
     $credential = Ml_Model_Credential::getInstance();
     $logger = Ml_Model_Logger::getInstance();
     if ($auth->hasIdentity()) {
         return $this->_forward("goback");
     }
     $request = $this->getRequest();
     $form = $credential->loginForm();
     if (Ml_Model_AntiAttack::ensureHuman()) {
         $ensureHuman = true;
     } else {
         $ensureHuman = false;
     }
     if ($request->isPost()) {
         ignore_user_abort(true);
         //A way to sign in only if captcha is right. This is a workaround to
         //signout if the captcha is wrong.
         //
         //I've decided to put the sign in code in the validator itself,
         //but couldn't find a way to make the password validator
         //load after the captcha one (but to let it come first in code,
         //and that's ugly on the screen) and get a result if the
         //validation worked. Notice that it is only useful when
         //the captcha is required.
         if ($form->isValid($request->getPost())) {
             //@see below
             $session = Ml_Model_Session::getInstance();
             //rememberMe and ForgetMe already regenerates the ID
             if ($form->getElement("remember_me")->isChecked()) {
                 Zend_Session::rememberMe($sessionConfig['cookie_lifetime']);
             } else {
                 Zend_Session::ForgetMe();
             }
             $session->associate($auth->getIdentity(), Zend_Session::getId());
             $logger->log(array("action" => "login", "username" => $form->getValue("username")));
             $this->_forward("goback");
         } else {
             //@see above
             if ($auth->hasIdentity()) {
                 $auth->clearIdentity();
             }
             $logger->log(array("action" => "login_denied", "username" => $form->getValue("username")));
             $this->view->errorlogin = true;
         }
         //@end of workaround
     }
     $challenge = $form->getElement("challenge");
     //don't show missing value in the first time that asks for the captcha
     if (!$ensureHuman && is_object($challenge)) {
         $challenge->setErrorMessages(array("missingValue" => ''));
     }
     $this->view->loginform = $form;
 }
Exemple #11
0
    public function loginAction()
    {
        // Don't allow logged in people here
        $user = Zend_Auth::getInstance()->getIdentity();
        if ($user !== null) {
            $this->_redirect('/');
        }

        $this->view->title = 'Log in';
        if ($this->_request->isPost()) {
            // collect the data from the user
            $f = new Zend_Filter_StripTags();
            $username = $f->filter($this->_request->getPost('handle'));
            $password = $f->filter($this->_request->getPost('password'));

            if (empty($username) || empty($password)) {
                $this->addErrorMessage('Please provide a username and password.');
            } else {
                // do the authentication
                $authAdapter = $this->_getAuthAdapter($username, $password);
                $auth   = Zend_Auth::getInstance();
                $result = $auth->authenticate($authAdapter);

                if ($result->isValid()) {
                    $auth->getStorage()->write($authAdapter->getResult());

                    // Receive Zend_Session_Namespace object
                    $session = new Zend_Session_Namespace('Zend_Auth');
                    // Set the time of user logged in
                    $session->setExpirationSeconds(24*3600);

                    // If "remember" was marked
                    if ($this->getRequest()->getParam('rememberme') !== null) {
                        // remember the session for 604800s = 7 days
                        Zend_Session::rememberMe(604800);
                    }

                    $ns = new Zend_Session_Namespace('lastUrl');
                    $lastUrl = $ns->value;
                    if ($lastUrl !== '') {
                        $ns->value = '';

                        // If our last request was an tester ajax request just
                        // go back to /tester
                        $lastUrl = (strpos($lastUrl,'/tester/ajax') === false) ? $lastUrl : '/tester';

                        $this->_redirect($lastUrl);
                    }

                    $this->_redirect('/');
                } else {
                    // failure: clear database row from session
                    $this->addErrorMessage('Login failed.');
                }
            }
        } else {
            $this->getResponse()->setHeader('HTTP/1.1', '403 Forbidden');
        }
    }
 /**
  * Login user
  *
  */
 public function kloginAction()
 {
     $this->_helper->getHelper('viewRenderer')->setNoRender();
     $this->_helper->getHelper('layout')->disableLayout();
     $response = array();
     $request = $this->getRequest();
     /**
      * Redirect to dashboard if user has logged in already
      */
     if ($request->isPost()) {
         $username = $request->getPost('u');
         $password = $request->getPost('p');
         $remember = $request->getPost('s');
         $authMan = new Pandamp_Auth_Manager($username, $password);
         $authResult = $authMan->authenticate();
         $zendAuth = Zend_Auth::getInstance();
         if ($zendAuth->hasIdentity()) {
             if ($authResult->isValid()) {
                 $returnUrl = base64_decode($request->getPost('r'));
                 if (!empty($returnUrl)) {
                     if (strpos($returnUrl, '?')) {
                         $sAddition = '&';
                     } else {
                         $sAddition = '?';
                     }
                     $data = array('success' => true, 'msg' => 'Logging in', 'message' => "{$returnUrl}" . $sAddition . "PHPSESSID=" . Zend_Session::getId());
                     Pandamp_Lib_Formater::writeLog();
                     // to help thwart session fixation/hijacking
                     // @modifiedDate 2014-09-15 17:01
                     if (isset($remember) && $remember == 'yes') {
                         /*$hol = new Pandamp_Core_Hol_Auth();
                         		$hol->user = $username;
                         		$hol->user_pw = $password;
                         		$hol->save_login = $remember;
                         		$hol->login_saver();*/
                         // remember the session for 604800s = 7 days
                         Zend_Session::rememberMe(604800);
                     } else {
                         // do not remember the session
                         // Zend_Session::forgetMe();
                     }
                     $this->_helper->FlashMessenger('Successful authentication');
                 }
             } else {
                 if ($authResult->getCode() != -51) {
                     Zend_Auth::getInstance()->clearIdentity();
                 }
                 $messages = $authResult->getMessages();
                 $data = array('error' => $messages[0], 'success' => false);
             }
         } else {
             $messages = $authResult->getMessages();
             $data = array('error' => $messages[0], 'failure' => true);
         }
     }
     $this->getResponse()->setBody(Zend_Json::encode($data));
 }
 public function loginAction()
 {
     $this->view->translate()->setLocale(isset($_GET['locale']) ? $_GET['locale'] : 'ru');
     $this->view->resource = $this->_request->getParam('resource');
     $this->view->headTitle($this->view->translate('Login page'));
     $this->view->headLink()->appendStylesheet(array('rel' => 'shortcut icon', 'type' => 'image/x-icon', 'href' => '/img/favicon.ico'));
     $this->view->headLink()->appendStylesheet('/modules/auth/css/login.css');
     if ($this->_request->isPost()) {
         //			file_put_contents('d:\\temp\\auth.txt', var_export($this->_request->getParams(), true));
         $filter = new Zend_Filter_StripTags();
         $username = $filter->filter($this->_request->getParam('username'));
         $password = $filter->filter($this->_request->getParam('password'));
         $woredir = $this->_request->getParam('woredir');
         if ($woredir) {
             $this->getHelper('viewRenderer')->setNoRender();
             $this->getHelper('layout')->disableLayout();
         }
         if (empty($username)) {
             $this->_response->setHttpResponseCode(401);
             // Unauthorized
             if ($woredir) {
                 echo 'Please, provide a username.';
             } else {
                 $this->view->message = 'Please, provide a username.';
             }
             //$this->view->translate('Please provide a username.');
         } else {
             Zend_Session::start();
             if (Uman_Auth::login($username, $password)) {
                 Zend_Session::rememberMe();
                 $auth = Zend_Auth::getInstance();
                 $identity = $auth->getIdentity();
                 $ns = new Zend_Session_Namespace('acl');
                 $ns->acl = new Uman_Acl($identity->NODEID, $identity->PATH);
                 if ($woredir) {
                     echo 'OK';
                 } else {
                     $this->_redirect($this->_request->getParam('resource', '/'));
                 }
             } else {
                 $this->_response->setHttpResponseCode(401);
                 // Unauthorized
                 Zend_Session::destroy();
                 if ($woredir) {
                     echo 'Authorization error. Please, try again.';
                 } else {
                     $this->view->message = $this->view->translate('Authorization error. Please, try again.');
                 }
             }
         }
     } else {
         if (Zend_Session::sessionExists()) {
             Zend_Session::start();
             Zend_Session::destroy();
         }
     }
 }
 protected function _user2Login()
 {
     // php array to object
     $data = (object) ($arr = array('id' => 1001, 'login' => 'user2', 'role_id' => 2, 'role_name' => 'operator_role'));
     // write session
     $auth = Zend_Auth::getInstance();
     $storage = $auth->getStorage();
     $storage->write($data);
     Zend_Session::rememberMe();
     echo ' (login as ' . $data->login . ') ';
 }
Exemple #15
0
 /**
  * Login user
  *
  * @param array $data
  * @return bool
  */
 public function login($data)
 {
     if ($this->authenticate($data['login'], $data['password'])) {
         $user = $this->getDbTable()->getByLogin($data['login']);
         $user->login();
         if (!empty($data['rememberMe'])) {
             Zend_Session::rememberMe(60 * 60 * 24 * 14);
         }
         return true;
     }
     return false;
 }
Exemple #16
0
 /**
  * Prepares the environment before running a test.
  */
 protected function setUp()
 {
     parent::setUp();
     // session begin
     $this->restoreNamespace = new Zend_Session_Namespace(self::RESTORE_NAME_SPACE);
     $this->restoreNamespace->setExpirationSeconds($this->ttl_restore_session);
     Zend_Session::rememberMe($this->ttl_restore_session);
     // запоминаем данные в сессии
     $this->restoreNamespace->typeRestore = 'restore';
     $this->restoreNamespace->JobId = $this->jobid;
     $this->restoreNamespace->JobHash = md5($this->jobid);
     $this->WbTmpTable = new WbTmpTable(md5($this->jobid), $this->ttl_restore_session);
 }
Exemple #17
0
 /**
  * Validate the form
  *
  * @param  array $data
  * @return boolean
  */
 public function isValid($data)
 {
     $valid = parent::isValid($data);
     if ($valid) {
         $session = new Zend_Session_Namespace('Zend_Auth');
         if ((bool) $this->getValue('remember_me')) {
             Zend_Session::rememberMe();
         } else {
             $session->setExpirationSeconds($this->_loginLifetime);
         }
     }
     return $valid;
 }
Exemple #18
0
 public function login($login = '******', $password = '', $remember = false)
 {
     self::$_authAdapter->setIdentity($login)->setCredentialColumn('password')->setCredentialTreatment("CONCAT(MD5(CONCAT(?,SUBSTRING_INDEX(`password`,':',-1))),':',SUBSTRING_INDEX(`password`,':',-1))")->setCredential($password);
     $auth = Zend_Auth::getInstance();
     if ($auth->authenticate(self::$_authAdapter)->isValid()) {
         if ($remember) {
             Zend_Session::rememberMe(60 * 60 * 24 * 7);
         }
         return true;
     } else {
         self::$_authAdapter->setIdentity('guest')->setCredential('');
         $auth->authenticate(self::$_authAdapter);
     }
     return false;
 }
 public function authenticate($email, $password)
 {
     $filter = new Zend_Validate_StringLength(array('min' => 5, 'max' => 25));
     if (!empty($password) && !$filter->isValid($password)) {
         $this->setMessage('password', 'Password non valida. La lunghezza della password deve essere compresa fra 5 e 25 caratteri');
         return false;
     }
     if ($this->_user_entity->loginByEmailAndPassword($email, $password) === true) {
         $storage = $this->_user_entity->getResultRowObject(array('id', 'email'));
         $storage->name = $storage->email;
         Zend_Session::rememberMe(60 * 60 * 24 * 7 * 2);
         Zend_Auth::getInstance()->getStorage()->write($storage);
         return true;
     }
     return false;
 }
Exemple #20
0
 public function login($email, $password, $remember = false)
 {
     $auth = Zend_Auth::getInstance();
     $adapter = new Zend_Auth_Adapter_DbTable(Zend_Registry::get('db'), 'user', 'email', 'password', 'MD5(?)');
     $adapter->setIdentity($email);
     $adapter->setCredential($password);
     $result = $auth->authenticate($adapter);
     if ($result->getCode() == Zend_Auth_Result::SUCCESS) {
         $identity = $adapter->getResultRowObject(null, 'password');
         if ((bool) $remember === true) {
             Zend_Session::rememberMe(365 * 24 * 60 * 60);
         }
         $auth->getStorage()->write($identity);
         return (int) $identity->id;
     }
     return false;
 }
Exemple #21
0
 /**
  * Authenticate a user
  *
  * @param  array $data Matched pair array containing email/password
  * @return boolean
  */
 public function authenticate($data)
 {
     $adapter = $this->getAuthAdapter($data);
     $auth = $this->getAuth();
     $result = $auth->authenticate($adapter);
     if (!$result->isValid()) {
         return false;
     }
     if ($data['save-login']) {
         Zend_Session::rememberMe();
     } else {
         Zend_Session::forgetMe();
     }
     $user = $this->_userModel->findByEmail($data['email']);
     $auth->getStorage()->write($user->toArray());
     return true;
 }
Exemple #22
0
 public function loginAction()
 {
     $this->flashMessenger = $this->_helper->FlashMessenger;
     $this->view->messages = $this->flashMessenger->getMessages();
     //        if (Zend_Registry::getInstance()->get('auth')->hasIdentity()) {
     //            $this->_redirect('/painel');
     //        }
     // action body
     if ($this->getRequest()->isPost()) {
         $email = $this->_request->getPost('email');
         $senha = $this->_request->getPost('pass');
         $url = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
         try {
             $_serviceAuth = new AuthService();
             $result = $_serviceAuth->login($email, $senha);
             if (isset($result['error'])) {
                 //login invalido
                 $this->_helper->flashMessenger->addMessage('Login ou senha incorreta');
                 $this->_redirect('/acesso/');
             } else {
                 //login válido
                 $usuario = new Usuarioacl();
                 $usuario->setFullName($result['nome']);
                 $usuario->setEmail($result['email']);
                 $usuario->setRoleId($result['user_type']);
                 $usuario->setRoleLabel($result['user_type']);
                 $usuario->setId($result['id']);
                 $usuario->setResources($result['resources']);
                 $auth = Zend_Auth::getInstance();
                 $storage = $auth->getStorage();
                 $storage->write($usuario);
                 $seconds = 10 * 365 * 24 * 60 * 60;
                 Zend_Session::rememberMe($seconds);
                 //                     print_r($url);
                 //                     die();
                 //                     echo '<pre>';
                 //                     print_r($url);die;
                 $this->_redirect('/dashboard/perfil/');
             }
         } catch (Exception $exc) {
             //                echo $exc->getTraceAsString();
             throw $exc;
         }
     }
 }
 public function loginAction()
 {
     if (vkNgine_Auth::isAuthenticated()) {
         header("location:/");
         exit;
     }
     $logger = Zend_Registry::get('logger');
     $form = $this->getLoginForm();
     $request = $this->getRequest();
     $this->view->error = false;
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $info = $form->getValues();
             $user = null;
             if (vkNgine_Public_Auth::attemptLogin($info)) {
                 $user = vkNgine_Auth::revalidate();
             } else {
                 $this->view->error = true;
             }
             $user = vkNgine_Auth::revalidate();
             $logger->log('LOGIN_REQUEST', print_r($info, true), vkNgine_Log::INFO, $user['userId']);
             if ($user != null) {
                 $modelUsers = new Model_Users();
                 $modelTrafficActivity = new vkNgine_Log_Activity();
                 $modelTrafficLogins = new vkNgine_Log_Logins();
                 $modelTrafficActivity->processActivity($user, $request, 'Logged in to Site');
                 $modelTrafficLogins->insertTrafficLogin($user->userId, $user->type);
                 $config = vkNgine_Config::getSystemConfig();
                 Zend_Session::rememberMe($config->settings->login->remember);
                 $modelUsers->update($user['userId'], array('lastLogin' => date('Y-m-d H:i:s')));
                 echo Zend_Json::encode(array('success' => 1, 'icon' => 'success', 'href' => '/'));
                 exit;
             } else {
                 echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Access denied!'), 'icon' => 'error'));
                 exit;
             }
         } else {
             echo Zend_Json::encode(array('title' => $this->t->_('Error Message'), 'message' => $this->t->_('Access denied!'), 'icon' => 'error'));
             exit;
         }
     }
     $this->view->form = $form;
 }
Exemple #24
0
 public function login()
 {
     $auth = Zend_Auth::getInstance();
     // 设了namespace,获取时也需使用同样的new一遍
     //$storage = new Zend_Auth_Storage_Session('lds-namespace');
     $storage = new Zend_Auth_Storage_Session();
     $namespace = $storage->getNamespace();
     //$storage->setExpirationHops(5);
     //$storage->setExpirationSeconds(3);
     //$storage->write('123');
     $auth->setStorage($storage);
     //Zend_Debug::dump($storage,'s');
     //$s = $auth->getStorage($storage);
     //$abs = $s->read();
     //Zend_Debug::dump($abs,'abs');
     $db = Zend_Registry::get('db');
     $authAdapter = new Zend_Auth_Adapter_DbTable($db);
     // ::todo::
     $authAdapter->setTableName('lds0019_users')->setIdentityColumn('username')->setCredentialColumn('password');
     $user = $this->_user;
     $userDB = new Database_User($db);
     $password = $userDB->getSafePassword($this->_password, $user);
     $authAdapter->setIdentity($user)->setCredential($password);
     // 执行认证查询,并保存结果
     //$result = $authAdapter->authenticate();
     $result = $auth->authenticate($authAdapter);
     if (!$result->isValid()) {
         // Authentication failed; print the reasons why
         $this->_message = $result->getMessages();
         $this->_result = false;
     } else {
         $identity = $result->getIdentity();
         //Zend_Debug::dump($identity);
         $storage = $auth->getStorage();
         $storage->write($authAdapter->getResultRowObject(array('username', 'user_id')));
         // set a cookie to save user info
         setcookie('ue', $user, time() + 2592000, '/', false);
         // ::todo::
         Zend_Session::rememberMe(2592000);
         $this->_result = true;
     }
     return $this->_result;
 }
Exemple #25
0
 /**
  * ACL Login
  *
  * @param string $email
  * @param string $password
  * @return Zend_Auth_Result | boolean
  */
 public static function fastlogin($email, $password, $rememberMe = false)
 {
     if (!empty($email) && !empty($password)) {
         $adapter = new Shineisp_Auth_Adapter_Doctrine(Doctrine_Manager::connection()->getTable("AdminUser"), "email", "password");
         $adapter->setCredential($password);
         $adapter->setIdentity($email);
         if ($rememberMe) {
             // remember the session for 604800s = 7 days
             Zend_Session::rememberMe(604800);
         } else {
             // do not remember the session
             Zend_Session::forgetMe();
         }
         $auth = Zend_Auth::getInstance();
         $auth->setStorage(new Zend_Auth_Storage_Session('admin'));
         return $auth->authenticate($adapter);
     } else {
         return false;
     }
 }
 /**
  * Authenticates with Erfurt using the provided credentials.
  */
 public function loginAction()
 {
     $erfurt = $this->_owApp->erfurt;
     $post = $this->_request->getPost();
     $this->_helper->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     // If remember option is on make session persistent
     if (!empty($post['login-save']) && $post['login-save'] == 'on') {
         // Make session persistent (for about 23 years)
         Zend_Session::rememberMe(726364800);
     }
     $loginType = $post['logintype'];
     // lokaler Login
     if ($loginType === 'locallogin') {
         $username = $post['username'];
         $password = $post['password'];
         $authResult = $erfurt->authenticate($username, $password);
     } else {
         if ($loginType === 'openidlogin') {
             // OpenID
             $username = $post['openid_url'];
             $redirectUrl = $post['redirect-uri'];
             $verifyUrl = $this->_config->urlBase . 'application/verifyopenid';
             $authResult = $erfurt->authenticateWithOpenId($username, $verifyUrl, $redirectUrl);
         } else {
             if ($loginType === 'webidlogin') {
                 // FOAF+SSL
                 $redirectUrl = $this->_config->urlBase . 'application/loginfoafssl';
                 $authResult = $erfurt->authenticateWithFoafSsl(null, $redirectUrl);
             } else {
                 // Not supported...
                 return;
             }
         }
     }
     // reload selected model w/ new privileges
     if ($this->_owApp->selectedModel instanceof Erfurt_Rdf_Model) {
         $this->_owApp->selectedModel = $erfurt->getStore()->getModel((string) $this->_owApp->selectedModel);
     }
     $this->_owApp->authResult = $authResult->getMessages();
 }
Exemple #27
0
 public function loginAction()
 {
     $goto = $this->getRequest()->getParam('goto');
     if (@$this->_me) {
         if ($goto) {
             $this->_redirect("/{$goto}");
         } else {
             $this->redirect("/track");
         }
     }
     $this->view->goto = $goto;
     if ($this->getRequest()->isPost()) {
         //Get form data from post array
         $data = $this->_request->getPost();
         if ($data['email'] == '' || $data['password'] == '') {
             $this->view->error = "Please provide your email address and password.";
             return false;
         }
         //Log user in to session
         $users = new Users();
         $auth = Zend_Auth::getInstance();
         $authAdapter = new Zend_Auth_Adapter_DbTable($users->getAdapter(), 'users');
         $authAdapter->setIdentityColumn('email')->setCredentialColumn('password');
         $authAdapter->setIdentity($data['email'])->setCredential(sha1($data['password']));
         $result = $auth->authenticate($authAdapter);
         if ($result->isValid()) {
             Zend_Session::rememberMe(31536000);
             $credentials = base64_encode(serialize(array('email' => $data['email'], 'password' => sha1($data['password']))));
             //Set login cookie
             setcookie('autl', $credentials, time() + 31536000, '', '.' . $_SERVER['HTTP_HOST']);
             $storage = new Zend_Auth_Storage_Session();
             $storage->write($authAdapter->getResultRowObject());
             $this->_redirect($data['goto']);
         } else {
             $this->view->error = "Invalid email or password. Please try again.";
         }
     }
 }
 /**
  * Start the session, using the session settings from application.ini and dots.xml
  * @access public
  * @static
  * @return void
  */
 public static function start()
 {
     $option = Zend_Registry::get('option');
     $config = Zend_Registry::get('configuration');
     //check is a session exists for the current module
     if (isset($option->session)) {
         $namespaceName = $option->session->name;
         //if session is not registered, create it
         if (!Zend_Registry::isRegistered('session')) {
             $session = new Zend_Session_Namespace($namespaceName);
             // set session options
             Zend_Session::setOptions($config->resources->session->toArray());
             if (!isset($session->initialized)) {
                 $session->initialized = true;
                 // use only session cookie and regenerate session in the same time
                 Zend_Session::rememberMe($config->resources->session->remember_me_seconds);
             }
             Zend_Registry::set('session', $session);
         }
     } else {
         Zend_Registry::set('session', null);
     }
 }
Exemple #29
0
 /**
  * @brief   authenticateUser method - authenticates a given user with given password
  * @param   string $username: user name
  * @param   string $password: submitted plain text password
  * @return  TRUE or FALSE
  * 
  * Authenticates the given user with the given password and sets the authentication
  * singleton to its new state. Authentication is carried out using HASHing (using given
  * hash) and SALTing.
  */
 public function authenticateUser($username, $password, $remember = false)
 {
     // first check if username or password are missing
     if (!$username) {
         throw new Exception('Username not given.');
     } else {
         if (!$password) {
             throw new Exception('Password not given.');
         }
     }
     // set username and password
     $this->_userAdapter->setIdentity($username);
     $this->_userAdapter->setCredential($password);
     // check authentification using the adapter
     $result = $this->_userAdapter->authenticate();
     if ($result->isValid()) {
         // store user table row in auth object, but suppress password
         $row = $this->_userAdapter->getResultRowObject(null, 'password');
         // get ip and user agent
         $row->ip = $this->getRemoteAddr();
         $row->userAgent = $this->getUserAgent();
         // get role and status
         $row->status = $this->getStatus($row->status_id);
         $row->role = $this->getRole($row->role_id);
         // get the auth singleton and its storage and store the row
         $storage = Zend_Auth::getInstance()->getStorage();
         $storage->write($row);
         // extend login to two weeks, i.e. 1209600 s
         if ($remember) {
             // extend lifetime of the clients cookie
             Zend_Session::rememberMe(1209600);
             // extent the lifetime of the session in the database
             $saveHandler = Zend_Session::getSaveHandler();
             $saveHandler->setLifetime(1209600, true);
         }
         return true;
     } else {
         return false;
     }
 }
Exemple #30
0
 public function loginAction()
 {
     if (!is_admin_theme()) {
         $referer = rtrim($_SERVER['HTTP_REFERER'], '/');
         $master = rtrim(MASTER_URL, '/');
         $login = $master . '/users/login';
         if (isset($_SERVER['HTTP_REFERER']) && is_integer(strpos($referer, $master)) && $referer != $master && $referer != $login && !strpos($referer, '/users/activate')) {
             $session = new Zend_Session_Namespace();
             $session->redirect = $_SERVER['HTTP_REFERER'];
         }
     }
     // require_once is necessary because lacking form autoloading.
     require_once APP_DIR . '/forms/Login.php';
     $loginForm = new Omeka_Form_Login();
     $loginForm = apply_filters('login_form', $loginForm);
     $this->view->form = $loginForm;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if ($loginForm instanceof Zend_Form && !$loginForm->isValid($_POST)) {
         return;
     }
     User::upgradeHashedPassword($loginForm->getValue('username'), $loginForm->getValue('password'));
     $authAdapter = new Omeka_Auth_Adapter_UserTable($this->_helper->db->getDb());
     $pluginBroker = $this->getInvokeArg('bootstrap')->getResource('Pluginbroker');
     // If there are no plugins filtering the login adapter, set the
     // credentials for the default adapter.
     if (!$pluginBroker || !$pluginBroker->getFilters('login_adapter')) {
         $authAdapter->setIdentity($loginForm->getValue('username'))->setCredential($loginForm->getValue('password'));
     } else {
         $authAdapter = apply_filters('login_adapter', $authAdapter, array('login_form' => $loginForm));
     }
     $authResult = $this->_auth->authenticate($authAdapter);
     if (!$authResult->isValid()) {
         if ($log = $this->_getLog()) {
             $ip = $this->getRequest()->getClientIp();
             $log->info("Failed login attempt from '{$ip}'.");
         }
         $this->_helper->flashMessenger($this->getLoginErrorMessages($authResult), 'error');
         return;
     }
     if ($loginForm && $loginForm->getValue('remember')) {
         // Remember that a user is logged in for the default amount of
         // time (2 weeks).
         Zend_Session::rememberMe();
     } else {
         // If a user doesn't want to be remembered, expire the cookie as
         // soon as the browser is terminated.
         Zend_Session::forgetMe();
     }
     $session = new Zend_Session_Namespace();
     if ($session->redirect) {
         $this->_helper->redirector->gotoUrl($session->redirect);
     } else {
         $this->_helper->redirector->gotoUrl('/');
     }
 }