require $lampcmsClasses . 'Base.php';
require $lampcmsClasses . 'WebPage.php';
require $lampcmsClasses . 'Forms' . DIRECTORY_SEPARATOR . 'Form.php';
require $lampcmsClasses . 'Cookie.php';
require $lampcmsClasses . 'LoginForm.php';
if (true !== session_start()) {
    /**
     * @todo
     * Translate String
     */
    echo 'Session start error';
} else {
    try {
        if (empty($_SESSION['viewer'])) {
            d('No Viewer is $_SESSION');
            \Lampcms\Cookie::sendRefferrerCookie();
        }
        $Request = $Registry->Request;
        $a = $Request['a'];
        $controller = ucfirst($a);
        include $lampcmsClasses . 'Controllers' . DIRECTORY_SEPARATOR . $controller . '.php';
        $class = '\\Lampcms\\Controllers\\' . $controller;
        header('Content-Type: text/html; charset=utf-8');
        echo new $class($Registry);
        /**
         *
         * Commenting out the session_write_close()
         * may improve performance since all session writes
         * will be done after the browser connection
         * is closed.
         * The downside is that if any of the registered shutdown
Exemple #2
0
 /**
  * Add extra div with "Join" form
  * where we ask to provide email address
  * after user joins with external provider
  *
  * @return object $this
  */
 protected function addJoinForm()
 {
     if (!$this->bInitPageVars || !Request::isAjax() && 'remindpwd' !== $this->action && 'logout' !== $this->action) {
         /**
          * If user opted out of continuing
          * registration, the special 'dnd' or "Do not disturb"
          * cookie was set via Javascritp
          * We will respect that and will not show that same
          * nagging prompt again
          *
          * This cookie is deleted on Logout
          * @todo set ttl for this cookie to last only a couple of days
          * so we can keep nagging user again after awhile until user
          * finally enters email address
          * Also do not have to check if user is UserExternal - if user
          * does not have email address then keep nagging the user
          * The thing is - only external user can possibly be logged in without
          * any email address because normal user will not know their password
          * since temp passwords are sent to email.
          */
         $cookie = Cookie::get('dnd');
         d('dnd: ' . $cookie);
         if (!$cookie) {
             if ($this->Registry->Viewer instanceof UserExternal) {
                 $email = $this->Registry->Viewer->email;
                 d('email: ' . $email);
                 if (empty($email)) {
                     $sHtml = RegBlock::factory($this->Registry)->getBlock();
                     d('$sHtml: ' . $sHtml);
                     $this->aPageVars['extra_html'] = $sHtml;
                 }
             }
         }
     }
     return $this;
 }
 /**
  *
  * 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;
 }
Exemple #4
0
 /**
  * Sets up the $this->locale value
  * Viewer object should already be instantiated
  * before this method is called
  * This method is usually called from the constructor,
  * so it's really important that this object
  * is NOT requested from the Registry
  * before the Viewer object is instantiated.
  *
  *
  * Get value of locale
  * This method will also
  * set the value in $_SESSION['locale']
  * if $_SESSION is present and
  * locale is not already set in session
  */
 public function init()
 {
     if (!empty($_SESSION) && !empty($_SESSION['locale'])) {
         $this->locale = $_SESSION['locale'];
     } else {
         /**
          * If Viewer is not a guest then
          * get value of locale from Viewer object
          */
         if (!$this->Registry->Viewer->isGuest()) {
             $this->locale = $this->Registry->Viewer->offsetGet('locale');
         } else {
             $this->locale = \Lampcms\Cookie::get('locale', LAMPCMS_DEFAULT_LOCALE);
         }
         if (isset($_SESSION)) {
             $_SESSION['locale'] = $this->locale;
         }
     }
     return $this;
 }
 /**
  * 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;
 }
Exemple #6
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;
 }
 /**
  *
  * 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;
 }
 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;
 }
 /**
  * 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;
 }
 /**
  *
  * 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;
 }
Exemple #11
0
 public function main()
 {
     /**
      * Will not check for the valid 'form token'
      * in this form because potential
      * hacher has nothing to gain by
      * exploiting CSRF of a login form because
      * the user using this form is be definition
      * 'not yet logged in', so there is really
      * nothing to gain by tricking someonw to login
      */
     $bRemember = isset($this->Request['chkRemember']) ? (bool) $this->Request['chkRemember'] : false;
     d('$bRemember ' . $bRemember . ' $this->Request ' . print_r($this->Request->getArrayCopy(), 1));
     try {
         $oCheckLogin = new UserAuth($this->Registry);
         $User = $oCheckLogin->validateLogin($this->Request['login'], $this->Request['pwd']);
         /**
          * If user logged in that means he got the email
          * with password,
          * thus we confirmed email address
          * and can activate user
          */
         $User->activate();
     } catch (\Lampcms\LoginException $e) {
         /**
          * @todo may add extra setting to !config.ini to send login errors
          * to special dedicated email address that will receive all security (hacking attempts)
          * related errors.
          */
         d('Login error: ' . $e->getMessage() . ' in file: ' . $e->getFile() . ' on line: ' . $e->getLine());
         if (Request::isAjax()) {
             Responder::sendJSON(array('error' => $e->getMessage()));
         }
         $_SESSION['login_error'] = $e->getMessage();
         d('$_SESSION[login_error] ' . $_SESSION['login_error']);
         Responder::redirectToPage();
     }
     d('User: '******'onUserLogin');
     if ($bRemember) {
         \Lampcms\Cookie::sendLoginCookie($User->getUid(), $User['rs']);
     }
     Responder::redirectToPage();
 }
 /**
  * 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;
 }
Exemple #13
0
 /**
  * Unsets all session variables and unsets some cookies
  * This is all that is needed to logout
  *
  * @param array $arrParams array or GET or POST parameters
  */
 public function main()
 {
     $this->Registry->Dispatcher->post($this, 'onBeforeUserLogout');
     /**
      * Don't forget about the 'dnd' cookies
      * that may have been set previosly
      * Whith dnd set to 1 a user may register
      * with external auth and will never
      * be asked to provide email address
      * This is designed so that a user may say, hey, don't
      * bother me with this again, I don't want to provide
      * an email address
      *
      * But once the user logges out
      * treat them as another guest!
      */
     $aDelete = array('uid', 'dnd');
     /**
      * If current viewer is logged in
      * with Google Friend Connect
      * then the logout process is somewhat
      * different: we need to delete user's fcauth cookie(s)
      *
      */
     if ($this->Registry->Viewer instanceof UserGfc) {
         $GfcSiteID = $this->Registry->Ini->GFC_ID;
         if (!empty($GfcSiteID)) {
             $gfc = sprintf(self::GFC_SIGNOUT, $GfcSiteID);
             $gfc = Responder::PAGE_OPEN . $gfc . Responder::PAGE_CLOSE;
             d('sending out GFC Logout page: ' . $gfc);
             $fcauthSession = 'fcauth' . $GfcSiteID . '-s';
             $fcauthRegular = 'fcauth' . $GfcSiteID;
             $aDelete[] = $fcauthSession;
             $aDelete[] = $fcauthRegular;
         }
     }
     //d('logging out Facebook User');
     //$aFB = $this->Registry->Ini->getSection('FACEBOOK');
     //if(!empty($aFB) && !empty($aFB['APP_ID'])){
     //	$fb_cookie = 'fbsr_'.$aFB['APP_ID'];
     //	d('deleting Facebook cookie '.$fb_cookie.' len: '.strlen($fb_cookie));
     //	$aDelete[] = $fb_cookie;
     //}
     d('Delete these cookies: ' . print_r($aDelete, 1));
     Cookie::delete($aDelete);
     /**
      * Get copy of user data
      * because we going to need
      * it's values AFTER the user loggs
      * out and after the $this->oViewer has been destroyed
      *
      */
     $aUser = $this->Registry->Viewer->getArrayCopy();
     $this->Registry->Viewer = null;
     session_destroy();
     $_SESSION = array();
     $this->Registry->Dispatcher->post($this, 'onUserLogout', $aUser);
     d('Logged out SESSION: ' . print_r($_SESSION, 1));
     /*if (Request::isAjax()) {
     		$sLoginForm = \Lampcms\LoginForm::makeLoginForm($this->Registry);
     		$arrJSON = array('message'=> $sLoginForm);
     		d('sending json: '.$sLoginForm);
     		Responder::sendJSON($arrJSON);
     		}*/
     /**
      * For Google Friend Connect sendout
      * the html with logout JavaScript - that's
      * the only right way to logout
      */
     if (isset($gfc)) {
         exit($gfc);
     }
     Responder::redirectToPage('/index.php?logout=1');
 }
Exemple #14
0
 protected function main()
 {
     $locale = $this->Request->get('locale');
     if (isset($_SESSION['guest_block'])) {
         unset($_SESSION['guest_block']);
     }
     if (isset($_SESSION['langs'])) {
         unset($_SESSION['langs']);
     }
     if (isset($_SESSION['welcome'])) {
         unset($_SESSION['welcome']);
     }
     if (isset($_SESSION['welcome_guest'])) {
         unset($_SESSION['welcome_guest']);
     }
     $_SESSION['locale'] = $locale;
     $this->Registry->Locale->set($locale);
     Cookie::set('locale', $locale);
     if (!empty($_SESSION['langs'])) {
         unset($_SESSION['langs']);
     }
     //echo __METHOD__.' '.__LINE__.' getting Tr object for locale: '.$locale;
     //$this->Tr = Translator::factory($this->Registry, $locale);
     //echo __METHOD__.' '.__LINE__.' '.print_r($this->Tr->getMessages(), 1);//$this->Tr->get('Questions');
     Responder::redirectToPage($this->Request->get('redirect'));
 }
Exemple #15
0
 protected function main()
 {
     $locale = $this->Registry->Router->getSegment(1);
     /**
      * Redirect url is passed as query string (?redirect=http://someurl)
      * because we cannot pass the url as a uri segment because url itself
      * has many segments
      */
     $redirect = $_GET['redirect'];
     if (isset($_SESSION['guest_block'])) {
         unset($_SESSION['guest_block']);
     }
     if (isset($_SESSION['langs'])) {
         unset($_SESSION['langs']);
     }
     if (isset($_SESSION['welcome'])) {
         unset($_SESSION['welcome']);
     }
     if (isset($_SESSION['welcome_guest'])) {
         unset($_SESSION['welcome_guest']);
     }
     $_SESSION['locale'] = $locale;
     $this->Registry->Locale->set($locale);
     Cookie::set('locale', $locale, 126144000);
     if (!empty($_SESSION['langs'])) {
         unset($_SESSION['langs']);
     }
     Responder::redirectToPage($redirect);
 }