public function validateApply()
 {
     // Extend me to validate your own stuff
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $email = $this->getRequestParameter('email');
         $email2 = $this->getRequestParameter('email2');
         $username = $this->getRequestParameter('username');
         if ($email !== $email2) {
             $this->logMessage("Emails don't match", 'info');
             $this->getRequest()->setError('email', "Email addresses do not match.");
             return false;
         }
         $password = $this->getRequestParameter('password');
         $password2 = $this->getRequestParameter('password2');
         if ($password !== $password2) {
             $this->logMessage("Passwords don't match", 'info');
             $this->getRequest()->setError('password', "Passwords do not match.");
             return false;
         }
         if (sfGuardUserPeer::retrieveByUsername($username)) {
             // TODO: efficient username suggest-o-matic ala Accountify
             $this->getRequest()->setError('username', "Sorry, that username is already in use. Please select another.");
             return false;
         }
         if (!preg_match("/^[\\w\\ \\.\\-]+\$/", $username)) {
             $this->getRequest()->setError('username', "Sorry, usernames may contain only letters, numbers, underscores, spaces, periods and dashes.");
             return false;
         }
         $c = new Criteria();
         $c->add(sfGuardUserProfilePeer::EMAIL, $email);
         $match = sfGuardUserProfilePeer::doSelectOne($c);
         if ($match) {
             $this->logMessage("Email in use", 'info');
             $this->getRequest()->setError('email', "Sorry, that email address is already associated with an account. Click on \"I forgot my password\" if you need to retrieve your password.");
             return false;
         }
     }
     $this->logMessage("Validate function succeeded", 'info');
     return true;
 }
 public static function retrieveByActivationKey($key)
 {
     $c = new Criteria();
     $c->add(sfGuardUserProfilePeer::ACTIVATION_KEY, $key);
     return sfGuardUserProfilePeer::doSelectOne($c);
 }
 /**
  * Get the associated sfGuardUserProfile object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     sfGuardUserProfile The associated sfGuardUserProfile object.
  * @throws     PropelException
  */
 public function getsfGuardUserProfile(PropelPDO $con = null)
 {
     if ($this->asfGuardUserProfile === null && $this->user_id !== null) {
         $c = new Criteria(sfGuardUserProfilePeer::DATABASE_NAME);
         $c->add(sfGuardUserProfilePeer::ID, $this->user_id);
         $this->asfGuardUserProfile = sfGuardUserProfilePeer::doSelectOne($c, $con);
         /* 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->asfGuardUserProfile->addJobNotess($this);
         		 */
     }
     return $this->asfGuardUserProfile;
 }
include_once "../../config/ProjectConfiguration.class.php";
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
$sfContext = sfContext::createInstance($configuration);
$sfContext->dispatch();
$res = ldap_connect("ldaps://ldap.tufts.edu/", 636);
$anon = ldap_bind($res);
if (!$anon) {
    echo ldap_error($res) . "\n";
    exit;
}
$users = sfGuardUserPeer::doSelect(new Criteria());
foreach ($users as $u) {
    if (strpos($u->getUserName(), "@tufts.edu") !== false) {
        $c = new Criteria();
        $c->add(sfGuardUserProfilePeer::USER_ID, $u->getId());
        $profile = sfGuardUserProfilePeer::doSelectOne($c);
        $result = ldap_search($res, "dc=tufts,dc=edu", "mail=" . $u->getUserName());
        $info = ldap_get_entries($res, $result);
        if ($info["count"]) {
            echo $info[0]["uid"][0] . "\n";
            $profile->setEmail(trim($u->getUserName()));
            $profile->save();
            $u->setUserName(trim($info[0]["uid"][0]));
            $u->save();
        } else {
            echo $u->getUserName() . " not found! \n";
            $profile->setEmail("");
            $profile->save();
        }
    }
}