Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated Authsome::set() and added Authsome::remove()

- Fixed issues where setting hashes would work improperly
- Added Authsome::remove() method, as well as AuthsomeComponent->remove()
  • Loading branch information...
commit 5eb2d45dfdbe56afe0c045193bf863b4420be21a 1 parent 3ad73bd
@josegonzalez josegonzalez authored
Showing with 47 additions and 10 deletions.
  1. +47 −10 controllers/components/authsome.php
View
57 controllers/components/authsome.php
@@ -67,24 +67,57 @@ public function get($field = null) {
return Set::extract($user, $field);
}
- public function set($field = null, $value = null) {
- if ($field === null) {
+ public function set($fields = null, $value = null) {
+ if ($fields === null) {
return false;
}
+ if (!is_array($fields)) {
+ $fields = array($fields => $value);
+ }
+
$user = $this->Session->read($this->settings['sessionKey']);
- if (!$user) {
+ if (empty($user)) {
+ $user = array();
+ }
+
+ foreach ($fields as $field => $value) {
+ if (strstr($field, '.') === false) {
+ $user[$this->settings['model']][$field] = $value;
+ } else {
+ $user = Set::insert($user, $field, $value);
+ }
+ }
+
+ $this->Session->write($this->settings['sessionKey'], $user);
+ Configure::write($this->settings['sessionKey'], $user);
+ return true;
+ }
+
+ public function delete($fields = null) {
+ if ($fields === null) {
return false;
}
- if (is_array($field)) {
- $userFields = array_merge($user[$this->settings['model']], $fields);
- $this->Session->write($this->settings['sessionKey'] . '.' . $this->settings['model'], $userFields);
- Configure::write($this->settings['sessionKey'] . '.' . $this->settings['model'], $userFields);
- } else {
- $this->Session->write($this->settings['sessionKey'] . '.' . $this->settings['model'] . '.' . $field, $value);
- Configure::write($this->settings['sessionKey'] . '.' . $this->settings['model'] . '.' . $field, $value);
+ if (!is_array($fields)) {
+ $fields = (array) $fields;
}
+
+ $user = $this->Session->read($this->settings['sessionKey']);
+ if (!$user) {
+ return true;
+ }
+
+ foreach ($fields as $field) {
+ if (strstr($field, '.') === false) {
+ unset($user[$this->settings['model']][$field]);
+ } else {
+ $user = Set::remove($user, $field, $value);
+ }
+ }
+
+ $this->Session->write($this->settings['sessionKey'], $user);
+ Configure::write($this->settings['sessionKey'], $user);
return true;
}
@@ -246,6 +279,10 @@ public static function set($field = null, $value = null) {
return self::instance()->set($field, $value);
}
+ public static function delete($field = null, $value = null) {
+ return self::instance()->delete($field, $value);
+ }
+
public static function login($type = 'credentials', $credentials = null) {
return self::instance()->login($type, $credentials);
}
Please sign in to comment.
Something went wrong with that request. Please try again.