diff --git a/README.md b/README.md index 418ec1a..9e8f9da 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,8 @@ The following options are available: `GoalioRememberMe\Entity\RememberMe`. - **cookie_expire** - Integer value in seconds when the login cookie should expire. Default is `2592000` (30 days). +- **cookie_domain** - String value for the domain this cookie should be set for. + Default is null. Security -------- diff --git a/config/goaliorememberme.global.php.dist b/config/goaliorememberme.global.php.dist index fe18f5c..efa0ca6 100644 --- a/config/goaliorememberme.global.php.dist +++ b/config/goaliorememberme.global.php.dist @@ -24,6 +24,14 @@ $settings = array( * Accepted values: the number of seconds the user should be remembered */ //'cookie_expire' => 2592000, + + /** + * Remember me cookie domain + * + * Default value: null (current domain) + * Accepted values: a string containing the domain (example.com), subdomains (sub.example.com) or the all subdomains qualifier (.example.com) + */ + //'cookie_domain' => null, /** * End of GoalioRememberMe configuration diff --git a/src/GoalioRememberMe/Options/ModuleOptions.php b/src/GoalioRememberMe/Options/ModuleOptions.php index 37bb585..5f2c71c 100644 --- a/src/GoalioRememberMe/Options/ModuleOptions.php +++ b/src/GoalioRememberMe/Options/ModuleOptions.php @@ -18,6 +18,11 @@ class ModuleOptions extends AbstractOptions implements */ protected $cookieExpire = 2592000; + /** + * @var string + */ + protected $cookieDomain = null; + /** * @var string */ @@ -42,4 +47,13 @@ public function setRememberMeEntityClass($rememberMeEntityClass) { public function getRememberMeEntityClass() { return $this->rememberMeEntityClass; } + + public function getCookieDomain() { + return $this->cookieDomain; + } + + public function setCookieDomain($cookieDomain) { + $this->cookieDomain = $cookieDomain; + return $this; + } } diff --git a/src/GoalioRememberMe/Options/RememberMeOptionsInterface.php b/src/GoalioRememberMe/Options/RememberMeOptionsInterface.php index 76c6266..b2d9cb3 100644 --- a/src/GoalioRememberMe/Options/RememberMeOptionsInterface.php +++ b/src/GoalioRememberMe/Options/RememberMeOptionsInterface.php @@ -13,4 +13,9 @@ public function setCookieExpire($seconds); * @return int */ public function getCookieExpire(); + + /** + * @return string + */ + public function getCookieDomain(); } diff --git a/src/GoalioRememberMe/Service/RememberMe.php b/src/GoalioRememberMe/Service/RememberMe.php index c187eaa..8581229 100644 --- a/src/GoalioRememberMe/Service/RememberMe.php +++ b/src/GoalioRememberMe/Service/RememberMe.php @@ -78,8 +78,9 @@ public static function getCookie() public function setCookie($entity) { $cookieLength = $this->getOptions()->getCookieExpire(); + $cookieDomain = $this->getOptions()->getCookieDomain(); $cookieValue = $entity->getUserId() . "\n" . $entity->getSid() . "\n" . $entity->getToken(); - return setcookie("remember_me", $cookieValue, time() + $cookieLength, '/', null, null, true); + return setcookie("remember_me", $cookieValue, time() + $cookieLength, '/', $cookieDomain, null, true); } /** @@ -143,4 +144,4 @@ public function getOptions() } return $this->options; } -} \ No newline at end of file +}