public function registerAction()
 {
     if (Site_Service_Auth::getInstance()->isLoggedIn()) {
         $this->redirect('/');
         return;
     }
     $this->view->formWarning = '';
     $isPost = $this->getRequest()->isPost();
     $authService = Site_Service_Auth::getInstance();
     if ($authService->isLoggedIn()) {
         $this->view->formWarning = "Вы уже зарегистрированы на сайте";
     }
     $from = $this->getRequest()->getParam('from');
     $this->view->formWarning = '';
     if (!$this->isGoodFromUrl($from)) {
         $from = '/';
     }
     $this->view->from = $from;
     $form = new Site_Form_Auth_Register();
     $form->getElement('from')->setValue($from);
     if ($isPost && $form->isValid($this->getRequest()->getPost())) {
         $userRecord = array('login' => $form->getValue('login'), 'email' => $form->getValue('email'), 'display_name' => $form->getValue('display_name'), 'password' => $form->getValue('password'), 'role_id' => Site_Acl::ROLE_ID_MEMBER);
         $userModel = new Site_Model_User();
         $userModel->insert($userRecord);
         $login = $userRecord['login'];
         Site_Service_Auth::getInstance()->loginAs($login);
         $this->redirect($from);
         return;
     }
     $this->view->form = $form;
 }
Exemple #2
0
 public function preDispatch()
 {
     parent::preDispatch();
     $navigation = Site_Service_Menu::getInstance()->getNavigation();
     $controller = $this->getRequest()->getControllerName();
     $module = $this->getRequest()->getModuleName();
     $url = $this->getRequest()->getPathInfo();
     $page = $navigation->findOneByUri($url);
     $this->view->currentPage = $page;
     if ($page) {
         $page->setActive(true);
     }
     if ($page && !empty($page->resource)) {
         $resource = $page->resource;
     } else {
         $resource = Site_Acl::RESOURCE_PUBLIC;
     }
     // Проверяем, авторизован ли пользователь
     $role = Site_Service_Auth::getInstance()->getUser()->getRole();
     $acl = Site_Acl::getInstance();
     // К этим 2 контроллерам доступ есть всегда
     if ($controller != 'error' && $controller != 'auth' && $module == 'default') {
         $allowed = $acl->isAllowed($role, $resource);
         if (!$allowed) {
             $url = $this->getRequest()->getRequestUri();
             if (Site_Service_Auth::getInstance()->isLoggedIn()) {
                 $this->forward('deny', 'error');
             } else {
                 $this->redirect('auth/login?from=' . urlencode($url) . '&warn=1');
             }
             return;
         }
     }
     // Меню
     $this->view->navigation($navigation);
     $this->view->navigation()->setAcl($acl)->setRole($role);
     // login
     $this->view->loggedUser = Site_Service_Auth::getInstance()->getUser();
 }
Exemple #3
0
 public static function getInstance()
 {
     return self::$instance ? self::$instance : (self::$instance = new self());
 }