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(); } } }
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); }
/** * 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'; } } } }
/** * * @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()); } }