示例#1
0
 public function __construct(\Lampcms\Ini $Ini)
 {
     $this->Ini = $Ini;
     $this->adminEmail = $Ini->EMAIL_ADMIN;
     $this->siteName = $Ini->SITE_NAME;
     $this->from = \Lampcms\String::prepareEmail($this->adminEmail, $this->siteName);
 }
示例#2
0
 public function main()
 {
     /**
      * $this->username and $this->pwd
      * are used in createNewUser() in Register
      */
     $this->username = $this->Request['username'];
     $this->pwd = String::makePasswd();
     $this->validateCaptcha()->checkUsername()->validateEmail()->createNewUser()->createEmailRecord()->sendActivationEmail()->setReturn();
 }
 /**
  *
  * 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;
 }
示例#4
0
 /**
  *
  * Update USERS collection with the
  * new value of salted password
  *
  * @param string $pwd
  * @param int $uid
  *
  * @return object $this
  */
 protected function savePassword()
 {
     d('$this->newPwd: ' . $this->newPwd);
     $salted = String::hashPassword($this->newPwd);
     $newdata = array('$set' => array("pwd" => $salted));
     $this->Registry->Mongo->USERS->update(array('_id' => (int) $this->Request['uid']), $newdata);
     return $this;
 }
示例#5
0
 /**
  *
  * What if email address provided from Facebook
  * already belongs to some other user?
  *
  * This would mean that existing user is just
  * trying to signup with Facebook.
  *
  * In this case we should allow it but ONLY create
  * a record in the USERS_FACEBOOK table and use users_id
  * of use that we find by email address
  *
  * and then also insert avatar_external into USERS
  *
  * @todo create username for user based on Facebook username
  *       Facebook does not really have username, so we can use fn_ln
  *
  */
 protected function createNewUser()
 {
     $extAuth = new \Lampcms\ExternalAuth($this->Registry);
     d('cp');
     $this->Registry->Mongo->USERS->ensureIndex(array('fb_id' => 1));
     /**
      * Time zone offset in seconds
      *
      * @var int
      */
     if (array_key_exists('timezone', $this->aFbUserData)) {
         $timezone = TimeZone::getTZbyoffset($this->aFbUserData['timezone'] * 3600);
     } elseif (false !== ($tzn = Cookie::get('tzn'))) {
         $timezone = $tzn;
     } else {
         $timezone = $this->Registry->Ini->SERVER_TIMEZONE;
     }
     /**
      * User language
      *
      * @var string
      */
     $lang = !empty($this->aFbUserData['locale']) ? \strtolower(\substr($this->aFbUserData['locale'], 0, 2)) : $this->Registry->getCurrentLang();
     /**
      * User locale
      *
      * @var string
      */
     $locale = !empty($this->aFbUserData['locale']) ? $this->aFbUserData['locale'] : $this->Registry->Locale->getLocale();
     $this->tempPassword = String::makePasswd();
     /**
      * Sid value use existing cookie val
      * if possible, otherwise create a new one
      *
      * @var string
      */
     $sid = false === ($sid = Cookie::getSidCookie()) ? String::makeSid() : $sid;
     $displayName = !empty($this->aFbUserData['name']) ? $this->aFbUserData['name'] : $this->aFbUserData['first_name'] . ' ' . $this->aFbUserData['last_name'];
     $username = $extAuth->makeUsername($displayName, true);
     if (!array_key_exists('email', $this->aFbUserData)) {
         /**
          * @todo if this becomes a common problem
          *       then we need to ask user for an email address
          *       at step 2 of registration, just like for Twitter users
          *       And the 'role' will then be different like 'unactivated_external'
          */
         e('No email in Facebook data: ' . print_r($this->aFbUserData, 1));
         $email = '';
     } else {
         $email = \mb_strtolower($this->aFbUserData['email']);
     }
     /**
      * Create new record in USERS table
      * do this first because we need uid from
      * newly created record
      */
     $aUser = array('username' => $username, 'username_lc' => \mb_strtolower($username, 'utf-8'), 'fn' => $this->aFbUserData['first_name'], 'ln' => $this->aFbUserData['last_name'], 'rs' => $sid, 'email' => $email, 'fb_id' => (string) $this->aFbUserData['id'], 'fb_token' => $this->aFbUserData['token'], 'pwd' => String::hashPassword($this->tempPassword), 'avatar_external' => 'http://graph.facebook.com/' . $this->aFbUserData['id'] . '/picture', 'i_reg_ts' => time(), 'date_reg' => date('r'), 'role' => 'external_auth', 'lang' => $lang, 'locale' => $locale, 'i_rep' => 1, 'tz' => $timezone, 'i_fv' => false !== ($intFv = Cookie::getSidCookie(true)) ? $intFv : time());
     if (!empty($this->aFbUserData['gender'])) {
         $aUser['gender'] = 'male' === $this->aFbUserData['gender'] ? 'M' : 'F';
     }
     $aUser = \array_merge($this->Registry->Geo->Location->data, $aUser);
     if (!empty($this->aFbUserData['locale'])) {
         $aUser['locale'] = $this->aFbUserData['locale'];
     }
     if (!empty($this->aFbUserData['link'])) {
         $aUser['fb_url'] = $this->aFbUserData['link'];
     }
     d('aUser: '******'$this->User after insert: ' . print_r($this->User->getArrayCopy(), 1));
     $this->Registry->Dispatcher->post($this->User, 'onNewUser');
     $this->Registry->Dispatcher->post($this->User, 'onNewFacebookUser');
     d('cp');
     $this->saveEmailAddress();
     d('cp');
     \Lampcms\PostRegistration::createReferrerRecord($this->Registry, $this->User);
     return $this;
 }
示例#6
0
 /**
  * Create new record in the USERS collection
  * also set the $this->User to the newly created
  * instance of UserLinkedin object
  *
  *
  */
 protected function createNewUser()
 {
     d('$this->aData: ' . print_r($this->aData, 1));
     $ln = !empty($this->aData['ln']) ? $this->aData['ln'] : '';
     $oEA = \Lampcms\ExternalAuth::factory($this->Registry);
     $u = $this->aData['fn'] . '_' . $ln;
     d('$u: ' . $u);
     $username = $oEA->makeUsername($u);
     $sid = \Lampcms\Cookie::getSidCookie();
     d('sid is: ' . $sid);
     $this->aData['username'] = $username;
     $this->aData['username_lc'] = \mb_strtolower($username, 'utf-8');
     $this->aData['i_reg_ts'] = time();
     $this->aData['date_reg'] = date('r');
     $this->aData['role'] = 'external_auth';
     $this->aData['rs'] = false !== $sid ? $sid : \Lampcms\String::makeSid();
     $this->aData['i_rep'] = 1;
     $this->aData['lang'] = $this->Registry->getCurrentLang();
     $this->aData['locale'] = $this->Registry->Locale->getLocale();
     if (empty($this->aData['cc']) && empty($this->aData['city'])) {
         $this->aData = array_merge($this->Registry->Geo->Location->data, $this->aData);
     }
     $this->User = \Lampcms\UserLinkedin::factory($this->Registry, $this->aData);
     /**
      * This will mark this userobject is new user
      * and will be persistent for the duration of this session ONLY
      * This way we can know it's a newsly registered user
      * and ask the user to provide email address but only
      * during the same session
      */
     $this->User->setNewUser();
     d('isNewUser: '******'onNewUser');
     return $this;
 }
示例#7
0
 /**
  * Generates a random string
  * to be use in password reset url
  * It checks to make sure this string does not already exist
  * in the PASSWORD_CHANGE table
  *
  * @return object $this
  *
  * @throws LampcmsException in case a unique string
  * could not be generated
  */
 protected function generateCode()
 {
     d('cp');
     $counter = 0;
     $done = false;
     do {
         $counter++;
         $aData = array();
         $aData['_id'] = \strtolower(\Lampcms\String::makeRandomString(12));
         $aData['i_ts'] = time();
         $aData['i_uid'] = $this->uid;
         /**
          * @todo
          * Don't use _id for string,
          * instead use unique index on string + 'y'/'n' value of 'used'
          * This way string can be duplicate as long as no same
          * string is used
          */
         try {
             $coll = $this->Registry->Mongo->PASSWORD_CHANGE;
             $coll->insert($aData, array('fsync' => true));
             $done = true;
             d('cp');
         } catch (\MongoException $e) {
             d('code already exists, trying again...');
         }
     } while (!$done && $counter < 50);
     if (!$done) {
         throw new \Lampcms\Exception('Error: Unable to generate random string at this time, please try again in 30 seconds');
     }
     $this->randomString = $aData['_id'];
     return $this;
 }
示例#8
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;
 }
示例#9
0
 /**
  * Prepare the url of Google authorization call
  *
  * @return string
  */
 protected function makeAuthUrl()
 {
     $state = \Lampcms\String::makeRandomString(16);
     $_SESSION[self::STATE_KEY] = $state;
     $vars = array('{prompt}' => LAMPCMS_DEBUG ? '&approval_prompt=force' : '', '{redirect}' => $this->redirectUri, '{client_id}' => $this->configSection['CLIENT_ID'], '{scope}' => \urlencode(\implode(' ', $this->configSection['SCOPE'])), '{state}' => $state);
     $res = \strtr(self::AUTH_URL, $vars);
     return $res;
 }
示例#10
0
 /**
  *
  * What if email address provided from Facebook
  * already belongs to some other user?
  *
  * This would mean that existing user is just
  * trying to signup with Facebook.
  *
  * In this case we should allow it but ONLY create
  * a record in the USERS_FACEBOOK table and use users_id
  * of use that we find by email address
  *
  * and then also insert avatar_external into USERS
  *
  * @todo create username for user based on Facebook username
  * Facebook does not really have username, so we can use fn_ln
  *
  */
 protected function createNewUser()
 {
     $extAuth = new \Lampcms\ExternalAuth($this->Registry);
     d('cp');
     $this->Registry->Mongo->USERS->ensureIndex(array('fb_id' => 1));
     /**
      * Time zone offset in seconds
      * @var int
      */
     $tzo = array_key_exists('timezone', $this->aFbUserData) ? $this->aFbUserData['timezone'] * 3600 : Cookie::get('tzo', 0);
     /**
      * User language
      * @var string
      */
     $lang = !empty($this->aFbUserData['locale']) ? \strtolower(\substr($this->aFbUserData['locale'], 0, 2)) : $this->Registry->getCurrentLang();
     /**
      * User locale
      * @var string
      */
     $locale = !empty($this->aFbUserData['locale']) ? $this->aFbUserData['locale'] : $this->Registry->Locale->getLocale();
     $this->tempPassword = String::makePasswd();
     /**
      * Sid value use existing cookie val
      * if possible, otherwise create a new one
      * @var string
      */
     $sid = false === ($sid = Cookie::getSidCookie()) ? String::makeSid() : $sid;
     $displayName = !empty($this->aFbUserData['name']) ? $this->aFbUserData['name'] : $this->aFbUserData['first_name'] . ' ' . $this->aFbUserData['last_name'];
     $username = $extAuth->makeUsername($displayName);
     /**
      * Create new record in USERS table
      * do this first because we need uid from
      * newly created record
      */
     $aUser = array('username' => $username, 'username_lc' => \mb_strtolower($username, 'utf-8'), 'fn' => $this->aFbUserData['first_name'], 'ln' => $this->aFbUserData['last_name'], 'rs' => $sid, 'email' => Utf8String::factory($this->aFbUserData['email'])->toLowerCase()->valueOf(), 'fb_id' => (string) $this->aFbUserData['id'], 'fb_token' => $this->aFbUserData['token'], 'pwd' => String::hashPassword($this->tempPassword), 'avatar_external' => 'http://graph.facebook.com/' . $this->aFbUserData['id'] . '/picture', 'i_reg_ts' => time(), 'date_reg' => date('r'), 'role' => 'external_auth', 'lang' => $lang, 'i_pp' => 1, 'tz' => TimeZone::getTZbyoffset($tzo), 'i_fv' => false !== ($intFv = Cookie::getSidCookie(true)) ? $intFv : time());
     if (!empty($this->aFbUserData['gender'])) {
         $aUser['gender'] = 'male' === $this->aFbUserData['gender'] ? 'M' : 'F';
     }
     $aUser = \array_merge($this->Registry->Geo->Location->data, $aUser);
     if (!empty($this->aFbUserData['locale'])) {
         $aUser['locale'] = $this->aFbUserData['locale'];
     }
     if (!empty($this->aFbUserData['link'])) {
         $aUser['fb_url'] = $this->aFbUserData['link'];
     }
     d('aUser: '******'$this->User after insert: ' . print_r($this->User->getArrayCopy(), 1));
     $this->Registry->Dispatcher->post($this->User, 'onNewUser');
     $this->Registry->Dispatcher->post($this->User, 'onNewFacebookUser');
     d('cp');
     $this->saveEmailAddress();
     d('cp');
     \Lampcms\PostRegistration::createReferrerRecord($this->Registry, $this->User);
     return $this;
 }
示例#11
0
 /**
  * Save the submitted form values
  * by setting the $this->oApi object
  * and then calling insert() or save() on it
  *
  * @return object $this
  *
  */
 protected function save()
 {
     $isUpdate = false;
     $vals = $this->Form->getSubmittedValues();
     d('vals: ' . print_r($vals, 1));
     $appid = (int) $vals['app_id'];
     if ($appid > 0) {
         $isUpdate = true;
         d('has appid, editing mode');
         $this->validateAppIdOwnership($appid);
     } else {
         /**
          * Auto-generate app_id
          * Use USERS auto-increment value
          * because we can then store the image in the same
          * way we store avatar - in the same directory
          * using hex based path.
          *
          */
         $appid = $this->Registry->Incrementor->nextValue('USERS');
     }
     d('$appid: ' . $appid);
     $this->oApi['_id'] = $appid;
     $this->oApi['i_uid'] = $this->Registry->Viewer->getUid();
     $this->oApi['app_name'] = (string) $this->Request->getUTF8('app_name')->trim()->stripTags();
     $this->oApi['appsite'] = (string) $this->Request->getUTF8('appsite')->trim()->stripTags();
     $this->oApi['company'] = (string) $this->Request->getUTF8('company')->trim()->stripTags();
     $this->oApi['app_type'] = (string) $this->Request->getUTF8('app_type')->trim()->stripTags();
     $this->oApi['about'] = (string) $this->Request->getUTF8('about')->trim()->stripTags();
     $this->oApi['api_key'] = $appid . '.' . String::makeRandomString(12);
     $this->parseIcon();
     /**
      * Ensure that app is a unique field
      * app is the name of application
      */
     $coll = $this->Registry->Mongo->API_CLIENTS;
     $coll->ensureIndex(array('app_name' => 1), array('unique' => true));
     $coll->ensureIndex(array('api_key' => 1), array('unique' => true));
     $coll->ensureIndex(array('i_uid' => 1));
     try {
         if ($isUpdate) {
             d('cp');
             $this->oApi['edited_time'] = date('F j, Y g:i a T');
             $this->oApi['edit_ip'] = Request::getIP();
             $res = $this->oApi->save();
         } else {
             d('cp');
             $this->oApi['created_time'] = date('F j, Y g:i a T');
             $this->oApi['ip'] = Request::getIP();
             $res = $this->oApi->insert();
         }
     } catch (\Exception $e) {
         throw new \OutOfBoundsException($e->getMessage());
     }
     d('$res: ' . $res);
     return $this;
 }
示例#12
0
 /**
  * Create new record in the USERS collection
  * also set the $this->User to the newly created
  * instance of UserLinkedin object
  *
  *
  */
 protected function createNewUser()
 {
     d('creating new user');
     /**
      * Need to call /people/~/email-address to get email address
      * and /people/~ to get data that includes avatar among other things
      */
     if (false !== ($tzn = Cookie::get('tzn'))) {
         $timezone = $tzn;
     } else {
         $timezone = $this->Registry->Ini->SERVER_TIMEZONE;
     }
     $ln = !empty($this->aData['ln']) ? $this->aData['ln'] : '';
     $oEA = \Lampcms\ExternalAuth::factory($this->Registry);
     $u = $this->aData['fn'] . ' ' . $ln;
     d('$u: ' . $u);
     $username = $oEA->makeUsername($u);
     $sid = \Lampcms\Cookie::getSidCookie();
     d('sid is: ' . $sid);
     $this->aData[Schema::USERNAME] = $username;
     $this->aData[Schema::USERNAME_LOWERCASE] = \mb_strtolower($username, 'utf-8');
     $this->aData[Schema::REGISTRATION_TIMESTAMP] = time();
     $this->aData[Schema::REGISTRATION_TIME] = date('r');
     $this->aData[Schema::ROLE] = Role::EXTERNAL_USER;
     $this->aData[Schema::SID] = false !== $sid ? $sid : \Lampcms\String::makeSid();
     $this->aData[Schema::REPUTATION] = 1;
     $this->aData[Schema::LANG] = $this->Registry->getCurrentLang();
     $this->aData[Schema::LOCALE] = $this->Registry->Locale->getLocale();
     $this->aData[Schema::TIMEZONE] = $timezone;
     if (!empty($this->email)) {
         $this->aData[Schema::EMAIL] = $this->email;
     }
     if (empty($this->aData['cc']) && empty($this->aData['city'])) {
         $this->aData = array_merge($this->Registry->Geo->Location->data, $this->aData);
     }
     $this->User = \Lampcms\UserLinkedin::userFactory($this->Registry, $this->aData);
     /**
      * This will mark this user object is new user
      * and will be persistent for the duration of this session ONLY
      * This way we can know it's a newly registered user
      * and ask the user to provide email address but only
      * during the same session
      */
     $this->User->setNewUser();
     d('isNewUser: '******'onNewUser');
     return $this;
 }
示例#13
0
 /**
  * @param \Lampcms\Config\Ini        $Ini
  * @param \Lampcms\Cache\Cache|null $cache
  */
 public function __construct(\Lampcms\Config\Ini $Ini, \Lampcms\Cache\Cache $cache = null)
 {
     $this->Ini = $Ini;
     $this->adminEmail = $Ini->EMAIL_ADMIN;
     $this->siteName = $Ini->SITE_NAME;
     $this->from = \Lampcms\String::prepareEmail($this->adminEmail, $this->siteName);
     $this->setupSwiftMailer();
     $this->Cache = $cache;
 }
示例#14
0
 /**
  *
  * Update USERS collection with the
  * new value of salted password
  *
  * @internal param string $pwd
  * @internal param int $uid
  *
  * @return object $this
  */
 protected function savePassword()
 {
     d('$this->newPwd: ' . $this->newPwd);
     $uid = $this->Router->getNumber(1);
     $salted = String::hashPassword($this->newPwd);
     $newdata = array('$set' => array(Schema::PASSWORD => $salted));
     $this->Registry->Mongo->USERS->update(array(Schema::PRIMARY => (int) $uid), $newdata);
     return $this;
 }
 protected function createNewUser()
 {
     $aUser = array();
     $username = $this->makeUsername();
     $sid = Cookie::getSidCookie();
     d('sid is: ' . $sid);
     $aUser['username'] = $username;
     $aUser['username_lc'] = \mb_strtolower($username, 'utf-8');
     $aUser['fn'] = $this->aUserData['name'];
     $aUser['avatar_external'] = $this->aUserData['profile_image_url'];
     $aUser['lang'] = $this->aUserData['lang'];
     $aUser['i_reg_ts'] = time();
     $aUser['date_reg'] = date('r');
     $aUser['role'] = 'external_auth';
     $aUser['tz'] = \Lampcms\TimeZone::getTZbyoffset($this->aUserData['utc_offset']);
     $aUser['rs'] = false !== $sid ? $sid : \Lampcms\String::makeSid();
     $aUser['twtr_username'] = $this->aUserData['screen_name'];
     $aUser['oauth_token'] = $this->aUserData['oauth_token'];
     $aUser['oauth_token_secret'] = $this->aUserData['oauth_token_secret'];
     $aUser['twitter_uid'] = $this->aUserData['_id'];
     $aUser['i_pp'] = 1;
     $aUser = array_merge($this->Registry->Geo->Location->data, $aUser);
     if (!empty($this->aUserData['url'])) {
         $aUser['url'] = $this->aUserData['url'];
     }
     if (!empty($this->aUserData['description'])) {
         $aUser['description'] = $this->aUserData['description'];
     }
     d('aUser: '******'s a newsly registered user
      * and ask the user to provide email address but only
      * during the same session
      */
     //$this->User->setNewUser();
     //d('isNewUser: '******'onNewUser');
     $this->Registry->Dispatcher->post($this->User, 'onNewTwitterUser');
     //exit(' new user: '******' '.print_r($this->User->getArrayCopy(), 1));
     return $this;
 }
示例#16
0
 /**
  * Update ['pwd'] in Viewer object and save object
  *
  * @return object $this
  */
 protected function saveNewPassword()
 {
     $this->email = $this->Registry->Viewer['email'];
     $this->username = $this->Registry->Viewer['username'];
     $this->newPwd = $this->Request['pwd1'];
     $this->Registry->Viewer['pwd'] = String::hashPassword($this->newPwd);
     $this->Registry->Viewer->save();
     return $this;
 }
示例#17
0
 /**
  * Update the viewer object
  * with the new values
  * then save the object
  *
  * @return object $this
  */
 protected function updateViewer()
 {
     $currentRole = $this->Registry->Viewer->getRoleId();
     d('$currentRole: ' . $currentRole);
     $this->pwd = String::makePasswd();
     $pwd = String::hashPassword($this->pwd);
     $this->Registry->Viewer->offsetSet(Schema::EMAIL, $this->email);
     /**
      * Only change username IF this is a new registration
      * and username was actually submitted
      *
      * This means we don't allow to change username after
      * the user has already joined the site.
      *
      * This extra measure here will prevent a possible
      * hack where an existing user otherwise may be able
      * to change username
      */
     if (!empty($this->Request['username'])) {
         $username = \trim($this->Request['username']);
         $this->Registry->Viewer->offsetSet(Schema::USERNAME, $username);
         $this->Registry->Viewer->offsetSet(Schema::USERNAME_LOWERCASE, \mb_strtolower($username));
         /**
          * Set the hashed password but it will only be
          * set if this is a new registration (post-registration)
          */
         $this->Registry->Viewer->offsetSet(Schema::PASSWORD, $pwd);
     }
     /**
      * Now sure about changing usergroup yet....
      * This is not so easy because if we change to unactivated then
      * user will not be able to do certain things like post comments
      * but would have been able to do it if he decided NOT to provide
      * email address and to just stay as 'external' account
      *
      * We have to do a more complicated check:
      * If user isNewRegistration then we let such user to post comments
      * and resources during the first visit otherwise we will check
      * if user does not have email address -> ask to provide it
      * if user is NOT activated then ask to activate it...
      *
      * OR we can just don't treat external account as trusted account
      * until user provides email and activates it!
      *
      * I think the best way is to treat external account as trusted BUT
      * periodically check and remind user to provide email address
      * and to activate it...
      *
      */
     /**
      * If current usergroup is external_users
      * then we change it to unactivated_external
      * otherwise change to unactivated
      *
      * unactivated_external have more rights that just
      * unactivated but we can still spot that the user
      * has not activated an account
      * and present a reminder as some point.
      */
     $this->Registry->Viewer->setRoleId(Role::UNACTIVATED_EXTERNAL);
     $this->Registry->Viewer->save();
     /**
      *
      * This is used in Register for sending out email
      */
     $this->username = $this->Registry->Viewer->offsetGet(Schema::USERNAME);
     return $this;
 }