Пример #1
0
 /**
  * Controller constructor.
  * @param bool $isAuthenticated
  * @param null $roleNames
  */
 public function __construct($isAuthenticated = false, $roleNames = null)
 {
     Browsing::setBrowsingId();
     PageMenu::setPageMenu();
     if (Authentication::isAuthenticated()) {
         Authentication::setUserEntity();
         if ($roleNames != null && !Authentication::hasRoles($roleNames)) {
             $this->redirectToUrlFromAction('main', 'no-access');
         }
     } else {
         Authentication::unsetUserEntity();
         if ($isAuthenticated) {
             $this->redirectToUrlFromAction('account', 'login');
         }
     }
 }
Пример #2
0
 /**
  *
  */
 public static function createBrowsingView()
 {
     (new BrowsingViewDAO())->createBrowsingView(Browsing::getBrowsingId());
 }
Пример #3
0
 /**
  * POST: /account/register
  */
 public function registerPost()
 {
     $model = new AccountRegisterModel(Language::$REGISTER[Config::$LANGUAGE], true);
     if ($model->validation) {
         $userDAO = new UserDAO();
         $hasUser = $userDAO->hasUser($model->email);
         if (!$hasUser) {
             $uniqueId = $userDAO->createUser($model->email, $model->password);
             $userEntity = $userDAO->getUserWithRolesByUniqueId($uniqueId);
             $roleDAO = new RoleDAO();
             if ($userDAO->countUsers() == 0) {
                 $roleDAO->addedRoleToUser('admin', $userEntity->id);
             }
             $roleDAO->addedRoleToUser('user', $userEntity->id);
             (new BrowsingDAO())->addedBrowsingToUser($userEntity->id, Browsing::getBrowsingId());
             if (Config::$SMTP) {
                 //Send email for confirm email address
                 (new Email())->send($model->email, Language::$CONFIRM_EMAIL[Config::$LANGUAGE], Language::$CONFIRM_EMAIL[Config::$LANGUAGE] . ' http://' . $_SERVER['SERVER_NAME'] . '/account/confirm-email/' . $uniqueId);
             }
             Authentication::signIn($uniqueId);
             parent::redirectToUrlFromArray(explode('/', $model->url));
         }
         $model->emailValidation = Language::$DUPLICATE_EMAIL[Config::$LANGUAGE];
         $model->validation = false;
     }
     parent::view(new Register(), $model);
 }
Пример #4
0
 /**
  * POST: /main/create-comment
  */
 public function createCommentPost()
 {
     $pageId = $_REQUEST['PageId'];
     $commentId = $_REQUEST['CommentId'];
     $body = $_REQUEST['Body'];
     $pageDAO = new PageDAO();
     $page = $pageDAO->getPage($pageId);
     if ($page->feedbackType != PageEntity::$FEEDBACK_COMMENTS_AUTH || Authentication::isAuthenticated()) {
         $captcha = true;
         if ($page->feedbackType == PageEntity::$FEEDBACK_COMMENTS_CAPTCHA && !Authentication::isAuthenticated()) {
             $captcha = Captcha::getCaptcha($commentId) == $_REQUEST['Captcha'];
         }
         if ($captcha) {
             $commentId = $commentId == 0 ? null : $commentId;
             $browsingId = Browsing::getBrowsingId();
             $userId = Authentication::isAuthenticated() ? Authentication::getUserEntity()->id : null;
             $commentOnPageDAO = new CommentOnPageDAO();
             $newCommentId = $commentOnPageDAO->createCommentOnPage($pageId, $commentId, $browsingId, $userId, $body);
             $newComment = $commentOnPageDAO->getCommentOnPage($newCommentId);
             echo CommentOnPageHelper::comment($newComment, $page->feedbackType);
         } else {
             echo 'captcha';
         }
     }
 }