Created
October 9, 2014 20:30
-
-
Save weierophinney/56a040d680d225839658 to your computer and use it in GitHub Desktop.
Example of a custom ZF\OAuth2 PdoAdapter implementation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyLib; | |
use ZF\OAuth2\Adapter\PdoAdapter; | |
class OAuth2PdoAdapter extends PdoAdapter | |
{ | |
protected $mapper; | |
public function setUsersMapper(Users\MapperInterface $mapper) | |
{ | |
$this->mapper = $mapper; | |
} | |
public function checkUserCredentials($username, $password) | |
{ | |
return $this->mapper->validate($username, $password); | |
} | |
public function getUser($username) | |
{ | |
$user = $this->mapper->fetch($username, $asArray = true); | |
if (! $user) { | |
return false; | |
} | |
unset( | |
$user['activated'], | |
$user['activated_date'], | |
$user['activation_key'], | |
$user['password'] | |
); | |
return array_merge(array( | |
'user_id' => $username, | |
), $user->getArrayCopy()); | |
} | |
public function setUser($username, $password, $firstName = null, $lastName = null) | |
{ | |
$user = $this->mapper->create( | |
$username, | |
$password, | |
sprintf('%s %s', $firstName, $lastName), | |
$asArray = true | |
); | |
if (false === $user) { | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment