Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cookie domain as module option #16

Merged
merged 1 commit into from
Aug 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What with L70? See #20 and #32.

}

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