Example #1
0
 /**
  * Logout
  */
 function indexAction()
 {
     $this->_helper->viewRenderer->setNoRender(true);
     session_start();
     $auth = Zend_Auth::getInstance();
     $infoUser = $auth->getIdentity();
     // staus OFF
     $timeON = date('Y-m-d H:i:s');
     $model_employee = Front_Model_Employee::getInstance();
     $model_employee->updateOnLogin($infoUser->id, $timeON, 'OFF');
     $model_employee->compareOffLogin();
     //clear cookies
     $this->_myCookie = new Myapp_Auth_Storage_Cookie($this->_dirApp['cookie_name'], $this->_dirApp['secretsalt']);
     $this->_myCookie->clear();
     // clear session
     $auth->clearIdentity();
     unset($this->_userInfo->username);
     session_unset();
     session_destroy();
     session_write_close();
     setcookie(session_name(), '', 0, '/');
     setcookie($this->_dirApp['cookie_name'], '', 0, '/');
     //session_regenerate_id(true);
     $this->_redirect($this->_dirApp['base_url']);
 }
Example #2
0
 /**
  * Ham khoi tao
  * @see Zend_Controller_Action::init()
  */
 function init()
 {
     $auth = Zend_Auth::getInstance();
     $this->_userInfo = $auth->getIdentity();
     $this->_dirApp = Zend_Registry::get('dirApp')->toArray();
     $this->view = Myapp_View_Smarty::getInstance();
     $this->view->setView($this->_dirApp['template_front'] . $this->_dirApp['style'] . '/');
     $smarty = $this->view->getEngine();
     $smarty->compile_dir = $this->_dirApp['template_front_cache'];
     $viewRenderer = $this->_helper->getHelper('viewRenderer');
     $viewRenderer->setView($this->view)->setViewBasePathSpec($smarty->template_dir)->setViewScriptPathSpec(':controller/:action.:suffix')->setViewScriptPathNoControllerSpec(':action.:suffix')->setViewSuffix($this->_dirApp['template_extension']);
     $this->_base_url = $this->_dirApp['base_url'];
     $this->view->assign('base_url', $this->_base_url);
     $this->view->assign('base_tpl', $this->_dirApp['base_tpl']);
     // 2015
     $this->_model = Front_Model_Employee::getInstance();
     $this->_module = $this->_getParam('module');
     $this->_control = $this->_getParam('controller');
     $action = $this->_getParam('action');
     $this->view->assign('form', array('module' => $this->_module, 'control' => $this->_control, 'action' => $action, 'lang' => $_SESSION['lang']));
     $this->_lable = Zend_Registry::get('lable');
     $this->view->assign('lable', $this->_lable);
     if (empty($this->_userInfo->adminId)) {
         $this->_redirect($this->_base_url . 'login/');
     }
     if ($this->_userInfo->adminId != '') {
         $file_name = $this->_dirApp['dir_auth'] . $this->_userInfo->adminLogin . '.ini';
         $sessionAuth = Myapp_File_Createauth::getInstance()->compareSession($file_name);
         if ($sessionAuth == true) {
             $this->_redirect($this->_base_url . 'logout/');
         }
     }
     $this->view->assign('userInfo', $this->_userInfo);
 }
Example #3
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c();
     }
     return self::$instance;
 }
Example #4
0
    function indexAction()
    {
        Zend_Session::start();
        $breadcrumb = '<li><a href="' . $this->_dirApp['base_url'] . '">' . $this->_lable['home']['value'] . '</a></li>
				<li class="active">' . $this->_lable['sign_in']['value'] . '</li>';
        $this->view->assign('breadcrumb', $breadcrumb);
        $seo['title'] = $this->_lable['sign_in_title']['value'];
        $this->view->assign('seo', $seo);
        $model = Front_Model_Employee::getInstance();
        /*
        $link = $this->_dirApp['base_url'].$this->control.'/confirm/';
        $sign_activation = sprintf(stripslashes($this->_lable['signin_activation_note']['value']), $link);
        $this->view->assign('sign_activation', $sign_activation);
        */
        $_SESSION['referer'] = empty($_SESSION['referer']) ? $_SERVER['HTTP_REFERER'] : $_SESSION['referer'];
        $arr = explode('/', $_SESSION['referer']);
        if (in_array('login', $arr) || in_array('login', $arr)) {
            $_SESSION['referer'] = '';
        }
        if (!empty($this->_userInfo->adminId)) {
            $refe_link = empty($_SESSION['referer']) ? $this->_dirApp['base_url'] : $_SESSION['referer'];
            $this->_redirect($refe_link);
        }
        $data = $this->_getParam('data');
        $username = trim($data['username']);
        $password = trim($data['password']);
        $remember = $this->_getParam('remember');
        $current_link = $this->_dirApp['base_url'] . $this->control . "/?lang=";
        $this->view->assign('current_link', $current_link);
        if ($this->_request->isPost() && !empty($username) && !empty($password)) {
            $master_db = Zend_Registry::get('master_db');
            $auth = Zend_Auth::getInstance();
            $authAdapter = new Zend_Auth_Adapter_DbTable($master_db);
            $authAdapter->setTableName('panpic_admin')->setIdentityColumn('adminLogin')->setCredentialColumn('adminPass');
            $authAdapter->setIdentity($username);
            $authAdapter->setCredential(md5($password));
            $select = $authAdapter->getDbSelect();
            $select->where('adminAvail = 1');
            $result = $auth->authenticate($authAdapter);
            $flag = 0;
            if ($result->isValid()) {
                $data = $authAdapter->getResultRowObject(null);
                //(null, array('password'))
                $auth->getStorage()->write($data);
                $infoUser = $auth->getIdentity();
                //set member on/off
                $model->updateOnLogin($infoUser->adminId, date('Y-m-d H:i:s'));
                //$model->compareOffLogin();
                $username = $infoUser->adminLogin;
                if ($remember == 1) {
                    //set cookie
                    $cookieValue = $infoUser->adminId . ';' . $username . ';' . $infoUser->adminPass;
                    //if localhost no set domain
                    if (strpos($_SERVER['HTTP_HOST'], '.') !== false) {
                        $cookieDomain = $_SERVER['HTTP_HOST'];
                        $this->_myCookie->setDomain($cookieDomain);
                    }
                    $this->_myCookie->write($cookieValue);
                }
                // write file ini session
                $session_id = session_id();
                $file_name = $this->_dirApp['dir_auth'] . $username . '.ini';
                Myapp_File_Createauth::getInstance()->fwrite_stream($file_name, $session_id);
                $flag = 1;
            }
            if ($flag == 1) {
                $infoUser = $auth->getIdentity();
                $client_ip = Myapp_Myapplication::getInstance()->get_client_ip();
                $log_event = array('emp_id' => $infoUser->emp_id, 'ip' => $client_ip);
                $model->insertLog($log_event);
                $model->updateLastLogin($infoUser->adminId);
                $refe_link = empty($_SESSION['referer']) ? $this->_dirApp['base_url'] : $_SESSION['referer'];
                $this->_redirect($refe_link);
            } else {
                $model->cond = " WHERE adminLogin='******' AND adminPass='******' ";
                $row = $model->getByCond();
                if (!empty($row['adminLogin'])) {
                    if ($row['avail'] == 0) {
                        $this->view->assign('alert', 'danger');
                        $this->view->assign('msg', $this->_lable['account_disable_note']['value']);
                        $this->_helper->viewRenderer('index');
                        return;
                    } else {
                        $this->view->assign('alert', 'danger');
                        $msg = sprintf($this->_lable['acount_noconfirm']['value'], $this->_dirApp['base_url'] . 'signin/confirm/');
                        $this->view->assign('msg', stripslashes($msg));
                        $this->_helper->viewRenderer('index');
                        return;
                    }
                } else {
                    $this->view->assign('alert', 'danger');
                    $this->view->assign('msg', $this->_lable['sign_in_error']['value']);
                    $this->_helper->viewRenderer('index');
                    return;
                }
            }
        }
    }