Yii Framework Forum: Rights Assignment On User Creation - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rights Assignment On User Creation Rate Topic: -----

#1 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 05 January 2013 - 07:03 PM

Hi everyone,
i'm using yii-user + rights extensions.
I would like to know if it would be possible to assign a role (keep using rights extension) for a user, during the user creation, with an yii-user custom field (a dropdownlist menu of the roles defined in rights), and not through the rights administration panel.

Thanks,

Lilli
0

#2 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 January 2013 - 10:17 AM

some additional information:
in my case only the administrator can create new users, through the "create new user" function of yii-user extension.
i would like to have a new dropdown field, so i can decide which is the role given to the user during his creation. this role must be recorded in rights (table AuthAssignment).
0

#3 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 06 January 2013 - 11:01 AM

Hi,

in your form:
<?php echo $form->dropDownList($model, 'reader_role', Rights::getAuthItemSelectOptions('2',array('Admin'))); ?>


2 : type of AuthItem (Role in this case)
array('Admin', '...') : array of roles to exclude

cheers
Hey Ho !
Let's go !
1

#4 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 January 2013 - 12:07 PM

thanks luc!
this is good for populating my dropdown menu with rights role, but i need a way to save the role in rights model, so in AuthAssigment table (remember that the form that we are using is for creating yii-user user and not for managing rights role).
do you know the easier way to do it?

thanks,

lilli
0

#5 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 06 January 2013 - 12:23 PM

assuming $reader_role is what you get from the form submission

$user = new User;
// do the user stuff here: 
...........

if($user->save()){
$auth=Yii::app()->authManager;
$auth->assign($reader_role,$user->id);
$this->redirect(array('view','id'=>$user->id));
}


assign function
Hey Ho !
Let's go !
1

#6 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 06 January 2013 - 12:41 PM

wow! great! thank you.

but does it works also with rights extension?
0

#7 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 06 January 2013 - 12:54 PM

yes, rights exetension is just a (great) front end for Yii's authManager
Hey Ho !
Let's go !
0

#8 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 09 January 2013 - 01:00 PM

hi luc,
and what if i want to revoke/change the role?
i've seen that there is a revoke function but i have to know which is the role to revoke. how can i get it?


update i've seen this http://www.yiiframew...uthItems-detail
0

#9 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 09 January 2013 - 01:23 PM

... but i can't get the values. why?

View Postlilli, on 09 January 2013 - 01:00 PM, said:

hi luc,
and what if i want to revoke/change the role?
i've seen that there is a revoke function but i have to know which is the role to revoke. how can i get it?


update i've seen this http://www.yiiframew...uthItems-detail

0

#10 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 09 January 2013 - 03:01 PM

... but i can't get the values. why?


could you provide me more informations on what you're trying to do ?
Hey Ho !
Let's go !
0

#11 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,654
  • Joined: 10-October 10
  • Location:Denmark

Posted 09 January 2013 - 04:06 PM

/* moved from General Discussion */
"Less noise - more signal"
0

#12 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 09 January 2013 - 04:47 PM

View Postluc, on 09 January 2013 - 03:01 PM, said:

... but i can't get the values. why?


could you provide me more informations on what you're trying to do ?


something like this but it doesn't work

	$auth=Yii::app()->authManager;
	$roles =$auth->getAuthItems('2',$user->id);
	if (!empty($roles)){
		foreach($roles as $role){
			$auth->revoke($role,$user->id);
		}
	}

0

#13 User is offline   lilli 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 19-April 12

Posted 09 January 2013 - 05:38 PM

now it works:

$auth=Yii::app()->authManager;
					$arrayAuthRoleItems=$auth->getAuthItems('2',$user->id);
$roles = array_keys($arrayAuthRoleItems);
if (!empty($roles)){
foreach($roles as $key=>$role){
    $auth->revoke($role,$user->id);
}
}

1

#14 User is offline   luc 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 211
  • Joined: 22-June 10
  • Location:france

Posted 10 January 2013 - 06:02 AM

good !
Hey Ho !
Let's go !
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users