Пример #1
0
 public function loginAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $identity = Zend_Auth::getInstance()->getIdentity();
         if ($identity->role == 'superadmin') {
             $this->_redirect('admin/dashboard');
         } elseif ($identity->role == 'admin') {
             $this->_redirect('wep/dashboard');
         } elseif ($identity->role == "user") {
             $this->_redirect('wep/dashboard');
         } elseif ($identity->role == "groupadmin") {
             $this->_redirect('group/dashboard');
         }
     }
     $request = $this->getRequest();
     $form = new User_Form_User_Login();
     if ($request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $authAdapter = $this->getAuthAdapter();
             $username = $form->getValue('username');
             $password = $form->getValue('password');
             $authAdapter->setIdentity($username)->setCredential($password);
             $auth = Zend_Auth::getInstance();
             $result = $auth->authenticate($authAdapter);
             if ($result->isvalid()) {
                 // check if user account has been disable
                 $model = new User_Model_DbTable_User();
                 $user = $model->getUserByUsername($username);
                 if (!$user['status']) {
                     if ($auth->hasIdentity()) {
                         $auth->clearIdentity();
                     }
                     $this->_helper->FlashMessenger->addMessage(array('error' => 'Your account has been disabled.' . ' Please contact the system administrator'));
                     $this->_redirect('/');
                 }
                 $identity = $authAdapter->getResultRowObject(null, 'password');
                 //getting role from table role and merging it with $authAdapter->getResultRowObject()
                 // [adding role to identity]
                 $rolevalue = new User_Model_DbTable_Role();
                 $role = $rolevalue->getRoleById($identity->role_id);
                 $obj2 = new stdClass();
                 $obj2->role = $role['role'];
                 $identity = (object) array_merge((array) $identity, (array) $obj2);
                 $authStorage = $auth->getStorage();
                 $authStorage->write($identity);
                 $accModel = new User_Model_DbTable_Account();
                 $account = $accModel->getAccountRowByUserName('account', 'id', $identity->account_id);
                 $simplified = new Zend_Session_Namespace('simplified');
                 $simplified->simplified = $account->simplified;
                 $this->_helper->FlashMessenger->addMessage(array('message' => 'Successfully Logged In'));
                 if ($identity->role == 'superadmin') {
                     $this->_redirect('admin/dashboard');
                 } elseif ($identity->role == 'admin') {
                     $this->_redirect('wep/dashboard');
                 } elseif ($identity->role == 'user') {
                     $this->_redirect('wep/dashboard');
                 } elseif ($identity->role == 'groupadmin') {
                     $this->_redirect('group/dashboard');
                 }
             } else {
                 $this->_helper->FlashMessenger->addMessage(array('error' => 'Username or password did not match.'));
             }
             //$this->_redirect('/');
         } else {
             $this->_helper->FlashMessenger->addMessage(array('error' => 'Username or password did not match.'));
             //$this->_redirect('/');
         }
     }
     $this->view->form = $form;
 }