psecio / gatekeeper

Gatekeeper: An Authentication & Authorization Library
367 stars 23 forks source link

Adding groups on user creation doesn't seem to work #26

Closed Ser5 closed 9 years ago

Ser5 commented 9 years ago

If I use following code:

$gkUserData = array(
    'username'      => $userData['email_address'],
    'password'      => '111111',
    'email'         => $userData['email_address'],
    'first_name'    => $userData['first_name'],
    'last_name'     => $userData['last_name'],
    'groups'        => array($groupId),
);
Gatekeeper::register($gkUserData);
//Gatekeeper::findUserByUsername($userData['email_address'])->addGroup($groupId);
foreach (Gatekeeper::findUserByUsername($userData['email_address'])->groups as $group) {
    var_dump($group->name);
}

var_dump() vardumps me nothing. If I uncomment the line with addGroup() method, var_dump() gives me right results.

Also please note that Gatekeeper::register() doesn't return the id of newly created user, so instead of Gatekeeper::findUserById($userId) I have to use somewhat inconvenient Gatekeeper::findUserByUsername($userData['email_address'])

Note 2: http://gatekeeper-auth.readthedocs.org/en/latest/users/#creating-users

// Use can use permission names
$credentials['groups'] = array('group1', 'group2');

should be changed to

// Use can use group names
$credentials['groups'] = array('group1', 'group2');
enygma commented 9 years ago

register now returns the model on success, false on failure in 85023c3. As far as the groups and permissions creation on the user registration, I'm honestly not sure where that part in the docs came from. I don't see functionality that was designed to handle that.

enygma commented 9 years ago

The functionality to add these was added in release 2.6.1. Closing this issue.