Skip to content

Commit

Permalink
Merge pull request #16 from stijnkoopal/feature/cookie-domain
Browse files Browse the repository at this point in the history
Add cookie domain as module option
  • Loading branch information
pdobrigkeit committed Aug 2, 2013
2 parents bda5dce + db89823 commit ebf614d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
8 changes: 8 additions & 0 deletions config/goaliorememberme.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/GoalioRememberMe/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ModuleOptions extends AbstractOptions implements
*/
protected $cookieExpire = 2592000;

/**
* @var string
*/
protected $cookieDomain = null;

/**
* @var string
*/
Expand All @@ -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;
}
}
5 changes: 5 additions & 0 deletions src/GoalioRememberMe/Options/RememberMeOptionsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ public function setCookieExpire($seconds);
* @return int
*/
public function getCookieExpire();

/**
* @return string
*/
public function getCookieDomain();
}
5 changes: 3 additions & 2 deletions src/GoalioRememberMe/Service/RememberMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -143,4 +144,4 @@ public function getOptions()
}
return $this->options;
}
}
}

0 comments on commit ebf614d

Please sign in to comment.