diff options
author | Chris Cornutt <enygma@phpdeveloper.org> | 2015-07-03 06:18:59 -0500 |
---|---|---|
committer | Chris Cornutt <enygma@phpdeveloper.org> | 2015-07-03 06:18:59 -0500 |
commit | a526d65710f9790e031fbf45bdb8ea6399ed0431 (patch) | |
tree | 1b4f601e3aa25088930d6cf6419792d83f0df261 | |
parent | 6c5330e65e24d50ade2c10b313e2ec9445f90bbe (diff) | |
download | gatekeeper-a526d65710f9790e031fbf45bdb8ea6399ed0431.zip gatekeeper-a526d65710f9790e031fbf45bdb8ea6399ed0431.tar.gz gatekeeper-a526d65710f9790e031fbf45bdb8ea6399ed0431.tar.bz2 |
adding expiration handling to adding user groups
-rw-r--r-- | docs/users.md | 17 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/GroupModel.php | 5 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/UserGroupModel.php | 5 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/UserModel.php | 10 |
4 files changed, 30 insertions, 7 deletions
diff --git a/docs/users.md b/docs/users.md index 347bf6e..489ff59 100644 --- a/docs/users.md +++ b/docs/users.md @@ -30,7 +30,7 @@ echo 'Full name: '.$user->firstName.' '.$user->lastName."\n"; ## Getting All Users -You can use the `findUsers` method on the `Gatekeeper` class to get a list (returnes a `UserCollection`) of the current users: +You can use the `findUsers` method on the `Gatekeeper` class to get a list (returns a `UserCollection`) of the current users: ```php $users = Gatekeeper::findUsers(); @@ -57,7 +57,7 @@ Gatekeeper::register($credentials); ``` The return value from the `register` call is a *boolean* indicating the pass/fail status of the registration. -Addiitonally, you can also link the user to permissions at create time: +Additionally, you can also link the user to permissions at create time: ```php <?php @@ -101,7 +101,7 @@ Gatekeeper::register($credentials); ## Removing users -Deleteing user records can be done with the `deleteUserById` method: +Deleting user records can be done with the `deleteUserById` method: ```php <?php @@ -165,11 +165,20 @@ You can add a user to a group by using the group ID: <?php $groupId = 1; if (Gatekeeper::findUserById($userId)->addGroup($groupId) === true) { - echo "User added successfullly!"; + echo "User added successfully!"; } ?> ``` +You can also grant the group to a user with an expiration time, giving them permissions until a certain time. You set the expiration as a second value on the `addGroup` method by passing in a Unix timestamp: + +```php +<?php +if (Gatekeeper::findUserById(1)->addGroup(1, strtotime('+1 day')) === true) { + echo "User added successfully!"; +} +``` + ## Revoking access to a group You can also remove a user from a group by revoking their access: diff --git a/src/Psecio/Gatekeeper/GroupModel.php b/src/Psecio/Gatekeeper/GroupModel.php index 899336b..5d7fe24 100644 --- a/src/Psecio/Gatekeeper/GroupModel.php +++ b/src/Psecio/Gatekeeper/GroupModel.php @@ -30,6 +30,11 @@ class GroupModel extends \Psecio\Gatekeeper\Model\Mysql 'column' => 'name', 'type' => 'varchar' ), + 'expire' => array( + 'description' => 'Expiration Date', + 'column' => 'expire', + 'type' => 'datetime' + ), 'created' => array( 'description' => 'Date Created', 'column' => 'created', diff --git a/src/Psecio/Gatekeeper/UserGroupModel.php b/src/Psecio/Gatekeeper/UserGroupModel.php index a8451b3..4c3269e 100644 --- a/src/Psecio/Gatekeeper/UserGroupModel.php +++ b/src/Psecio/Gatekeeper/UserGroupModel.php @@ -30,6 +30,11 @@ class UserGroupModel extends \Psecio\Gatekeeper\Model\Mysql 'column' => 'id', 'type' => 'integer' ), + 'expire' => array( + 'description' => 'Expiration Date', + 'column' => 'expire', + 'type' => 'datetime' + ), 'created' => array( 'description' => 'Date Created', 'column' => 'created', diff --git a/src/Psecio/Gatekeeper/UserModel.php b/src/Psecio/Gatekeeper/UserModel.php index 503fcf4..9389fb2 100644 --- a/src/Psecio/Gatekeeper/UserModel.php +++ b/src/Psecio/Gatekeeper/UserModel.php @@ -229,15 +229,19 @@ class UserModel extends \Psecio\Gatekeeper\Model\Mysql * @param integer|GroupModel $group Add the user to a group * @return boolean Success/fail of add */ - public function addGroup($group) + public function addGroup($group, $expire = null) { if ($group instanceof GroupModel) { $group = $group->id; } - $group = new UserGroupModel($this->getDb(), array( + $data = [ 'group_id' => $group, 'user_id' => $this->id - )); + ]; + if ($expire !== null && is_int($expire)) { + $data['expire'] = $expire; + } + $group = new UserGroupModel($this->getDb(), $data); return $this->getDb()->save($group); } |