Example #1
0
function CheckAuthentication()
{
    if (User_Helper_Auth::hasIdentity()) {
        return true;
    }
    return false;
}
 public function init()
 {
     // Cache
     $frontEnd = array('lifetime' => null, 'automatic_serialization' => 'true');
     $backEnd = array('cache_dir' => CACHE_PATH . '/db');
     $this->_cache['db'] = Zend_Cache::factory('Core', 'File', $frontEnd, $backEnd);
     // Set data
     $this->view->adminUrl = BASE_URL . '/admin';
     $this->view->baseUrl = BASE_URL;
     $this->view->setTheme('admin');
     if (!User_Helper_Auth::hasIdentity()) {
         $this->setTemplate('module/user/admin/login');
     } else {
         // Set session
         $this->_session = Core_Session::getInstance();
         $this->view->username = $this->_session->get('username', 'auth');
     }
 }
 public function authAction()
 {
     $this->_noRender = true;
     $params = $this->_request['params'];
     if ($this->isAjax()) {
         $session = Core_Session::getInstance();
         $username = $params['username'];
         $password = $params['password'];
         if ($user = User_Helper_Auth::checkAuth($username, $password)) {
             // Update user login
             $user->last_login_ip = $this->getClientIp();
             $user->last_login = time();
             $user->save();
             $session->regenerateId();
             $session->set('username', $user->username, 'auth');
             $session->set('level', $user->level, 'auth');
             $session->set('user_agent', $_SERVER['HTTP_USER_AGENT'], 'auth');
             $session->set('ip', $_SERVER['REMOTE_ADDR'], 'auth');
             echo json_encode(array('success' => true));
         } else {
             echo json_encode(array('success' => false));
         }
     }
 }