Skip to content
This repository
Browse code

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
Jose Diaz-Gonzalez authored

Showing 1 changed file with 47 additions and 10 deletions. Show diff stats Hide diff stats

  1. 57  controllers/components/authsome.php
57  controllers/components/authsome.php
@@ -67,24 +67,57 @@ public function get($field = null) {
67 67
 		return Set::extract($user, $field);
68 68
 	}
69 69
 
70  
-	public function set($field = null, $value = null) {
71  
-		if ($field === null) {
  70
+	public function set($fields = null, $value = null) {
  71
+		if ($fields === null) {
72 72
 			return false;
73 73
 		}
74 74
 
  75
+		if (!is_array($fields)) {
  76
+			$fields = array($fields => $value);
  77
+		}
  78
+
75 79
 		$user = $this->Session->read($this->settings['sessionKey']);
76  
-		if (!$user) {
  80
+		if (empty($user)) {
  81
+			$user = array();
  82
+		}
  83
+
  84
+		foreach ($fields as $field => $value) {
  85
+			if (strstr($field, '.') === false) {
  86
+				$user[$this->settings['model']][$field] = $value;
  87
+			} else {
  88
+				$user = Set::insert($user, $field, $value);
  89
+			}
  90
+		}
  91
+
  92
+		$this->Session->write($this->settings['sessionKey'], $user);
  93
+		Configure::write($this->settings['sessionKey'], $user);
  94
+		return true;
  95
+	}
  96
+
  97
+	public function delete($fields = null) {
  98
+		if ($fields === null) {
77 99
 			return false;
78 100
 		}
79 101
 
80  
-		if (is_array($field)) {
81  
-			$userFields = array_merge($user[$this->settings['model']], $fields);
82  
-			$this->Session->write($this->settings['sessionKey'] . '.' . $this->settings['model'], $userFields);
83  
-			Configure::write($this->settings['sessionKey'] . '.' . $this->settings['model'], $userFields);
84  
-		} else {
85  
-			$this->Session->write($this->settings['sessionKey'] . '.' . $this->settings['model'] . '.' . $field, $value);
86  
-			Configure::write($this->settings['sessionKey'] . '.' . $this->settings['model'] . '.' . $field, $value);
  102
+		if (!is_array($fields)) {
  103
+			$fields = (array) $fields;
87 104
 		}
  105
+
  106
+		$user = $this->Session->read($this->settings['sessionKey']);
  107
+		if (!$user) {
  108
+			return true;
  109
+		}
  110
+
  111
+		foreach ($fields as $field) {
  112
+			if (strstr($field, '.') === false) {
  113
+				unset($user[$this->settings['model']][$field]);
  114
+			} else {
  115
+				$user = Set::remove($user, $field, $value);
  116
+			}
  117
+		}
  118
+
  119
+		$this->Session->write($this->settings['sessionKey'], $user);
  120
+		Configure::write($this->settings['sessionKey'], $user);
88 121
 		return true;
89 122
 	}
90 123
 
@@ -246,6 +279,10 @@ public static function set($field = null, $value = null) {
246 279
 		return self::instance()->set($field, $value);
247 280
 	}
248 281
 
  282
+	public static function delete($field = null, $value = null) {
  283
+		return self::instance()->delete($field, $value);
  284
+	}
  285
+
249 286
 	public static function login($type = 'credentials', $credentials = null) {
250 287
 		return self::instance()->login($type, $credentials);
251 288
 	}

0 notes on commit 5eb2d45

Please sign in to comment.
Something went wrong with that request. Please try again.