From f806d373fa170b65ec21b61ab4edab78c20f5a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 23 Jan 2014 13:07:54 +0100 Subject: [PATCH] [add] UserProvider --- src/Poche/User/UserProvider.php | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Poche/User/UserProvider.php diff --git a/src/Poche/User/UserProvider.php b/src/Poche/User/UserProvider.php new file mode 100644 index 0000000..9fa4632 --- /dev/null +++ b/src/Poche/User/UserProvider.php @@ -0,0 +1,43 @@ +conn = $conn; + } + + public function loadUserByUsername($username) + { + $stmt = $this->conn->executeQuery('SELECT * FROM users WHERE username = ?', array(strtolower($username))); + if (!$user = $stmt->fetch()) { + throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); + } + + return new User($user['username'], $user['password'], explode(',', $user['roles']), true, true, true, true); + } + + public function refreshUser(UserInterface $user) + { + if (!$user instanceof User) { + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); + } + + return $this->loadUserByUsername($user->getUsername()); + } + + public function supportsClass($class) + { + return $class === 'Symfony\Component\Security\Core\User\User'; + } +} \ No newline at end of file