Ejemplo n.º 1
0
 /**
  * Change user's user_group_id to registered
  * and set validation_time to now in EMAILS record
  *
  * @return object $this
  */
 protected function activateUser()
 {
     $aUser = $this->Registry->Mongo->USERS->findOne(array('_id' => (int) $this->aEmail['i_uid']));
     if (empty($aUser)) {
         /**
          * @todo translate string
          */
         throw new \Lampcms\Exception($this->_('Unable to find user, please create a new account'));
     }
     $this->oActivatedUser = User::factory($this->Registry, $aUser);
     $role = $this->oActivatedUser->getRoleId();
     /**
      * If User's role is NOT 'unactivated' then
      * throw an exception
      */
     if (false === \strstr($role, 'unactivated')) {
         e('Account already activated. ' . $role . ' $aUser: '******'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.º 2
0
 /**
  * Decrease the profit point amount 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['i_uid'];
         if (!empty($uid)) {
             try {
                 \Lampcms\User::factory($this->Registry)->by_id($uid)->setProfitPoint(0 - \Lampcms\Points::BEST_ANSWER)->save();
             } catch (\MongoException $e) {
                 e('unable to update the profit point amount for old answerer ' . $e->getMessage());
             }
         }
     }
     return $this;
 }
Ejemplo n.º 3
0
 /**
  *
  * Create new record in USERS collection,
  *
  * @return object $this
  */
 protected function createNewUser()
 {
     $coll = $this->Registry->Mongo->USERS;
     $coll->ensureIndex(array('username_lc' => 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('email' => 1));
     $coll->ensureIndex(array('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 = \Lampcms\Cookie::getSidCookie();
     $aData['username'] = $this->username;
     $aData['username_lc'] = strtolower($this->username);
     $aData['email'] = $this->email;
     $aData['rs'] = false !== $sid ? $sid : \Lampcms\String::makeSid();
     $aData['role'] = $this->getRole();
     $aData['tz'] = \Lampcms\TimeZone::getTZbyoffset($this->Request->get('tzo'));
     $aData['pwd'] = String::hashPassword($this->pwd);
     $aData['i_reg_ts'] = time();
     $aData['date_reg'] = date('r');
     $aData['i_fv'] = false !== ($intFv = \Lampcms\Cookie::getSidCookie(true)) ? $intFv : time();
     $aData['lang'] = $this->Registry->getCurrentLang();
     $aData['locale'] = $this->Registry->Locale->getLocale();
     /**
      * Initial amount of profit point is always 1
      * @var int
      */
     $aData['i_pp'] = 0;
     $aUser = array_merge($this->Registry->Geo->Location->data, $aData);
     d('aUser: '******'id: ' . $User['_id']);
     $this->processLogin($User);
     \Lampcms\PostRegistration::createReferrerRecord($this->Registry, $User);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Increase or decrease owner's profit point amount
  * after his question or answer receives a vote
  *
  * @return object $this
  */
 protected function setOwnerProfitPoint()
 {
     $uid = $this->Resource->getOwnerId();
     d('uid of resource owner: ' . $uid);
     /**
      * Now need to calculate points
      *
      */
     try {
         \Lampcms\User::factory($this->Registry)->by_id($uid)->setProfitPoint($this->calculatePoints())->save();
     } catch (\Exception $e) {
         e($e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine());
     }
     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::factory($this->Registry)->by_id($this->Resource->getOwnerId());
         $User->setRoleId('suspended');
         $User->save();
         $this->Registry->Dispatcher->post($User, 'onUserBanned');
     }
     return $this;
 }
Ejemplo n.º 6
0
 public function testFactory()
 {
     $o = \Lampcms\User::factory(new Registry());
     $o->setSaved();
     $this->assertTrue($o instanceof \Lampcms\User);
 }
Ejemplo n.º 7
0
 /**
  * Create $this->User object
  * that represents User whose profile
  * is being viewed currently
  *
  * @throws \Lampcms\Exception if user could not be
  * found by user id passed in request
  *
  * @return object $this
  */
 protected function getUser()
 {
     $a = $this->Registry->Mongo->USERS->findOne(array('_id' => $this->Request['uid']));
     if (empty($a)) {
         /**
          * @todo translate string
          */
         throw new \Lampcms\Lampcms404Exception($this->_('User not found'));
     }
     $this->User = User::factory($this->Registry, $a);
     $this->aPageVars['title'] = $this->User->getDisplayName();
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Create $this->User User object for user whose
  * profile is being edited
  *
  * @todo unfinished. IT will be possible to
  * edit user other than Viewer when Viewer has
  * permission to edit_other_profile
  * For now this is a Viewe object
  *
  * @return object $this
  */
 protected function getUser()
 {
     $uid = $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::factory($this->Registry)->by_id($uid);
     } else {
         $this->User = $this->Registry->Viewer;
     }
     return $this;
 }