コード例 #1
0
 public function savesfGuardUserGroupList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['sf_guard_user_group_list'])) {
         // somebody has unset this widget
         return;
     }
     if (is_null($con)) {
         $con = $this->getConnection();
     }
     $c = new Criteria();
     $c->add(sfGuardUserGroupPeer::GROUP_ID, $this->object->getPrimaryKey());
     sfGuardUserGroupPeer::doDelete($c, $con);
     $values = $this->getValue('sf_guard_user_group_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new sfGuardUserGroup();
             $obj->setGroupId($this->object->getPrimaryKey());
             $obj->setUserId($value);
             $obj->save();
         }
     }
 }
コード例 #2
0
 public function executeIndex(sfWebRequest $request)
 {
     //        if ($this->getUser()->isAuthenticated()) {
     //            $this->getUser()->setFlash('notice', 'You are already registered and signed in!');
     //            $this->redirect('@homepage');
     //        }
     $this->forward404Unless($sf_guard_user = Doctrine_Core::getTable('sfGuardUser')->find(array($this->getUser()->getUserId())), sprintf('Object sf_guard_user does not exist (%s).', $this->getUser()->getUserId()));
     $this->form = new sfGuardRegisterForm(array(), array('currentUser' => $sf_guard_user));
     $this->form->setDefault('genero', $sf_guard_user->getGenero());
     $this->form->setDefault('email_address', "no_mail" . rand(1, 9999) . "@cdfeg12.com");
     $this->form->setDefault('movil', str_repeat(rand(0, 9), sfConfig::get('app_digitos_telefono') + 1));
     $grupo = new sfGuardUserGroup();
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             $user = $this->form->save();
             $grupo->asignarGrupo($user->getId(), 1);
             $nombre_foto = $user->getFotografia();
             if ($nombre_foto != "") {
                 Utilitarios::cambiarFoto($nombre_foto);
             }
             $this->getUser()->setFlash('notice', 'Discípulo registrado exitosamente', FALSE);
             $this->redirect('discipulos');
         }
     }
 }
コード例 #3
0
 public function addGroupByName($name, $con = null)
 {
     $group = Doctrine::getTable('sfGuardGroup')->findOneByName($name);
     if (!$group) {
         throw new Exception(sprintf('The group "%s" does not exist.', $name));
     }
     $ug = new sfGuardUserGroup();
     $ug->setsfGuardUser($this);
     $ug->setsfGuardGroup($group);
     $ug->save($con);
 }
コード例 #4
0
 public function saveusersList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['users_list'])) {
         // somebody has unset this widget
         return;
     }
     if (is_null($con)) {
         $con = $this->getConnection();
     }
     $q = Doctrine_Query::create()->delete()->from('sfGuardUserGroup r')->where('r.group_id = ?', current($this->object->identifier()))->execute();
     $values = $this->getValue('users_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new sfGuardUserGroup();
             $obj->group_id = current($this->object->identifier());
             $obj->user_id = $value;
             $obj->save();
         }
     }
 }
コード例 #5
0
 /**
  * Filter the query by a related sfGuardUserGroup object
  *
  * @param     sfGuardUserGroup $sfGuardUserGroup  the related object to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return    sfGuardUserQuery The current query, for fluid interface
  */
 public function filterBysfGuardUserGroup($sfGuardUserGroup, $comparison = null)
 {
     if ($sfGuardUserGroup instanceof sfGuardUserGroup) {
         return $this->addUsingAlias(sfGuardUserPeer::ID, $sfGuardUserGroup->getUserId(), $comparison);
     } elseif ($sfGuardUserGroup instanceof PropelCollection) {
         return $this->usesfGuardUserGroupQuery()->filterByPrimaryKeys($sfGuardUserGroup->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterBysfGuardUserGroup() only accepts arguments of type sfGuardUserGroup or PropelCollection');
     }
 }
コード例 #6
0
ファイル: BasesfGuardGroupQuery.php プロジェクト: EQ4/smint
 /**
  * Filter the query by a related sfGuardUserGroup object
  *
  * @param     sfGuardUserGroup $sfGuardUserGroup  the related object to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return    sfGuardGroupQuery The current query, for fluid interface
  */
 public function filterBysfGuardUserGroup($sfGuardUserGroup, $comparison = null)
 {
     return $this->addUsingAlias(sfGuardGroupPeer::ID, $sfGuardUserGroup->getGroupId(), $comparison);
 }
コード例 #7
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      sfGuardUserGroup $value A sfGuardUserGroup object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(sfGuardUserGroup $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getUserId(), (string) $obj->getGroupId()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
コード例 #8
0
 public function addGroupByName($name, $con = null)
 {
     $group = sfGuardGroupPeer::retrieveByName($name);
     if (!$group) {
         throw new Exception(sprintf('The group "%s" does not exist.', $name));
     }
     $ug = new sfGuardUserGroup();
     $ug->setsfGuardUser($this);
     $ug->setGroupId($group->getId());
     $ug->save($con);
 }
コード例 #9
0
 /**
  * Exclude object from result
  *
  * @param   sfGuardUserGroup $sfGuardUserGroup Object to remove from the list of results
  *
  * @return sfGuardUserGroupQuery The current query, for fluid interface
  */
 public function prune($sfGuardUserGroup = null)
 {
     if ($sfGuardUserGroup) {
         $this->addCond('pruneCond0', $this->getAliasedColName(sfGuardUserGroupPeer::USER_ID), $sfGuardUserGroup->getUserId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(sfGuardUserGroupPeer::GROUP_ID), $sfGuardUserGroup->getGroupId(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
     }
     return $this;
 }
コード例 #10
0
 /**
  * @param	sfGuardUserGroup $sfGuardUserGroup The sfGuardUserGroup object to add.
  */
 protected function doAddsfGuardUserGroup($sfGuardUserGroup)
 {
     $this->collsfGuardUserGroups[] = $sfGuardUserGroup;
     $sfGuardUserGroup->setsfGuardGroup($this);
 }
コード例 #11
0
 /**
  * Executes apply action
  *
  * @param sfRequest $request A request object
  */
 public function executeApply(sfRequest $request)
 {
     $this->form = $this->newForm('sfApplyApplyForm');
     if ($request->isMethod('post')) {
         $parameter = $request->getParameter('sfApplyApply');
         $this->form->bind($request->getParameter('sfApplyApply'));
         if ($this->form->isValid()) {
             $guid = "n" . self::createGuid();
             $this->form->setValidate($guid);
             $this->form->save();
             // Generate unique token based on random time
             list($usec, $sec) = explode(" ", microtime());
             $rand_num = substr(sha1((int) ($usec * 1000000 * ($sec / 1000000))), 0, 20);
             // Retrieve current user
             $user = $this->form->getObject();
             $now = date("Y-m-d H:i:s");
             // Create new entry into sfGuardUserProfile table
             $profileObject = new sfGuardUserProfile();
             $profileObject->setUserId($user->getId());
             $profileObject->setToken($rand_num);
             $profileObject->setSecurityLevel(sfConfig::get('app_security_level_new_user'));
             $userPermission = Doctrine_Core::getTable("sfGuardPermission")->findOneByName(sfConfig::get('app_permission_new_user'));
             if (empty($userPermission)) {
                 return;
             }
             // Create new entry into sfGuardUserPermission table
             $permissionObject = new sfGuardUserPermission();
             $permissionObject->setUserId($user->getId());
             $permissionObject->setPermissionId($userPermission->getId());
             $permissionObject->setCreatedAt($now);
             $permissionObject->setUpdatedAt($now);
             $userGroup = Doctrine_Core::getTable("sfGuardGroup")->findOneByName(sfConfig::get('app_project_group'));
             if (empty($userGroup)) {
                 return;
             }
             // Create new entry into sfGuardUserGroup table
             $groupObject = new sfGuardUserGroup();
             $groupObject->setUserId($user->getId());
             $groupObject->setGroupId($userGroup->getId());
             $groupObject->setCreatedAt($now);
             $groupObject->setUpdatedAt($now);
             try {
                 // Send mail
                 $this->sendVerificationMail($user);
                 // Save tables entries
                 $profileObject->save();
                 $permissionObject->save();
                 $groupObject->save();
                 return 'After';
             } catch (Exception $e) {
                 $groupObject->delete();
                 $permissionObject->delete();
                 $profileObject->delete();
                 $user->delete();
                 throw $e;
                 // You could re-throw $e here if you want to
                 // make it available for debugging purposes
                 return 'MailerError';
             }
         }
     }
 }
コード例 #12
0
ファイル: BasesfGuardUser.php プロジェクト: sgrove/cothinker
 public function addsfGuardUserGroup(sfGuardUserGroup $l)
 {
     $this->collsfGuardUserGroups[] = $l;
     $l->setsfGuardUser($this);
 }
 /**
  * Adds the user a new group from its name.
  *
  * @param string $name The group name
  * @param Doctrine_Connection $con A Doctrine_Connection object
  * @throws sfException
  */
 public function addGroupByName($name, $con = null)
 {
     $group = Doctrine_Core::getTable('sfGuardGroup')->findOneByName($name);
     if (!$group) {
         throw new sfException(sprintf('The group "%s" does not exist.', $name));
     }
     $ug = new sfGuardUserGroup();
     $ug->setUser($this);
     $ug->setGroup($group);
     $ug->save($con);
     // add group and permissions to local vars
     $this->_groups[$group->getName()] = $group;
     foreach ($group->getPermissions() as $permission) {
         $this->_allPermissions[$permission->getName()] = $permission;
     }
 }
コード例 #14
0
ファイル: actions.class.php プロジェクト: silky/littlesis
 public function executeAddUser($request)
 {
     $this->checkGroup($request);
     $this->checkUser($request);
     $this->checkOwner();
     if ($request->isMethod('post')) {
         if (!($userId = $request->getParameter('user_id'))) {
             $this->forward('error', 'invalid');
         }
         //add user if not already group member
         $q = LsDoctrineQuery::create()->from('sfGuardUserGroup ug')->where('ug.group_id = ? AND ug.user_id = ?', array($this->group->id, $userId));
         if (!$q->count()) {
             $ug = new sfGuardUserGroup();
             $ug->group_id = $this->group->id;
             $ug->user_id = $userId;
             $ug->save();
         }
         $this->clearCache($this->group);
         $this->redirect($this->group->getInternalUrl('members'));
     }
     if ($terms = $request->getParameter('q')) {
         $q = sfGuardUserTable::getPublicNameSearchQuery($terms);
         $this->result_pager = new LsDoctrinePager($q, $page = 1, $num = 20);
     }
 }
コード例 #15
0
ファイル: actions.class.php プロジェクト: silky/littlesis
 public function executeJoin($request)
 {
     $userParams = $request->getParameter('user');
     $this->is_invited = false;
     $this->group = $request->getParameter('group');
     if ($this->group && $this->getUser()->isAuthenticated()) {
         $this->redirect('@groupView?name=' . $this->group);
     }
     //if there's an invitation code supplied, it should match an invitation generated by an invite
     if ($code = $request->getParameter('code')) {
         $profile = Doctrine_Query::create()->from('sfGuardUserProfile p')->where('p.invitation_code = ?', $code)->fetchOne();
         if ($profile) {
             $this->is_invited = true;
         }
     }
     if (!$this->is_invited) {
         $profile = new sfGuardUserProfile();
     }
     //if a network name is supplied
     if ($network_name = $request->getParameter('network')) {
         if ($network = LsListTable::getNetworkByDisplayName($network_name)) {
             $profile->home_network_id = $network["id"];
         }
     }
     $this->user_form = new UserJoinForm($profile);
     $this->profile = $profile;
     //if form is posted, validate
     if ($request->isMethod('post')) {
         //bind request params to form
         $captcha = array('recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'));
         $userParams = array_merge($userParams, array('captcha' => $captcha));
         $this->user_form->bind($userParams);
         //if public_name is valid, check that it's unique
         $errors = $this->user_form->getErrorSchema()->getErrors();
         if (!isset($errors['public_name'])) {
             $q = LsDoctrineQuery::create()->from('sfGuardUserProfile p')->where('p.public_name LIKE ?', $userParams['public_name']);
             if (in_array($userParams['public_name'], sfGuardUserProfileTable::$prohibitedPublicNames) || $q->count()) {
                 $validatorSchema = $this->user_form->getValidatorSchema();
                 $validatorSchema['public_name']->setMessage('invalid', 'Sorry, the public name you chose is already taken!');
                 $this->user_form->getErrorSchema()->addError(new sfValidatorError($validatorSchema['public_name'], 'invalid'), 'public_name');
             }
         }
         //look for user with duplicate email
         $q = LsDoctrineQuery::create()->from('sfGuardUserProfile p')->where('REPLACE(p.email, \'.\', \'\') = REPLACE(?, \'.\', \'\')', $userParams['email']);
         //if user was invited, the duplicate user shouldn't have the same code
         //if ($code)
         //{
         //  $q->addWhere('p.invitation_code <> ?', $code);
         //}
         if ($q->count()) {
             $request->setError('email', 'There is already a user with that email');
         }
         //proceed if there are no errors
         if ($this->user_form->isValid() && !$request->hasErrors()) {
             //if user is invited, consider user confirmed
             if ($this->is_invited) {
                 $user = $profile->User;
                 $user->is_active = true;
                 $profile->invitation_code = null;
                 $profile->is_visible = true;
                 $profile->is_confirmed = true;
             } else {
                 $user = new sfGuardUser();
                 //auto-approve?
                 $user->is_active = sfConfig::get('app_accounts_auto_approve') ? true : false;
             }
             $db = Doctrine_Manager::connection();
             try {
                 $db->beginTransaction();
                 //save submitted email as password
                 $user->username = $userParams['email'];
                 $user->algorithm = 'sha1';
                 $user->setPassword($userParams['password1']);
                 if (!$user->hasPermission('contributor')) {
                     $user->addPermissionByName('contributor');
                 }
                 if (!$user->hasPermission('editor')) {
                     $user->addPermissionByName('editor');
                 }
                 $user->save();
                 //save submitted profile fields
                 $profile->user_id = $user->id;
                 $profile->name_first = $userParams['name_first'];
                 $profile->name_last = $userParams['name_last'];
                 $profile->email = $userParams['email'];
                 $profile->reason = $userParams['reason'];
                 $profile->analyst_reason = $userParams['analyst_reason'];
                 $profile->public_name = $userParams['public_name'];
                 $profile->home_network_id = $userParams['home_network_id'];
                 //if not invited, generate code for email confirmation
                 if (!$this->is_invited) {
                     $code = substr(sha1($profile->email . time()), 0, 20);
                     $profile->confirmation_code = $code;
                 }
                 $profile->save();
                 //add user to group, if requested
                 if ($this->group) {
                     $db = Doctrine_Manager::connection();
                     $sql = 'SELECT id FROM sf_guard_group WHERE name = ?';
                     $stmt = $db->execute($sql, array($this->group));
                     if ($groupId = $stmt->fetch(PDO::FETCH_COLUMN)) {
                         $ug = new sfGuardUserGroup();
                         $ug->user_id = $user->id;
                         $ug->group_id = $groupId;
                         $ug->is_owner = 0;
                         $ug->save();
                     }
                 }
                 //send email to notify administrator of new account creation
                 $mailBody = $this->getPartial('accountcreatenotify', array('user' => $user, 'analyst' => $userParams['analyst_reason'], 'group' => $this->group));
                 if ($this->is_invited) {
                     $subject = 'LittleSis account invitation accepted by ' . $userParams['name_first'] . ' ' . $userParams['name_last'];
                 } else {
                     $subject = 'LittleSis account ' . ($user->is_active ? 'created' : 'requested') . ' by ' . $userParams['name_first'] . ' ' . $userParams['name_last'];
                 }
                 $mailer = new Swift(new Swift_Connection_NativeMail());
                 $message = new Swift_Message($subject, $mailBody, 'text/plain');
                 $address = new Swift_Address(sfConfig::get('app_mail_join_sender_address'), sfConfig::get('app_mail_join_sender_name'));
                 $mailer->send($message, sfConfig::get('app_mail_join_sender_address'), $address);
                 $mailer->disconnect();
                 //notify user that the account has been created/requested
                 $subject = $user->is_active ? 'Welcome to LittleSis!' : 'Your request to become a LittleSis analyst';
                 $mailBody = $this->getPartial($user->is_active ? 'accountcreatereceipt' : 'accountrequestreceipt', array('user' => $user, 'password' => $userParams['password1'], 'is_invited' => $this->is_invited));
                 $mailer = new Swift(new Swift_Connection_NativeMail());
                 $message = new Swift_Message('Welcome to LittleSis!', $mailBody, 'text/plain');
                 $address = new Swift_Address(sfConfig::get('app_mail_join_sender_address'), sfConfig::get('app_mail_join_sender_name'));
                 $mailer->send($message, $profile->email, $address);
                 $mailer->disconnect();
                 //if invited, sign in user and record login time
                 if ($this->is_invited) {
                     // signin user
                     $this->getUser()->setAttribute('user_id', $user->id, 'sfGuardSecurityUser');
                     $this->getUser()->setAuthenticated(true);
                     $this->getUser()->clearCredentials();
                     $this->getUser()->addCredentials($user->getAllPermissionNames());
                     // save last login
                     $user->last_login = date('Y-m-d H:i:s');
                     $user->save();
                 }
                 //commit changes
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollback();
                 throw $e;
             }
             //redirect to requested or joined page
             if ($user->is_active) {
                 $this->redirect('home/joined' . ($this->is_invited ? '?conf=1' : ''));
             } else {
                 $this->redirect('home/requested');
             }
         }
     }
 }
コード例 #16
0
 /**
  *
  * @param sfWebRequest $request
  * @param LdapForm $form
  */
 protected function processLdap(sfWebRequest $request, LdapForm $form)
 {
     $form->bind($request->getParameter('signin'));
     if ($form->isValid()) {
         $values = $form->getValues();
         // Check if user already exists in the DB
         $user = Doctrine::getTable('sfGuardUser')->findOneByUsername($values["username"]);
         // If not, create an account for him
         if (empty($user)) {
             $datetime = date("Y-m-d H:i:s");
             // Create entry in sfGuardUser
             $sfGuardUser = new sfGuardUser();
             $sfGuardUser->setEmailAddress($values["username"]);
             $sfGuardUser->setUsername($values["username"]);
             $sfGuardUser->setFirstName($values["firstname"]);
             $sfGuardUser->setLastName($values["lastname"]);
             $sfGuardUser->setCreatedAt($datetime);
             $sfGuardUser->setUpdatedAt($datetime);
             $sfGuardUser->save();
             // Additional informations for user's profile
             $sfGuardUserProfile = new sfGuardUserProfile();
             $sfGuardUserProfile->setUserId($sfGuardUser->getId());
             $sfGuardUserProfile->setToken(MiscUtils::generateToken());
             $sfGuardUserProfile->setSecurityLevel(sfConfig::get("app_security_level_new_user", 0));
             $sfGuardUserProfile->save();
             $permission = Doctrine_Core::getTable("sfGuardPermission")->findOneByName(sfConfig::get("app_permission_new_user", "User"));
             if (!$permission) {
                 $this->getUser()->setFlash("error", "Unable to set permissions for this account! Contact your administrator.");
                 $sfGuardUserProfile->delete();
                 $sfGuardUser->delete();
                 return;
             }
             // Give basic permissions for user
             $sfGuardPermission = new sfGuardUserPermission();
             $sfGuardPermission->setUserId($sfGuardUser->getId());
             $sfGuardPermission->setPermissionId($permission->getId());
             $sfGuardPermission->setCreatedAt($datetime);
             $sfGuardPermission->setUpdatedAt($datetime);
             $sfGuardPermission->save();
             $userGroup = Doctrine_Core::getTable("sfGuardGroup")->findOneByName(sfConfig::get("app_project_group"));
             if (!$userGroup) {
                 $this->getUser()->setFlash("error", "Unable to set project group for this account! Contact your administrator.");
                 $sfGuardUserProfile->delete();
                 $sfGuardUser->delete();
                 $sfGuardPermission->delete();
                 return;
             }
             // Create new entry into sfGuardUserGroup table
             $sfGuardGroup = new sfGuardUserGroup();
             $sfGuardGroup->setUserId($sfGuardUser->getId());
             $sfGuardGroup->setGroupId($userGroup->getId());
             $sfGuardGroup->setCreatedAt($datetime);
             $sfGuardGroup->setUpdatedAt($datetime);
             $sfGuardGroup->save();
             $user = $sfGuardUser;
         }
         $this->getUser()->signIn($user, array_key_exists('remember', $values) ? $values['remember'] : false);
         // Set the tow previous referer to the same value for:
         // 1) redirect to previous user's location
         // 2) avoid redirect loop in signin
         $this->getUser()->setReferer($this->getUser()->getReferer());
         // Redirect to referer
         return $this->redirect($this->getUser()->getReferer());
     }
 }