Skip to content

Commit

Permalink
Allow extensible user attribute information to be stored.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffRMoore committed Jul 18, 2010
1 parent 20c6cb5 commit cb2cd5c
Showing 1 changed file with 45 additions and 18 deletions.
63 changes: 45 additions & 18 deletions Solar/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Solar_Auth extends Solar_Base {
'moniker',
'uri',
'uid',
'info',
);

/**
Expand Down Expand Up @@ -242,6 +243,11 @@ public function __get($key)
if ($key == 'status' && ! $val) {
$val = Solar_Auth::ANON;
}

// special behavior for 'info'
if ($key == 'info' && ! $val) {
$val = array();
}

return $val;
}
Expand Down Expand Up @@ -406,6 +412,41 @@ public function isValid()
{
return $this->status == Solar_Auth::VALID;
}

/**
*
* Set user information. Only serializable information may be included.
*
* @param array $info Array of user attributes
*
* @return void
*
*/
protected function _setInfo($info = array())
{
// baseline user information
$base = array(
'handle' => null,
'moniker' => null,
'email' => null,
'uri' => null,
'uid' => null,
);

// Set default values for require info keys
$info = array_merge($base, (array) $info);

// Store any additional information gathered from the login protocol
// or from the backend storage.
$this->info = $info;

// For historical reasons, some user attributes get their own properties
$this->handle = $info['handle'];
$this->moniker = $info['moniker'];
$this->email = $info['email'];
$this->uri = $info['uri'];
$this->uid = $info['uid'];
}

/**
*
Expand All @@ -426,16 +467,8 @@ public function isValid()
*/
public function reset($status = Solar_Auth::ANON, $info = array())
{
// baseline user information
$base = array(
'handle' => null,
'moniker' => null,
'email' => null,
'uri' => null,
'uid' => null,
);

// reset the status

// canonicalize the status value
$this->status = strtoupper($status);

// change properties
Expand All @@ -451,14 +484,8 @@ public function reset($status = Solar_Auth::ANON, $info = array())
$info = null;
}

// set the user-info properties
$info = array_merge($base, (array) $info);
$this->handle = $info['handle'];
$this->moniker = $info['moniker'];
$this->email = $info['email'];
$this->uri = $info['uri'];
$this->uid = $info['uid'];

$this->_setInfo($info);

// reset the session id and delete previous session
$this->_session->regenerateId();

Expand Down

0 comments on commit cb2cd5c

Please sign in to comment.