Skip to content

Commit

Permalink
Add special handling for User authenticated and authorized properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 14, 2018
1 parent e6dd91f commit 8e0e3e8
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions system/src/Grav/Common/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

class User extends Data
{
protected $authenticated;
protected $authorized;

/**
* Load user account.
*
Expand Down Expand Up @@ -102,6 +105,55 @@ public static function remove($username)
return false;
}


public function offsetExists($offset)
{
if ($offset === 'authenticated') {
return null !== $this->authenticated;
}
if ($offset === 'authorized') {
return null !== $this->authorized;
}

return parent::offsetExists($offset);
}

public function offsetGet($offset)
{
if ($offset === 'authenticated') {
return null !== $this->authenticated ? $this->authenticated : false;
}
if ($offset === 'authorized') {
return null !== $this->authorized ? $this->authorized : $this->authenticated;
}

return parent::offsetGet($offset);
}

public function offsetSet($offset, $value)
{
if ($offset === 'authenticated') {
$this->authenticated = (bool)$value;
}
if ($offset === 'authorized') {
$this->authorized = (bool)$value;
}

parent::offsetSet($offset, $value);
}

public function offsetUnset($offset)
{
if ($offset === 'authenticated') {
$this->authenticated = null;
}
if ($offset === 'authorized') {
$this->authorized = null;
}

parent::offsetUnset($offset);
}

/**
* Authenticate user.
*
Expand Down

0 comments on commit 8e0e3e8

Please sign in to comment.