Rights Assignment On User Creation
#1
Posted 05 January 2013 - 07:03 PM
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
#2
Posted 06 January 2013 - 10:17 AM
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).
#3
Posted 06 January 2013 - 11:01 AM
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
Let's go !
#4
Posted 06 January 2013 - 12:07 PM
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
#5
Posted 06 January 2013 - 12:23 PM
$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
Let's go !
#7
Posted 06 January 2013 - 12:54 PM
Let's go !
#8
Posted 09 January 2013 - 01:00 PM
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
#9
Posted 09 January 2013 - 01:23 PM
lilli, on 09 January 2013 - 01:00 PM, said:
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
#10
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 ?
Let's go !
#11
Posted 09 January 2013 - 04:06 PM
#12
Posted 09 January 2013 - 04:47 PM
luc, 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); } }
#13
Posted 09 January 2013 - 05:38 PM
$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); } }