public function savesfGuardUserPermissionList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['sf_guard_user_permission_list'])) {
         // somebody has unset this widget
         return;
     }
     if (null === $con) {
         $con = $this->getConnection();
     }
     $c = new Criteria();
     $c->add(sfGuardUserPermissionPeer::PERMISSION_ID, $this->object->getPrimaryKey());
     sfGuardUserPermissionPeer::doDelete($c, $con);
     $values = $this->getValue('sf_guard_user_permission_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new sfGuardUserPermission();
             $obj->setPermissionId($this->object->getPrimaryKey());
             $obj->setUserId($value);
             $obj->save();
         }
     }
 }
예제 #2
0
 public function addPermissionByName($name, $con = null)
 {
     $permission = Doctrine::getTable('sfGuardPermission')->findOneByName($name);
     if (!$permission) {
         throw new Exception(sprintf('The permission "%s" does not exist.', $name));
     }
     $up = new sfGuardUserPermission();
     $up->setsfGuardUser($this);
     $up->setsfGuardPermission($permission);
     $up->save($con);
 }
예제 #3
0
 /**
  * Filter the query by a related sfGuardUserPermission object
  *
  * @param     sfGuardUserPermission $sfGuardUserPermission  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 filterBysfGuardUserPermission($sfGuardUserPermission, $comparison = null)
 {
     if ($sfGuardUserPermission instanceof sfGuardUserPermission) {
         return $this->addUsingAlias(sfGuardUserPeer::ID, $sfGuardUserPermission->getUserId(), $comparison);
     } elseif ($sfGuardUserPermission instanceof PropelCollection) {
         return $this->usesfGuardUserPermissionQuery()->filterByPrimaryKeys($sfGuardUserPermission->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterBysfGuardUserPermission() only accepts arguments of type sfGuardUserPermission or PropelCollection');
     }
 }
예제 #4
0
 public function addPermissionByName($name, $con = null)
 {
     $permission = sfGuardPermissionPeer::retrieveByName($name);
     if (!$permission) {
         throw new Exception(sprintf('The permission "%s" does not exist.', $name));
     }
     $up = new sfGuardUserPermission();
     $up->setsfGuardUser($this);
     $up->setPermissionId($permission->getId());
     $up->save($con);
 }
 /**
  * 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      sfGuardUserPermission $value A sfGuardUserPermission object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(sfGuardUserPermission $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getUserId(), (string) $obj->getPermissionId()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
예제 #6
0
 public function savepermissionsList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['permissions_list'])) {
         // somebody has unset this widget
         return;
     }
     if (is_null($con)) {
         $con = $this->getConnection();
     }
     $q = Doctrine_Query::create()->delete()->from('sfGuardUserPermission r')->where('r.user_id = ?', current($this->object->identifier()))->execute();
     $values = $this->getValue('permissions_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new sfGuardUserPermission();
             $obj->user_id = current($this->object->identifier());
             $obj->permission_id = $value;
             $obj->save();
         }
     }
 }
 public function executePermissions(sfWebRequest $request)
 {
     $module = 'sfGuardUser';
     if (!in_array($module, array_keys(sfPlop::getSafePluginModules()))) {
         $this->redirect('@sf_plop_dashboard');
     }
     if ($request->isMethod(sfRequest::POST)) {
         if ($request->isXmlHttpRequest()) {
             $this->setTemplate('ajaxPermissions');
             $this->setLayout(false);
         }
         $group_id = $request->getParameter('g');
         $user_id = $request->getParameter('u');
         $permission_id = $request->getParameter('p');
         if ($group_id) {
             $group_exists = sfPlopGuard::groupExists($group_id);
             if (!$group_exists && $request->isXmlHttpRequest()) {
                 return sfView::ERROR;
             } else {
                 if (!$group_exists) {
                     $this->redirect('@sf_plop_dashboard_permissions');
                 }
             }
         }
         if ($user_id) {
             $user_exists = sfPlopGuard::userExists($user_id);
             if (!$user_exists && $request->isXmlHttpRequest()) {
                 return sfView::ERROR;
             } else {
                 if (!$user_exists) {
                     $this->redirect('@sf_plop_dashboard_permissions');
                 }
             }
         }
         if (isset($group_exists) && isset($user_exists)) {
             $user_group = sfGuardUserGroupPeer::retrieveByPK($user_id, $group_id);
             if ($user_group) {
                 $user_group->delete();
             } else {
                 $user_group = new sfGuardUsergroup();
                 $user_group->setUserId($user_id);
                 $user_group->setGroupId($group_id);
                 $user_group->save();
                 $this->getResponse()->setStatusCode(201);
             }
         }
         if ($permission_id) {
             if ($permission_id == 'super') {
                 if (!sfPlopGuard::isLastSuperAdminUser($user_id)) {
                     $user = sfGuardUserPeer::retrieveByPK($user_id);
                     if ($user->getIsSuperAdmin()) {
                         $user->setIsSuperAdmin(false);
                     } else {
                         $user->setIsSuperAdmin(true);
                     }
                     $user->save();
                 } else {
                     $this->getResponse()->setStatusCode(202);
                     return sfView::ERROR;
                 }
             } else {
                 if (!is_int($permission_id)) {
                     $permission_exists = sfPlopGuard::permissionExists($permission_id);
                     if (!$permission_exists) {
                         $modules = sfPlop::getSafePluginModules();
                         if ($request->isXmlHttpRequest() && !isset($modules[$permission_id])) {
                             return sfView::ERROR;
                         } elseif (!isset($modules[$permission_id])) {
                             $this->redirect('@sf_plop_dashboard_permissions');
                         } else {
                             $module = $modules[$permission_id];
                         }
                         $permission = new sfGuardPermission();
                         $permission->setName($permission_id);
                         $permission->setDescription($module['name']);
                         $permission->save();
                         $permission_id = $permission->getId();
                         $this->getResponse()->setStatusCode(201);
                     } else {
                         $permission_id = sfPlopGuard::getPermission($permission_id)->getId();
                     }
                 } else {
                     $permission_exists = sfPlopGuard::permissionExists($permission_id);
                     if (!$permission_exists && $request->isXmlHttpRequest()) {
                         return sfView::ERROR;
                     } else {
                         if (!$permission_exists) {
                             $this->redirect('@sf_plop_dashboard_permissions');
                         }
                     }
                 }
                 if (isset($user_exists)) {
                     $user_permission = sfGuardUserPermissionPeer::retrieveByPK($user_id, $permission_id);
                     if ($user_permission) {
                         $user_permission->delete();
                     } else {
                         $user_permission = new sfGuardUserPermission();
                         $user_permission->setUserId($user_id);
                         $user_permission->setPermissionId($permission_id);
                         $user_permission->save();
                         $this->getResponse()->setStatusCode(201);
                     }
                 } elseif (isset($group_exists)) {
                     $group_permission = sfGuardGroupPermissionPeer::retrieveByPK($group_id, $permission_id);
                     if ($group_permission) {
                         $group_permission->delete();
                     } else {
                         $group_permission = new sfGuardGroupPermission();
                         $group_permission->setGroupId($group_id);
                         $group_permission->setPermissionId($permission_id);
                         $group_permission->save();
                         $this->getResponse()->setStatusCode(201);
                     }
                 }
             }
         }
         if (!$request->isXmlHttpRequest()) {
             $this->redirect('@sf_plop_dashboard_permissions');
         }
     }
     $this->groups = sfPlopGuard::getAllGroups();
     $this->users = sfPlopGuard::getAllUsers();
     $this->permissions = sfPlopGuard::getAllPermissions();
 }
예제 #8
0
 /**
  * @param	sfGuardUserPermission $sfGuardUserPermission The sfGuardUserPermission object to add.
  */
 protected function doAddsfGuardUserPermission($sfGuardUserPermission)
 {
     $this->collsfGuardUserPermissions[] = $sfGuardUserPermission;
     $sfGuardUserPermission->setsfGuardUser($this);
 }
예제 #9
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';
             }
         }
     }
 }
예제 #10
0
 public function addsfGuardUserPermission(sfGuardUserPermission $l)
 {
     $this->collsfGuardUserPermissions[] = $l;
     $l->setsfGuardUser($this);
 }
 /**
  * Adds the user a permission from its name.
  *
  * @param string $name The permission name
  * @param Doctrine_Connection $con A Doctrine_Connection object
  * @throws sfException
  */
 public function addPermissionByName($name, $con = null)
 {
     $permission = Doctrine_Core::getTable('sfGuardPermission')->findOneByName($name);
     if (!$permission) {
         throw new sfException(sprintf('The permission "%s" does not exist.', $name));
     }
     $up = new sfGuardUserPermission();
     $up->setUser($this);
     $up->setPermission($permission);
     $up->save($con);
     // add permission to local vars
     $this->_allPermissions[$permission->getName()] = $permission;
 }
 /**
  * Exclude object from result
  *
  * @param     sfGuardUserPermission $sfGuardUserPermission Object to remove from the list of results
  *
  * @return    sfGuardUserPermissionQuery The current query, for fluid interface
  */
 public function prune($sfGuardUserPermission = null)
 {
     if ($sfGuardUserPermission) {
         $this->addCond('pruneCond0', $this->getAliasedColName(sfGuardUserPermissionPeer::USER_ID), $sfGuardUserPermission->getUserId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(sfGuardUserPermissionPeer::PERMISSION_ID), $sfGuardUserPermission->getPermissionId(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
     }
     return $this;
 }
예제 #13
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());
     }
 }
예제 #14
0
 /**
  * Filter the query by a related sfGuardUserPermission object
  *
  * @param     sfGuardUserPermission $sfGuardUserPermission  the related object to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return    sfGuardPermissionQuery The current query, for fluid interface
  */
 public function filterBysfGuardUserPermission($sfGuardUserPermission, $comparison = null)
 {
     return $this->addUsingAlias(sfGuardPermissionPeer::ID, $sfGuardUserPermission->getPermissionId(), $comparison);
 }