public function configure()
 {
     sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR'));
     sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%'));
     $items = PcTimezonePeer::doSelect(new Criteria());
     $tzs = array();
     foreach ($items as $item) {
         $tzs[$item->getLabel()] = $item->getDescription();
     }
     $this->setWidgets(array('email' => new sfWidgetFormInputText(), 'password1' => new sfWidgetFormInputPassword(), 'password2' => new sfWidgetFormInputPassword(), 'lang' => new sfWidgetFormInputHidden(), 'tz' => new sfWidgetFormInputHidden(array('default' => self::TIMEZONE_DEFAULT_VALUE)), 'dst_on' => new sfWidgetFormInputHidden(array('default' => 0))));
     $this->setValidators(array('password1' => new sfValidatorString(array('max_length' => sfConfig::get('app_password_maxLength'), 'min_length' => sfConfig::get('app_password_minLength'))), 'password2' => new sfValidatorString(array('max_length' => sfConfig::get('app_password_maxLength'), 'min_length' => sfConfig::get('app_password_minLength'))), 'tz' => new sfValidatorString(), 'lang' => new sfValidatorString(array('max_length' => 8, 'required' => false)), 'dst_on' => new sfValidatorString(array('max_length' => 1))));
     $emailDomainsBlacklistedInRegistration = sfConfig::get('app_site_emailDomainsBlacklistedInRegistration');
     foreach ($emailDomainsBlacklistedInRegistration as $k => $v) {
         $emailDomainsBlacklistedInRegistration[$k] = str_replace('.', '\\.', $v);
     }
     $emailDomainsBlacklistedInRegistration = implode('|', $emailDomainsBlacklistedInRegistration);
     $this->validatorSchema['email'] = new sfValidatorAnd(array(new sfValidatorEmail(array('required' => true, 'max_length' => sfConfig::get('app_email_maxLength'), 'min_length' => sfConfig::get('app_email_minLength'))), new sfValidatorRegex(array('pattern' => '/@(' . $emailDomainsBlacklistedInRegistration . ')(\\b|$)/si', 'must_match' => false), array('invalid' => 'Domain blocked - please use another email'))), array(), array());
     $this->mergePostValidator(new sfValidatorSchemaCompare('password1', '==', 'password2', array(), array('invalid' => __('WEBSITE_REGISTRATION_PASSWORD_MISMATCH_ERROR'))));
     $this->mergePostValidator(new sfValidatorDetectingSpammersOnRegistration(null, array(), array('invalid' => __('WEBSITE_REGISTRATION_PASSWORD_MISMATCH_ERROR'))));
     $this->widgetSchema->setLabels(array('email' => __('WEBSITE_REGISTRATION_EMAIL_ADDRESS_LABEL'), 'password1' => __('WEBSITE_REGISTRATION_CHOOSE_PASSWORD_LABEL'), 'password2' => __('WEBSITE_REGISTRATION_REPEAT_PASSWORD_LABEL')));
     $this->widgetSchema->setNameFormat('registration[%s]');
     // {{{ START: anti-spam (see sfValidatorTimerAntiSpam class)
     $this->widgetSchema['asdf'] = new sfWidgetFormInputHidden(array(), array('value' => base64_encode(time())));
     $this->validatorSchema['asdf'] = new sfValidatorTimerAntiSpam();
     // }}} STOP: anti-spam
 }
 public function configure()
 {
     $items = PcTimezonePeer::doSelect(new Criteria());
     $tzs = array();
     foreach ($items as $item) {
         $tzs[$item->getLabel()] = $item->getDescription();
     }
     $this->setWidgets(array('tz' => new sfWidgetFormSelect(array('choices' => $tzs, 'default' => '00:00,0')), 'dst_on' => new sfWidgetFormInputCheckbox(array('default' => 0))));
     $this->setValidators(array('tz' => new sfValidatorString(), 'dst_on' => new sfValidatorString(array('required' => false, 'max_length' => 3))));
     $this->widgetSchema->setLabels(array('tz' => __('ACCOUNT_SETTINGS_SELECT_TIMEZONE'), 'dst_on' => __('ACCOUNT_SETTINGS_DAYLIGHT_SAVING_ACTIVE')));
     $this->widgetSchema->setNameFormat('timezone[%s]');
 }
 public function executeTimezone(sfWebRequest $request)
 {
     $user = PcUserPeer::getLoggedInUser();
     // die($user->getTimezoneLabel());
     $this->form = new EditTimezoneForm(array('tz' => $user->getTimezoneLabel(), 'dst_on' => $user->getDstActive()));
     $fields = array();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter('timezone'));
         if ($this->form->isValid()) {
             $fields = $request->getParameter('timezone');
             $c = new Criteria();
             $c->add(PcTimezonePeer::LABEL, $fields['tz'], Criteria::EQUAL);
             $timezone = PcTimezonePeer::doSelectOne($c);
             $user->setTimezoneId($timezone->getId());
             if (isset($fields['dst_on']) && $fields['dst_on']) {
                 $user->setDstActive($fields['dst_on']);
             } else {
                 $user->setDstActive(false);
             }
             $user->save();
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent('userSetTimezone', 'user.set_timezone', array('user' => $user)));
             sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent('userSetDst', 'user.set_dst', array('user' => $user)));
             $this->getUser()->setFlash('settingSuccess', __('ACCOUNT_SETTINGS_TIMEZONE_SUCCESS'));
             $this->forward('settings', 'index');
         }
     }
     $this->user = $user;
 }
Example #4
0
 /**
  * Returns the real offset in seconds between and GMT and user settings, 
  * considering both the timezone and dst of the user
  *
  * @return integer
  */
 public function getRealOffsetFromGMT()
 {
     $timezone = PcTimezonePeer::retrieveByPk($this->getTimezoneId());
     $ret = 0;
     if ($timezone) {
         $timezoneOffsetFromGMT = $timezone->getOffset();
         // in minutes
         $dstOffsetFromGMT = $this->getDstActive() * 60;
         // in minutes // if dst is active, the clock is 1 hour forward
         $ret = $timezoneOffsetFromGMT * 60 + $dstOffsetFromGMT * 60;
     }
     return $ret;
 }
Example #5
0
 /**
  * Sets the timezone
  *
  * @param PcUser $user
  */
 private static function setTimezone(PcUser $user)
 {
     $forumTablesPrefix = sfConfig::get('app_forum_tablePrefix');
     $connection = Propel::getConnection();
     $userId = $user->getForumId();
     $timezone = PcTimezonePeer::retrieveByPk($user->getTimezoneId());
     $timezone = $timezone->getOffset() / 60;
     // in the forum the timezone is in hours, not in minutes
     $query = sprintf("UPDATE " . $forumTablesPrefix . "users SET timezone=:timezone WHERE id=%d", (int) $userId);
     $statement = $connection->prepare($query);
     $statement->execute(array('timezone' => $timezone));
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PcTimezonePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setLabel($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setDescription($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setOffset($arr[$keys[3]]);
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(PcTimezonePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PcTimezonePeer::DATABASE_NAME);
         $criteria->add(PcTimezonePeer::ID, $pks, Criteria::IN);
         $objs = PcTimezonePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Example #8
0
 /**
  * Register a new user
  *
  * @param string $email - the email address
  * @param string $password - the plain password (no encryption)
  * @param string $lang - if it is null or empty, the language will be detected from the header of the request
  * @param string $preferredLang - this should be a 2-char abbreviation of the lang the user wants,
  *         among the ones in the main app.yml config file
  * @param string $tzLabel - a timezone label as in the PcTimezone db table
  * @param integer $dstOn (1 or 0) - whether or not the dst for the user is on
  * @param boolen $joinNewsletter(=false) - whether the user decided to join our newsletter
  * @param boolen $sendActivationEmail(=true) - whether to send the activation email  
  * @return boolean|PcUser false is a user with that email already exists, the PcUser object otherwise
  */
 public static function registerNewUser($email, $password, $lang, $preferredLang, $tzLabel, $dstOn, $joinNewsletter = false, $sendActivationEmail = true)
 {
     if (self::emailExist($email)) {
         return false;
     }
     $newUser = new PcUser();
     $newUser->setEmail($email);
     $newUser->setPassword($password);
     $newUser->setAwaitingActivation(1);
     if ($joinNewsletter) {
         $newUser->setNewsletter(1);
     }
     $newUser->save();
     // Dealing with timezone
     $newUser->setDstActive($dstOn);
     $c = new Criteria();
     $c->add(PcTimezonePeer::LABEL, $tzLabel, Criteria::EQUAL);
     $timezone = PcTimezonePeer::doSelectOne($c);
     if (!is_object($timezone)) {
         // set to a default one
         $timezone = PcTimezonePeer::retrieveByPK(21);
     }
     $newUser->setTimezoneId($timezone->getId());
     // Dealing with formats
     // _ time format: the countries with the majority of our users are using the
     //   12H format, thus we can leave the default
     // _ for the date format we check whether they are in USA
     // _ for the first day of the week, we check whether they are in USA
     $dateFormatId = 3;
     $weekStart = 1;
     // from Monday
     $tzOffset = $timezone->getOffset();
     if ($tzOffset <= -300 && $tzOffset >= -450) {
         $dateFormatId = 4;
         $weekStart = 0;
         // from Sunday
     }
     $newUser->setDateFormat($dateFormatId);
     $newUser->setWeekStart($weekStart);
     if ($lang != null && $lang !== '') {
         $newUser->setLanguage($lang);
     } else {
         $newUser->setLanguage(PcUtils::getVisitorAcceptLanguage());
     }
     $availableLangs = PcLanguagePeer::getAvailableLanguageAbbreviations();
     if (in_array($preferredLang, $availableLangs)) {
         $newUser->setPreferredLanguage($preferredLang);
     } else {
         $newUser->setPreferredLanguage(SfConfig::get('app_site_defaultLang'));
     }
     $newUser->setIpAddress(PcUtils::getVisitorIPAddress());
     if ($sessionEntryPoint = sfContext::getInstance()->getUser()->getAttribute('session_entry_point')) {
         $newUser->setSessionEntryPoint($sessionEntryPoint);
     }
     if ($sessionReferral = sfContext::getInstance()->getUser()->getAttribute('session_referral')) {
         $newUser->setSessionReferral($sessionReferral);
     }
     $newUser->save();
     // Creating system lists
     $inboxList = new PcList();
     $inboxList->setIsInbox(1)->setTitle(__('ACCOUNT_LISTS_INBOX'))->setCreator($newUser)->save();
     $todoList = new PcList();
     $todoList->setIsTodo(1)->setTitle(__('ACCOUNT_LISTS_TODO'))->setCreator($newUser)->save();
     // Creating default contexts
     $context = new PcUsersContexts();
     $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_HOME'))->save();
     $context = new PcUsersContexts();
     $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_ERRANDS'))->save();
     $context = new PcUsersContexts();
     $context->setPcUser($newUser)->setContext(__('ACCOUNT_TAGS_DEFAULT_COMPUTER'))->save();
     // Creating some tasks for the inbox
     $newUser->addToInbox(__('ACCOUNT_MISC_WELCOME_TASK'));
     // creating Plancake email address
     $newUser->generateAndStorePlancakeEmailAddress();
     // I need to use a token for the activation of their account
     $token = '';
     $c = new Criteria();
     $c->add(PcActivationTokenPeer::USER_ID, $newUser->getId(), Criteria::EQUAL);
     $tokenEntry = PcActivationTokenPeer::doSelectOne($c);
     if (is_object($tokenEntry)) {
         $token = $tokenEntry->getToken();
     } else {
         $secret = sfConfig::get('app_registration_secret');
         // token doesn't need to be 32-char long. It is better to keep it short
         // so there will be less chance the email client will break the link into 2 lines
         $token = substr(md5($newUser->getId() . $secret . time()), 0, 14);
         $tokenEntry = new PcActivationToken();
         $tokenEntry->setUserId($newUser->getId());
         $tokenEntry->setToken($token);
         $tokenEntry->save();
     }
     // now we can send the email
     if ($sendActivationEmail) {
         $link = sfContext::getInstance()->getController()->genUrl('@activation?t=' . $token, true);
         $from = sfConfig::get('app_emailAddress_contact');
         $subject = 'Plancake - ' . __('WEBSITE_REGISTRATION_EMAIL_SUBJECT');
         $body = sprintf(__('WEBSITE_REGISTRATION_EMAIL_BODY'), $link);
         PcUtils::sendEmail($email, $subject, $body, $from);
     }
     $newUser->refreshLatestBlogAccess();
     sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($newUser, 'user.sign_up', array('user' => $newUser, 'plainPassword' => $password)));
     return $newUser;
 }
Example #9
0
 /**
  * Get the associated PcTimezone object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     PcTimezone The associated PcTimezone object.
  * @throws     PropelException
  */
 public function getPcTimezone(PropelPDO $con = null)
 {
     if ($this->aPcTimezone === null && $this->timezone_id !== null) {
         $this->aPcTimezone = PcTimezonePeer::retrieveByPk($this->timezone_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aPcTimezone->addPcUsers($this);
         		 */
     }
     return $this->aPcTimezone;
 }
 /**
  * Selects a collection of PcUser objects pre-filled with all related objects.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of PcUser objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     PcUserPeer::addSelectColumns($criteria);
     $startcol2 = PcUserPeer::NUM_COLUMNS - PcUserPeer::NUM_LAZY_LOAD_COLUMNS;
     PcTimezonePeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (PcTimezonePeer::NUM_COLUMNS - PcTimezonePeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(PcUserPeer::TIMEZONE_ID, PcTimezonePeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BasePcUserPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = PcUserPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = PcUserPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = PcUserPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             PcUserPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined PcTimezone rows
         $key2 = PcTimezonePeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = PcTimezonePeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = PcTimezonePeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 PcTimezonePeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (PcUser) to the collection in $obj2 (PcTimezone)
             $obj2->addPcUser($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }