summaryrefslogtreecommitdiff
path: root/app/Auth/RememberMeAuth.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-12-05 20:31:27 -0500
committerFrederic Guillot <fred@kanboard.net>2015-12-05 20:31:27 -0500
commite9fedf3e5cd63aea4da7a71f6647ee427c62fa49 (patch)
treeabc2de5aebace4a2d7c94805552264dab6b10bc7 /app/Auth/RememberMeAuth.php
parent346b8312e5ac877ce3192c2db3a26b500018bbb5 (diff)
Rewrite of the authentication and authorization system
Diffstat (limited to 'app/Auth/RememberMeAuth.php')
-rw-r--r--app/Auth/RememberMeAuth.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/app/Auth/RememberMeAuth.php b/app/Auth/RememberMeAuth.php
new file mode 100644
index 00000000..02b7b9f6
--- /dev/null
+++ b/app/Auth/RememberMeAuth.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Kanboard\Auth;
+
+use Kanboard\Core\Base;
+use Kanboard\Core\Security\PreAuthenticationProviderInterface;
+use Kanboard\User\DatabaseUserProvider;
+
+/**
+ * Rember Me Cookie Authentication Provider
+ *
+ * @package auth
+ * @author Frederic Guillot
+ */
+class RememberMeAuth extends Base implements PreAuthenticationProviderInterface
+{
+ /**
+ * User properties
+ *
+ * @access private
+ * @var array
+ */
+ private $userInfo = array();
+
+ /**
+ * Get authentication provider name
+ *
+ * @access public
+ * @return string
+ */
+ public function getName()
+ {
+ return 'RememberMe';
+ }
+
+ /**
+ * Authenticate the user
+ *
+ * @access public
+ * @return boolean
+ */
+ public function authenticate()
+ {
+ $credentials = $this->rememberMeCookie->read();
+
+ if ($credentials !== false) {
+ $session = $this->rememberMeSession->find($credentials['token'], $credentials['sequence']);
+
+ if (! empty($session)) {
+ $this->rememberMeCookie->write(
+ $session['token'],
+ $this->rememberMeSession->updateSequence($session['token']),
+ $session['expiration']
+ );
+
+ $this->userInfo = $this->user->getById($session['user_id']);
+
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Get user object
+ *
+ * @access public
+ * @return null|DatabaseUserProvider
+ */
+ public function getUser()
+ {
+ if (empty($this->userInfo)) {
+ return null;
+ }
+
+ return new DatabaseUserProvider($this->userInfo);
+ }
+}