Ejemplo n.º 1
0
 /**
  * Create $this->User object
  * that represents User whose profile
  * is being viewed currently
  *
  *
  * @throws \Lampcms\Lampcms404Exception
  * @return object $this
  */
 protected function getUser()
 {
     $uid = $this->Router->getSegment($this->uidSegment, 'i');
     $a = $this->Registry->Mongo->USERS->findOne(array('_id' => $uid));
     if (empty($a)) {
         throw new \Lampcms\Lampcms404Exception('@@User not found@@');
     }
     $this->User = User::userFactory($this->Registry, $a);
     $this->aPageVars['title'] = $this->User->getDisplayName();
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Increase or decrease owner's reputation
  * after his question or answer receives a vote
  *
  * @return object $this
  */
 protected function setOwnerReputation()
 {
     $uid = $this->Resource->getOwnerId();
     d('uid of resource owner: ' . $uid);
     /**
      * Now need to calculate points
      *
      */
     try {
         \Lampcms\User::userFactory($this->Registry)->by_id($uid)->setReputation($this->calculatePoints())->save();
     } catch (\Exception $e) {
         e($e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine());
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Create $this->User User object for user whose
  * profile is being edited
  *
  * @return object $this
  */
 protected function getUser()
 {
     $uid = !\Lampcms\Request::isPost() ? $this->Router->getSegment(1, 'i', 0) : $this->Request->get('uid', 'i', null);
     if ($uid && $uid !== $this->Registry->Viewer->getUid()) {
         /**
          * This is edit profile for another user
          * check Viewer permission here
          */
         $this->checkAccessPermission('edit_any_profile');
         $this->User = \Lampcms\User::userFactory($this->Registry)->by_id($uid);
     } else {
         $this->User = $this->Registry->Viewer;
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Decrease reputation of user who
  * owns the old answer
  *
  * @todo check current score and make sure
  *       it will not become negative after we deduct
  *       some points
  *
  * @return object $this
  */
 protected function updateOldAnswerer()
 {
     if (!empty($this->aOldAnswer)) {
         $uid = $this->aOldAnswer[Schema::POSTER_ID];
         if (!empty($uid)) {
             try {
                 \Lampcms\User::userFactory($this->Registry)->by_id($uid)->setReputation(0 - $this->Registry->Ini->POINTS->BEST_ANSWER)->save();
             } catch (\MongoException $e) {
                 e('unable to update reputation for old answerer ' . $e->getMessage());
             }
         }
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  *
  * Change role of Question or Answer poster
  * to 'Banned'
  *
  * @return $this;
  *
  */
 protected function banUser()
 {
     $ban = $this->Request->get('ban', 's', '');
     d('ban: ' . $ban);
     if (!empty($ban) && $this->checkAccessPermission('ban_user')) {
         $User = User::userFactory($this->Registry)->by_id($this->Resource->getOwnerId());
         $User->setRoleId('suspended');
         $User->save();
         $this->Registry->Dispatcher->post($User, 'onUserBanned');
     }
     return $this;
 }
Ejemplo n.º 6
0
 /**
  *
  * Create new record in USERS collection,
  *
  * @return object $this
  */
 protected function createNewUser()
 {
     $coll = $this->Registry->Mongo->USERS;
     $coll->ensureIndex(array(Schema::USERNAME_LOWERCASE => 1), array('unique' => true));
     /**
      * Cannot make email unique index because external users
      * don't have email, and then value counts as null
      * and multiple null values count as duplicate!
      *
      */
     $coll->ensureIndex(array(Schema::EMAIL => 1));
     $coll->ensureIndex(array(Schema::ROLE => 1));
     /**
      * Indexes for managing 3 types
      * of following
      */
     $coll->ensureIndex(array('a_f_t' => 1));
     $coll->ensureIndex(array('a_f_u' => 1));
     $coll->ensureIndex(array('a_f_q' => 1));
     $sid = Cookie::getSidCookie();
     if (false !== ($tzn = Cookie::get('tzn'))) {
         $timezone = $tzn;
     } else {
         $timezone = $this->Registry->Ini->SERVER_TIMEZONE;
     }
     $aData[Schema::USERNAME] = $this->username;
     $aData[Schema::USERNAME_LOWERCASE] = \mb_strtolower($this->username);
     $aData[Schema::EMAIL] = $this->email;
     $aData[Schema::SID] = false !== $sid ? $sid : \Lampcms\String::makeSid();
     $aData[Schema::ROLE] = $this->getRole();
     $aData[Schema::TIMEZONE] = $timezone;
     $aData[Schema::PASSWORD] = String::hashPassword($this->pwd);
     $aData[Schema::REGISTRATION_TIMESTAMP] = time();
     $aData[Schema::REGISTRATION_TIME] = date('r');
     $aData[Schema::FIRST_VISIT_TIMESTAMP] = false !== ($intFv = \Lampcms\Cookie::getSidCookie(true)) ? $intFv : time();
     $aData[Schema::LOCALE] = $this->Registry->Locale->getLocale();
     /**
      * Initial reputation is always 1
      *
      * @var int
      */
     $aData[Schema::REPUTATION] = 1;
     $aUser = \array_merge($this->Registry->Geo->Location->data, $aData);
     d('aUser: '******'new user _id: ' . $User['_id']);
     $this->processLogin($User);
     \Lampcms\PostRegistration::createReferrerRecord($this->Registry, $User);
     return $this;
 }
Ejemplo n.º 7
0
 /**
  * Create record of new user
  *
  * @return \Lampcms\User object User object
  */
 protected function createUser()
 {
     $sid = false === ($sid = Cookie::getSidCookie()) ? String::makeSid() : $sid;
     if (false !== ($tzn = Cookie::get('tzn'))) {
         $timezone = $tzn;
     } else {
         $timezone = $this->Registry->Ini->SERVER_TIMEZONE;
     }
     $aUser = array();
     $aUser[Schema::EMAIL] = $this->email;
     $aUser[Schema::REPUTATION] = 1;
     $aUser[Schema::REGISTRATION_TIMESTAMP] = time();
     $aUser[Schema::REGISTRATION_TIME] = date('r');
     $aUser[Schema::FIRST_VISIT_TIMESTAMP] = false !== ($intFv = Cookie::getSidCookie(true)) ? $intFv : time();
     $aUser[Schema::SID] = $sid;
     $aUser['google_id'] = (string) $this->userInfo['id'];
     $aUser['google_token'] = $this->token;
     if (!empty($this->userInfo['given_name'])) {
         $aUser[Schema::FIRST_NAME] = $this->userInfo['given_name'];
     }
     if (!empty($this->userInfo['family_name'])) {
         $aUser[Schema::LAST_NAME] = $this->userInfo['family_name'];
     }
     if (!empty($this->userInfo['locale'])) {
         $aUser[Schema::LOCALE] = $this->userInfo['locale'];
     }
     if (!empty($this->userInfo['link'])) {
         $aUser[Schema::URL] = $this->userInfo['link'];
     }
     if (!empty($this->userInfo['gender'])) {
         $aUser[Schema::GENDER] = 'male' === $this->userInfo['gender'] ? 'M' : 'F';
     }
     if (!empty($this->userInfo['name'])) {
         $username = $this->userInfo['name'];
     } elseif (!empty($this->userInfo['family_name'])) {
         $username = !empty($this->userInfo['family_name']);
         if (!empty($this->userInfo['family_name'])) {
             $username = '******' . $this->userInfo['family_name'];
         }
     }
     $oEA = \Lampcms\ExternalAuth::factory($this->Registry);
     $username = $oEA->makeUsername($username);
     $aUser[Schema::USERNAME] = $username;
     $aUser[Schema::USERNAME_LOWERCASE] = \mb_strtolower($username);
     $aUser[Schema::ROLE] = Role::EXTERNAL_USER;
     $aUser[Schema::TIMEZONE] = $timezone;
     $aUser[Schema::EXTERNAL_AVATAR] = $this->userInfo['picture'] . '?sz=50';
     $aUser = \array_merge($this->Registry->Geo->Location->data, $aUser);
     d('creating new googlge aUser: '******'new user _id: ' . $User['_id']);
     \Lampcms\PostRegistration::createReferrerRecord($this->Registry, $User);
     try {
         $this->createEmailRecord($User['_id']);
     } catch (\Lampcms\DevException $e) {
         e('Unable to create email record: ' . $e->getMessage());
     }
     $this->addContacts($User->getUid());
     $this->Registry->Dispatcher->post($User, 'onNewUser');
     return $User;
 }
Ejemplo n.º 8
0
 /**
  * Change user's user_group_id to registered
  * and set validation_time to now in EMAILS record
  *
  * @throws \Lampcms\NoticeException
  * @throws \Lampcms\Exception
  * @return object $this
  */
 protected function activateUser()
 {
     $aUser = $this->Registry->Mongo->USERS->findOne(array(Schema::PRIMARY => (int) $this->aEmail['i_uid']));
     if (empty($aUser)) {
         throw new \Lampcms\Exception('@@Unable to find user, please create a new account@@');
     }
     $this->oActivatedUser = User::userFactory($this->Registry, $aUser);
     $role = $this->oActivatedUser->getRoleId();
     /**
      * If User's role is NOT 'unactivated' then
      * throw an exception
      */
     if (false === \strstr($role, 'unactivated')) {
         throw new \Lampcms\NoticeException('@@This account has already been activated@@');
     }
     $this->oActivatedUser->activate()->save();
     /**
      * Now IF Viewer is actually the user that was just activated
      * we must also update the Viewer!
      * If we don't then the Viewer object is not updated
      * and the Viewer in session is still unactivated
      */
     if ($this->Registry->Viewer->equals($this->oActivatedUser)) {
         $this->processLogin($this->oActivatedUser);
     }
     $this->Registry->Dispatcher->post($this->oActivatedUser, 'onUserActivated');
     $this->aEmail['i_vts'] = time();
     $this->Registry->Mongo->EMAILS->save($this->aEmail);
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * Attempt to find existing user by email address
  * Search in EMAILS collection first, then if not found, in USERS collection
  * If record is found creates User object and returns it
  *
  * @return mixed null | User object
  */
 protected function findUserByEmail()
 {
     $User = null;
     /**
      * Search EMAILS collection
      * try to find user that has this email address
      */
     $res = $this->Registry->Mongo->EMAILS->findOne(array(Schema::EMAIL => $this->email), array('i_uid' => true));
     if (!empty($res) && !empty($res['i_uid'])) {
         d('found user id by email address. uid: ' . $res['i_uid']);
         $aUser = $this->Registry->Mongo->USERS->findOne(array(Schema::PRIMARY => $res['i_uid']));
         $User = \Lampcms\User::userFactory($this->Registry, $aUser);
     }
     /**
      * Was Not able to find user by search EMAILS collection
      * Search USERS collection by email address
      */
     if (null === $User) {
         $a = $this->Registry->Mongo->USERS->findOne(array(Schema::EMAIL => $this->email));
         if (!empty($a)) {
             d('found user id by email address. uid: ' . $a['_id']);
             $User = \Lampcms\User::userFactory($this->Registry, $a);
         }
     }
     d('User not found by email: ' . $this->email);
     return $User;
 }
Ejemplo n.º 10
0
 /**
  * Increase answer count
  * for question.
  * Also set Last Answerer details
  * and add Answerer User to list
  * of Question contributors
  * (this is for the dot-folders feature)
  *
  * The increaseAnswerCount will also update
  * the last modified timestamp for question
  *
  * @return object $this
  */
 protected function updateQuestion()
 {
     d('cp');
     $uid = $this->Resource->getOwnerId();
     d('uid of answer: ' . $uid);
     $User = \Lampcms\User::userFactory($this->Registry)->by_id($uid);
     d('$User id: ' . $User->getUid());
     $this->Question->updateAnswerCount();
     $this->Question->addContributor($User);
     $this->Question->setLatestAnswer($User, $this->Resource);
     $this->Question->touch();
     $this->Question->save();
     return $this;
 }