当前位置: 首页>>代码示例>>PHP>>正文


PHP sfGuardUser::hasPermission方法代码示例

本文整理汇总了PHP中sfGuardUser::hasPermission方法的典型用法代码示例。如果您正苦于以下问题:PHP sfGuardUser::hasPermission方法的具体用法?PHP sfGuardUser::hasPermission怎么用?PHP sfGuardUser::hasPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfGuardUser的用法示例。


在下文中一共展示了sfGuardUser::hasPermission方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: queryByUser

 public function queryByUser(sfGuardUser $user)
 {
     if ($user->hasPermission(myUser::CREDENTIAL_ADMIN)) {
         return $this->queryAll()->innerJoin('w.Petition p')->innerJoin('p.Campaign c')->where('p.status != ? AND c.status = ?', array(Petition::STATUS_DELETED, CampaignTable::STATUS_ACTIVE));
     }
     return $this->queryAll()->innerJoin('w.Petition p')->leftJoin('p.PetitionRights pr ON p.id = pr.petition_id and pr.user_id = ?', $user->getId())->innerJoin('p.Campaign c')->leftJoin('c.CampaignRights cr ON c.id = cr.campaign_id and cr.user_id = ?', $user->getId())->where('p.status != ? AND c.status = ?', array(Petition::STATUS_DELETED, CampaignTable::STATUS_ACTIVE))->andWhere('w.user_id = ? OR (cr.user_id = ? AND pr.user_id = ? AND cr.active = 1 AND pr.active = 1 AND (pr.admin = 1 OR pr.member = 1) AND (cr.admin = 1 OR cr.member = 1))', array($user->getId(), $user->getId(), $user->getId()));
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:7,代码来源:WidgetTable.class.php

示例2: queryByMember

 /**
  *
  * @param sfGuardUser $user
  * @return Doctrine_Query
  */
 public function queryByMember(sfGuardUser $user, $is_member = true, $deleted_too = false)
 {
     if ($user->hasPermission(myUser::CREDENTIAL_ADMIN)) {
         return $this->queryAll($deleted_too);
     }
     if ($is_member) {
         return $this->queryAll($deleted_too)->innerJoin('c.CampaignRights cr')->andWhere('cr.user_id = ? AND cr.active = ?', array($user->getId(), 1));
     } else {
         return $this->queryAll($deleted_too)->andWhere('c.id NOT IN (SELECT cr.campaign_id FROM CampaignRights cr WHERE cr.user_id = ? AND cr.active = ?)', array($user->getId(), 1));
     }
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:16,代码来源:CampaignTable.class.php

示例3: queryForUser

 public function queryForUser(sfGuardUser $user, $stati = null)
 {
     $query = $this->queryAll();
     if (!$user->hasPermission(myUser::CREDENTIAL_ADMIN)) {
         $campaign_admin_ids = $user->getCampaignAdminIds();
         $petition_admin_ids = $user->getPetitionAdminIds();
         $ors = array('t.to_id = ?');
         $params = array($user->getId());
         if ($campaign_admin_ids) {
             $ors[] = 't.campaign_id IN ?';
             $params[] = $campaign_admin_ids;
         }
         if ($petition_admin_ids) {
             $ors[] = 't.petition_id IN ?';
             $params[] = $petition_admin_ids;
         }
         $query->where(implode(' OR ', $ors), $params);
     }
     $query->andWhere('t.to_id IS NULL OR t.to_id = ?', $user->getId());
     if ($stati) {
         $query->andWhereIn('t.status', $stati);
     }
     return $query;
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:24,代码来源:TicketTable.class.php

示例4: catch

try {
    $activeUser->addGroupByName('test-group');
    $t->pass('->addGroupByName() does not throw an exception if group exist');
} catch (Exception $e) {
    $t->diag($e->getMessage());
    $t->fail('->addGroupByName() does not throw an exception if group exist');
}
$t->is($activeUser->getGroupNames(), array('test-group'), '->getGroupNames() return array with group names');
$t->is($activeUser->hasGroup('test-group'), true, '->hasGroup() return true if user has this group');
// permission managment
$t->diag('permission managment');
$t->is($activeUser->getPermissionNames(), array(), '->getPermissionNames() return empty array if no permission is set');
try {
    $activeUser->addPermissionByName('test-permission');
    $t->fail('->addPermissionByName() does throw an exception if group not exist');
} catch (Exception $e) {
    $t->pass('->addPermissionByName() does throw an exception if group not exist');
}
$permission = new sfGuardPermission();
$permission->name = 'test-permission';
$permission->save();
$t->is($activeUser->hasPermission('test-permission'), false, '->hasPermission() return false if user hasn\'t this group');
try {
    $activeUser->addPermissionByName('test-permission');
    $t->pass('->addPermissionByName() does not throw an exception if permission exist');
} catch (Exception $e) {
    $t->diag($e->getMessage());
    $t->fail('->addPermissionByName() does not throw an exception if permission exist');
}
$t->is($activeUser->getPermissionNames(), array('test-permission'), '->getPermissionNames() return array with permission names');
$t->is($activeUser->hasPermission('test-permission'), true, '->hasPermission() return true if user has this group');
开发者ID:limitium,项目名称:uberlov,代码行数:31,代码来源:PluginsfGuardUserTest.php

示例5: executeJoin

 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));
//.........这里部分代码省略.........
开发者ID:silky,项目名称:littlesis,代码行数:101,代码来源:actions.class.php

示例6: queryByUserCampaigns

 /**
  *
  * @param sfGuardUser $user
  * @return Doctrine_Query
  */
 public function queryByUserCampaigns(sfGuardUser $user, $fetch_rights = false, $deleted_too = false, $actionsOfUser = null)
 {
     $admin = $user->hasPermission(myUser::CREDENTIAL_ADMIN);
     if ($admin) {
         $query = $this->queryAll($deleted_too);
         if (!$deleted_too) {
             $query->leftJoin('p.Campaign c')->andWhere('c.status = ?', CampaignTable::STATUS_ACTIVE);
         }
     } else {
         $query = $this->queryAll($deleted_too)->leftJoin('p.Campaign c')->innerJoin('c.CampaignRights cr')->andWhere('cr.user_id = ? AND cr.active = 1 AND (cr.member = 1 OR cr.admin = 1)', $user->getId());
         if (!$deleted_too) {
             $query->andWhere('c.status = ?', CampaignTable::STATUS_ACTIVE);
         }
     }
     $joined_action_rights = false;
     if ($fetch_rights && !$admin) {
         $query->leftJoin('p.PetitionRights pr')->andWhere('pr.user_id = ? OR pr.user_id is null', $user->getId())->select('p.*, c.*, cr.*, pr.*');
         $joined_action_rights = true;
     }
     if ($actionsOfUser === true && !$admin) {
         if (!$joined_action_rights) {
             $query->leftJoin('p.PetitionRights pr')->andWhere('pr.user_id = ? OR pr.user_id is null', $user->getId());
         }
         $query->andWhere('pr.active = 1 AND (pr.member = 1 OR pr.admin = 1)');
     }
     return $query;
 }
开发者ID:uniteddiversity,项目名称:policat,代码行数:32,代码来源:PetitionTable.class.php


注:本文中的sfGuardUser::hasPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。