public function logoutAction() { $authenticate = $this->getServiceLocator()->get('MyAuth'); $authenticate->logout(); $infoObj = new \ZendVN\System\Info(); $infoObj->destroyInfo(); $this->redirect()->toRoute('homeShop'); }
public function onInit(MvcEvent $e) { $routerMatch = $e->getRouteMatch(); $arrayController = explode("\\", $routerMatch->getParam("controller")); $module = strtolower($arrayController[0]); $viewModel = $e->getViewModel(); $this->_mainParam['module'] = strtolower($arrayController[0]); $this->_mainParam['controller'] = strtolower($arrayController[2]); $this->_mainParam['action'] = strtolower($routerMatch->getParam("action")); //truyền ra cho layout $viewModel->params = array("module" => strtolower($arrayController[0]), "controller" => strtolower($arrayController[2]), "action" => strtolower($routerMatch->getParam("action"))); $config = $this->getServiceLocator()->get("config"); $layout = $config["module_for_layouts"][strtolower($arrayController[0])]; //set layout $this->layout($layout); $infoObj = new \ZendVN\System\Info(); //KIEM TRA USER AuTH if ($this->_mainParam['module'] == 'admin') { //chưa đăng nhập if (!$this->identity()) { return $this->redirect()->toRoute('homeShop'); } else { //đăng nhập rồi mà không có quyền vào $group_acp = $infoObj->getGroupInfo('group_acp'); if ($group_acp != 1) { return $this->redirect()->toRoute('homeShop'); } else { // KIEM TRA PERMISSION $aclObj = new Acl(); $role = $infoObj->getPermissionInfo()['role']; $privilegesOfRole = $infoObj->getPermissionInfo()['privileges']; $aclObj->addRole($role); $aclObj->allow($role, null, $privilegesOfRole); $privilegesOfArea = $this->_mainParam['module'] . "|" . $this->_mainParam['controller'] . "|" . $this->_mainParam['action']; if ($aclObj->isAllowed($role, null, $privilegesOfArea) == false) { return $this->goNoAccess(); } } } } //kiem tra controller user khong đăng nhập thi không được vào if ($this->_mainParam['controller'] == 'user' && $this->_mainParam['module'] == 'shop') { //chưa đăng nhập if (!$this->identity()) { return $this->redirect()->toRoute('homeShop'); } } // ------------------------------------------------------------ //func Init() giúp cho các controller extends có thể override onInit() $this->init(); }
<i class="fa fa-%s"></i> <span>%s</span> <i class="fa fa-angle-down pull-right"></i> </a> <ul class="treeview-menu">', $content['class'], $content['link'], $content['icon'], $content['text']); foreach ($contentSidebarChild[$content['class']] as $contentChild) { $xhtmlSidebar .= sprintf(' <li class="%s"><a href="%s"><i class="fa fa-%s"></i>%s</a></li>', $contentChild['class'], $contentChild['link'], $contentChild['icon'], $contentChild['text']); } $xhtmlSidebar .= "</ul></li>"; } else { $xhtmlSidebar .= sprintf('<li class="admin-%s"> <a href="%s"><i class="fa fa-%s"></i><span>%s</span></a> </li>', $content['class'], $content['link'], $content['icon'], $content['text']); } $infoObj = new \ZendVN\System\Info(); $userInfo = $infoObj->getUserInfo(); } ?> <section class="sidebar" style="height: auto;"> <div class="user-panel"> <div class="pull-left image"> <img src="<?php echo URL_PUBLIC . 'files/users/' . $userInfo->avatar; ?> " class="img-circle" alt="User Image"> </div> <div class="pull-left info"> <p><?php
<?php if (!$this->identity()) { $linkHome = $this->url("homeShop"); $arrContent = array(array("link" => $linkHome, "name" => "Home", "icon" => "fa-home", "action" => "index"), array("link" => $this->linkLogin(), "name" => "Login", "icon" => "fa-lock", "action" => "login"), array("link" => $this->linkRegister(), "name" => "Register", "icon" => "fa-user", "action" => "register")); } else { $linkHome = $this->url("homeShop"); $linkMyAccount = $this->url("shopRoute/default", array("controller" => "user", "action" => "index")); $arrContent = array(array("link" => $linkHome, "name" => "Home", "icon" => "fa-home", "action" => "index"), array("link" => $linkMyAccount, "name" => "MyAccount", "icon" => "fa-lock", "action" => "login"), array("link" => $this->linkHistory(), "name" => "MyHistory", "icon" => "fa-user", "action" => "register")); //them shortcut cpanel $infoObj = new \ZendVN\System\Info(); $group_acp = $infoObj->getGroupInfo('group_acp'); if ($group_acp == 1) { $linkAdmin = $this->url("shopRoute/default", array("controller" => "user", "action" => "admin")); $arrContent[] = array("link" => $linkAdmin, "name" => "ControlPanel", "icon" => "fa-user", "action" => ""); } $arrContent[] = array("link" => $this->linkLogout(), "name" => "Logout", "icon" => "fa-user", "action" => "register"); } $xhtml = ""; foreach ($arrContent as $content) { $class = ""; if ($this->params['action'] == $content['action']) { $class = "class='active'"; } $xhtml .= sprintf('<li><a %s href="%s"><i class="fa %s"></i>%s</a></li>', $class, $content['link'], $content['icon'], $content['name']); } ?> <div class="toprow"> <div class="container"> <div class="row"> <div class="col-sm-12">
public function logoutAction() { $authService = $this->getServiceLocator()->get('AuthenticateService'); $authService->clearIdentity(); $infoUser = new \ZendVN\System\Info(); $infoUser->destroyInfo(); $this->redirect()->toUrl('/'); return $this->getResponse(); }
public function onInit(MvcEvent $e) { //GET MODULE - CONTROLLER - ACTION $this->_arrParam = $this->params()->fromRoute(); $routeMatch = $e->getRouteMatch(); $controllerArray = explode('\\', $routeMatch->getParam('controller')); $this->_params['module'] = strtolower($controllerArray[0]); $this->_params['controller'] = strtolower($controllerArray[2]); $this->_params['action'] = $routeMatch->getParam('action'); $viewModel = $e->getApplication()->getMvcEvent()->getViewModel(); $viewModel->module = $this->_params['module']; $viewModel->controller = $this->_params['controller']; $viewModel->action = $this->_params['action']; //SET LAYOUT //$config = $this->getServiceLocator()->get('config'); //$this->layout($config['module_layouts'][$controllerArray[0]]); //CHECK PERMISSION $loggedStatus = $this->identity() ? true : false; if ($this->_params['module'] == 'admin' || $this->_params['module'] == 'user') { if ($loggedStatus == false && $this->_params['module'] == 'user') { $this->goLogin(); } if ($loggedStatus == false && $this->_params['module'] == 'admin') { $this->goLoginAdmin(); } $info = new \ZendVN\System\Info(); $groupAcp = $info->getGroupInfo('group_acp'); if ($loggedStatus == true && $groupAcp == 0) { $this->goNoAccess(); } $permission = $info->getPermission(); if ($permission['privileges'] != 'full') { $aclObj = new \ZendVN\System\Acl($permission['role'], $permission['privileges']); if ($aclObj->isAllowed($this->_params) == false) { $this->goNoAccess(); } } } else { if ($this->_params['module'] == 'user') { if ($this->_params['controller'] == 'account' && $loggedStatus == false) { $this->goLogin(); } } } //KIỂM TRA TIN BẤT ĐỘNG SẢN ĐĂNG if ($this->_params['controller'] == 'realestate' && $this->_params['action'] == 'detail') { $RealEstateTable = $this->getServiceLocator()->get('Home\\Model\\RealEstateTable'); $item = $this->getTable()->getItem($this->_arrParam); $hansudung = explode("/", $item['date_end']); //tính số ngày còn lại của tin đăng $month = !empty($hansudung[1]) ? $hansudung[1] : ''; $day = !empty($hansudung[0]) ? $hansudung[0] : ''; $year = !empty($hansudung[2]) ? $hansudung[2] : ''; $remain = ceil((mktime(0, 0, 0, $month, $day, $year) - time()) / 86400); //Nếu tin chưa kích hoạt, thời hạn đăng đã hết thì không thể xem được tin đó if (empty($item['type_news']) || $item['status'] != 5 || $remain <= 0) { //$this->goNoView(); } } //Kiểm tra bảo trì website if ($this->_params['module'] == 'home' || $this->_params['module'] == 'user') { $config = $this->getServiceLocator()->get('Admin\\Model\\ConfigTable'); $itemConfig = $config->getItem(array('id' => 1), array('task' => 'get-item')); $arrConfig = \Zend\Json\Json::decode($itemConfig->maintenance); if ($arrConfig->status == 1) { $this->goMaintenance(); } } //Cấm truy cập website(ban nick\ip) if ($this->_params['module'] == 'home' || $this->_params['module'] == 'user') { $flagBan = false; //Trường hợp thành viên đăng nhập(cấm nick) if (!empty($this->identity()->id)) { $userTable = $this->getServiceLocator()->get('Admin\\Model\\UserTable'); $itemBan = $userTable->getItem(array('id' => $this->identity()->id), array('task' => 'get-item-with-id')); if (!empty($itemBan)) { $flagBan = true; } } else { //Trường hợp cấm IP $ip = $_SERVER['REMOTE_ADDR']; $validator = new \Zend\Validator\Ip(); if ($validator->isValid($ip)) { $userTable = $this->getServiceLocator()->get('Admin\\Model\\UserTable'); $itemBan = $userTable->getItem(array('ip' => $ip), array('task' => 'get-item-with-ip')); if (!empty($itemBan)) { $flagBan = true; } } } if ($flagBan == true) { $this->goBanned(); } } //Kiểm tra trang doanh nghiệp có tồn tại không if ($this->_params['module'] == 'home' && $this->_params['controller'] == 'business') { if ($this->_params['action'] == 'detail' || $this->_params['action'] == 'landsale' || $this->_params['action'] == 'landforrent' || $this->_params['action'] == 'investors' || $this->_params['action'] == 'construction' || $this->_params['action'] == 'management' || $this->_params['action'] == 'design' || $this->_params['action'] == 'distributors' || $this->_params['action'] == 'contact' || $this->_params['action'] == 'department') { $businessTable = $this->getServiceLocator()->get('Home\\Model\\BusinessTable'); $item = $businessTable->getItem($this->_arrParam); if (empty($item)) { $this->goNotFoundPageBusiness(); } } } $this->init(); }