public function favorite()
 {
     header('Content-Type: application/json');
     $u = new User();
     $data = $this->post();
     $pageID = (int) $this->get('id');
     $p = \Page::getByID($pageID);
     if ($u->getUserID() && !$p->isError() && $p->isSystemPage() == false) {
         //If user favorited remove entry else add entry
         $db = Database::get();
         $res = $db->GetRow("SELECT mpRelationID as rel FROM MultilingualPageRelations WHERE cID=?", array($pageID));
         $relation = $res['rel'];
         // var_dump($relation);
         // $res = $db->GetAll("SELECT cID FROM MultilingualPageRelations WHERE mpRelationID=?",array($relation));
         // var_dump($res);
         // if($res['rel'])
         // $res = $db->GetRow("SELECT Count(fav.cID) as num FROM MultilingualPageRelations mppr LEFT JOIN UserPageFavorites fav ON mppr.cID = fav.cID where uID = ? and mpRelationID = ?",array((int)$u->getUserID(),$rel));
         $res = $db->GetRow("SELECT Count(cID) as num FROM UserPageFavorites WHERE uID=? and cID in (SELECT cID FROM MultilingualPageRelations WHERE mpRelationID=?)", array((int) $u->getUserID(), $relation));
         // var_dump($res);
         if ($res['num'] > 0) {
             //Favorite Product
             $db->Execute('DELETE FROM UserPageFavorites WHERE cID in (SELECT cID FROM MultilingualPageRelations WHERE mpRelationID=?) and uID=?', array($relation, (int) $u->getUserID()));
             echo json_encode(array('status' => 'unfavorited'));
         } else {
             //Unfavorite Product
             $db->Execute('INSERT INTO UserPageFavorites(cID,uID) VALUES(?,?)', array($pageID, (int) $u->getUserID()));
             echo json_encode(array('status' => 'favorited'));
         }
         exit;
     } else {
         echo json_encode(array('status' => 'not_logged'));
     }
 }
示例#2
0
 public function check(User $ux)
 {
     if (preg_match('/a|e|i|o|u/i', $ux->getUsername())) {
         return true;
     }
     return false;
 }
 public function findMyAlerts(User $user)
 {
     $entity = $user->getUserInfoObject()->getEntityObject();
     $query = $this->getEntityManager()->createQuery('select na, n from Concrete\\Core\\Entity\\Notification\\NotificationAlert na join na.notification n where na.naIsArchived = false and na.user = :user order by n.nDate asc');
     $query->setParameter('user', $entity);
     $result = $query->getResult();
     return $result;
 }
 public function view()
 {
     $defaultMessage = t('Your user account is being upgraded and requires a new password. Please enter your email address below to create this now.');
     $resetMessage = \Core::make('config/database')->get(self::PASSWORD_RESET_MESSAGE_KEY, $defaultMessage);
     $this->set('resetMessage', $resetMessage);
     $user = new User();
     $this->set('disableForm', !$user->isSuperUser());
 }
示例#5
0
 public function completeAuthentication(User $u)
 {
     $ui = \UserInfo::getByID($u->getUserID());
     if (!$ui->hasAvatar()) {
         try {
             $image = \Image::open($this->getExtractor()->getImageURL());
             $ui->updateUserAvatar($image);
         } catch (\Imagine\Exception\InvalidArgumentException $e) {
             \Log::addNotice("Unable to fetch user images in Google Authentication Type, is allow_url_fopen disabled?");
         } catch (\Exception $e) {
         }
     }
     return parent::completeAuthentication($u);
 }
 private function validateUser()
 {
     // check to see if this is a valid user account
     $user = new User();
     if (!$user->checkLogin()) {
         $isActive = $user->isActive();
         $user->logout();
         if ($user->isError()) {
             switch ($user->getError()) {
                 case USER_SESSION_EXPIRED:
                     return Redirect::to('/login', 'session_invalidated')->send();
             }
         } elseif (!$isActive) {
             return Redirect::to('/login', 'account_deactivated')->send();
         } else {
             $v = new View('/frontend/user_error');
             $v->setViewTheme('concrete');
             $contents = $v->render();
             return $this->app->make(ResponseFactoryInterface::class)->forbidden($contents);
         }
     }
 }
 /**
  * Initialize localization.
  */
 private function setSystemLocale()
 {
     $u = new User();
     $lan = $u->getUserLanguageToDisplay();
     $loc = Localization::getInstance();
     $loc->setContextLocale('ui', $lan);
 }
示例#8
0
 public function verifyAuthTypeCookie()
 {
     if ($_COOKIE['ccmAuthUserHash']) {
         list($_uID, $authType, $uHash) = explode(':', $_COOKIE['ccmAuthUserHash']);
         $at = AuthenticationType::getByHandle($authType);
         $u = User::getByUserID($_uID);
         if (!is_object($u) || $u->isError()) {
             return;
         }
         if ($at->controller->verifyHash($u, $uHash)) {
             User::loginByUserID($_uID);
         }
     }
 }
示例#9
0
 public function changePassword($newPassword)
 {
     $db = Loader::db();
     if ($this->uID) {
         $dh = Loader::helper('date');
         $dateTime = $dh->getOverridableNow();
         $v = array($this->getUserObject()->getUserPasswordHasher()->HashPassword($newPassword), $dateTime, $this->uID);
         $q = "update Users set uPassword = ?, uLastPasswordChange = ?  where uID = ?";
         $r = $db->prepare($q);
         $res = $db->execute($r, $v);
         $ue = new \Concrete\Core\User\Event\UserInfoWithPassword($this);
         $ue->setUserPassword($newPassword);
         $currentUser = new User();
         $session = Core::make('session');
         if ($currentUser->isLoggedIn() && $currentUser->getUserID() == $session->get('uID')) {
             $session->set('uLastPasswordChange', $dateTime);
         }
         Events::dispatch('on_user_change_password', $ue);
         return $res;
     }
 }
示例#10
0
 public function submit()
 {
     if ($this->validateAction()) {
         $comments = $this->request->request('comments');
         $comments = is_string($comments) ? trim($comments) : '';
         if ($comments === '' && $this->app->make('config')->get('concrete.misc.require_version_comments')) {
             return Response::create(t('Please specify the version comments'), 400);
         }
         $c = $this->page;
         $u = new User();
         $v = CollectionVersion::get($c, "RECENT");
         $v->setComment($_REQUEST['comments']);
         $pr = new PageEditResponse();
         if (($this->request->request->get('action') == 'publish' || $this->request->request->get('action') == 'schedule') && $this->permissions->canApprovePageVersions()) {
             $e = $this->checkForPublishing();
             $pr->setError($e);
             if (!$e->has()) {
                 $pkr = new ApprovePagePageWorkflowRequest();
                 $pkr->setRequestedPage($c);
                 $pkr->setRequestedVersionID($v->getVersionID());
                 $pkr->setRequesterUserID($u->getUserID());
                 $u->unloadCollectionEdit($c);
                 if ($this->request->request->get('action') == 'schedule') {
                     $dateTime = new DateTime();
                     $publishDateTime = $dateTime->translate('check-in-scheduler');
                     $pkr->scheduleVersion($publishDateTime);
                 }
                 if ($c->isPageDraft()) {
                     $pagetype = $c->getPageTypeObject();
                     $pagetype->publish($c, $pkr);
                 } else {
                     $pkr->trigger();
                 }
             }
         } else {
             if ($this->request->request->get('action') == 'discard') {
                 if ($c->isPageDraft() && $this->permissions->canDeletePage()) {
                     $u = new User();
                     $cID = $u->getPreviousFrontendPageID();
                     $this->page->delete();
                     $pr->setRedirectURL(DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $cID);
                     $pr->outputJSON();
                 } else {
                     if ($v->canDiscard()) {
                         $v->discard();
                     }
                 }
             } else {
                 $v->removeNewStatus();
             }
         }
         $nc = Page::getByID($c->getCollectionID(), $v->getVersionID());
         $u->unloadCollectionEdit();
         $pr->setRedirectURL(Loader::helper('navigation')->getLinkToCollection($nc, true));
         $pr->outputJSON();
     }
 }
示例#11
0
文件: Pile.php 项目: ceko/concrete5-1
 /**
  * @return bool
  */
 public function isMyPile()
 {
     $u = new User();
     if ($u->isRegistered()) {
         return $this->getUserID() == $u->getUserID();
     }
 }
 /**
  * Test user authentication status.
  *
  * @param \User $u
  *
  * @return bool Returns true if user is authenticated, false if not
  */
 public function isAuthenticated(User $u)
 {
     return $u->isLoggedIn();
 }
示例#13
0
 public function remove_locale_section()
 {
     if (!$this->token->validate('remove_locale_section')) {
         $this->error->add($this->token->getErrorMessage());
     }
     $u = new User();
     if (!$u->isSuperUser()) {
         $this->error->add(t("Only the super user may remove a multilingual section."));
     }
     $service = new Service($this->entityManager);
     /**
      * @var $locale Locale
      */
     $locale = $service->getByID($this->post('siteLocaleID'));
     if (!is_object($locale)) {
         $this->error->add(t("Invalid locale object."));
     }
     if (!$this->error->has()) {
         $service->delete($locale);
         $this->flash('success', t('Section removed.'));
         $this->redirect('/dashboard/system/multilingual/setup', 'view');
     }
     $this->view();
 }
示例#14
0
 public function setPropertiesFromArray($arr)
 {
     return parent::setPropertiesFromArray($arr);
 }
示例#15
0
 /**
  * @param null|int $requesterUID
  * @return bool
  */
 function triggerDeactivate($requesterUID = null)
 {
     if ($requesterUID === null) {
         $u = new User();
         $requesterUID = $u->getUserID();
     }
     $db = $this->connection;
     $v = array($this->getUserID());
     $pkr = new ActivateUserWorkflowRequest();
     $pkr->setRequestAction('deactivate');
     $pkr->setRequestedUserID($this->getUserID());
     $pkr->setRequesterUserID($requesterUID);
     $pkr->trigger();
     $this->uIsActive = intval($db->GetOne('select uIsActive from Users where uID = ?', $v));
     return $this->isActive() == 0;
 }