-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from donbeave/master
Improved delete cookie method.
- Loading branch information
Showing
13 changed files
with
105 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,71 @@ | ||
/* | ||
* Copyright 2012 the original author or authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import grails.util.Holders | ||
import javax.servlet.http.HttpServletRequest | ||
|
||
/** | ||
* @author <a href='mailto:[email protected]'>Dale Wiggins</a> | ||
* @author <a href='mailto:[email protected]'>Sergey Ponomarev</a> | ||
* @author <a href='mailto:[email protected]'>Alexey Zhokhov</a> | ||
*/ | ||
class CookieGrailsPlugin { | ||
/** the plugin version */ | ||
def version = '0.51' | ||
/** the version or versions of Grails the plugin is designed for */ | ||
|
||
def version = '0.52' | ||
def grailsVersion = '2.1 > *' | ||
/** the other plugins this plugin depends on */ | ||
def dependsOn = [:] | ||
/** resources that are excluded from plugin packaging */ | ||
def pluginExcludes = [ | ||
'grails-app/views/error.gsp' | ||
] | ||
|
||
def author = 'Dale Wiggins' | ||
def authorEmail = '[email protected]' | ||
def title = 'Cookie Plugin' | ||
def description = 'Makes dealing with cookies easy. Provides an injectable service and expands request with methods to easily get, set, and delete cookies with one line' | ||
|
||
def cookieService = new com.dalew.CookieService() | ||
|
||
def observe = ['controllers'] | ||
|
||
/** URL to the plugin's documentation */ | ||
def documentation = 'https://github.com/dalew75/grails-cookie' | ||
|
||
/** License: one of 'APACHE', 'GPL2', 'GPL3' */ | ||
def license = 'APACHE' | ||
|
||
/** Any additional developers beyond the author specified above. */ | ||
def developers = [[name: 'Sergey Ponomarev', email: 'stokito@gmail.com']] | ||
|
||
/** Location of the plugin's issue tracker. */ | ||
def issueManagement = [system: 'github', url: 'https://github.com/dalew75/grails-cookie/issues'] | ||
def developers = [ | ||
[name: 'Dale Wiggins', email: 'dale@dalew.com'], | ||
[name: 'Sergey Ponomarev', email: '[email protected]'], | ||
[name: 'Alexey Zhokhov', email: '[email protected]'] | ||
] | ||
|
||
/** Online location of the plugin's browseable source code. */ | ||
def issueManagement = [system: 'GITHUB', url: 'https://github.com/dalew75/grails-cookie/issues'] | ||
def scm = [url: 'https://github.com/dalew75/grails-cookie'] | ||
|
||
def doWithDynamicMethods = { applicationContext -> | ||
extendReqResp() | ||
def doWithDynamicMethods = { applicationContext -> | ||
extendReqResp() | ||
} | ||
|
||
def onChange = { event -> | ||
extendReqResp() | ||
} | ||
|
||
void extendReqResp() { | ||
javax.servlet.http.HttpServletRequest.metaClass.getCookie = { String name -> | ||
return cookieService.getCookie(name) | ||
HttpServletRequest.metaClass.getCookie = { String name -> | ||
return Holders.applicationContext.cookieService.getCookie(name) | ||
} | ||
javax.servlet.http.HttpServletResponse.metaClass.setCookie = { String name, String value, Integer maxAge = null -> | ||
return cookieService.setCookie(name, value, maxAge) | ||
HttpServletRequest.metaClass.setCookie = { String name, String value, Integer maxAge = null -> | ||
return Holders.applicationContext.cookieService.setCookie(name, value, maxAge) | ||
} | ||
javax.servlet.http.HttpServletResponse.metaClass.deleteCookie = { String name -> | ||
return cookieService.deleteCookie(name) | ||
HttpServletRequest.metaClass.deleteCookie = { String name, String domain = null -> | ||
return Holders.applicationContext.cookieService.deleteCookie(name, domain) | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#Grails Metadata file | ||
#Sat Oct 05 07:05:45 EDT 2013 | ||
app.grails.version=2.3.0 | ||
app.name=cookie | ||
#Grails Metadata file | ||
#Sun Jun 08 13:35:14 CST 2014 | ||
app.grails.version=2.4.0 | ||
app.name=cookie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
// configuration for plugin testing - will not be included in the plugin zip | ||
|
||
log4j = { | ||
// Example of changing the log pattern for the default console | ||
// appender: | ||
// | ||
//appenders { | ||
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n') | ||
//} | ||
|
||
error 'org.codehaus.groovy.grails.web.servlet', // controllers | ||
'org.codehaus.groovy.grails.web.pages', // GSP | ||
'org.codehaus.groovy.grails.web.sitemesh', // layouts | ||
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping | ||
'org.codehaus.groovy.grails.web.mapping', // URL mapping | ||
'org.codehaus.groovy.grails.commons', // core / classloading | ||
'org.codehaus.groovy.grails.plugins', // plugins | ||
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration | ||
'org.springframework', | ||
'org.hibernate', | ||
'net.sf.ehcache.hibernate' | ||
error 'org.codehaus.groovy.grails.web.servlet', // controllers | ||
'org.codehaus.groovy.grails.web.pages', // GSP | ||
'org.codehaus.groovy.grails.web.sitemesh', // layouts | ||
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping | ||
'org.codehaus.groovy.grails.web.mapping', // URL mapping | ||
'org.codehaus.groovy.grails.commons', // core / classloading | ||
'org.codehaus.groovy.grails.plugins', // plugins | ||
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration | ||
'org.springframework', | ||
'org.hibernate', | ||
'net.sf.ehcache.hibernate' | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,29 @@ | ||
/* | ||
* Copyright 2012 the original author or authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.dalew | ||
|
||
import javax.servlet.http.Cookie | ||
import org.codehaus.groovy.grails.web.util.WebUtils | ||
|
||
import javax.servlet.http.Cookie | ||
|
||
/** | ||
* @author <a href='mailto:[email protected]'>Dale Wiggins</a> | ||
* @author <a href='mailto:[email protected]'>Sergey Ponomarev</a> | ||
* @author <a href='mailto:[email protected]'>Alexey Zhokhov</a> | ||
*/ | ||
class CookieService { | ||
|
||
/** Default cookie age is 30 days */ | ||
|
@@ -89,16 +110,18 @@ class CookieService { | |
} | ||
|
||
/** Deletes the named cookie */ | ||
void deleteCookie(String name) { | ||
void deleteCookie(String name, String domain = null) { | ||
assert name | ||
log.info "Removing cookie \"${name}\"" | ||
Cookie cookie = createCookie(name, null, 0) | ||
if (domain) | ||
cookie.domain = domain | ||
writeCookieToResponse(cookie) | ||
} | ||
|
||
/** Deletes the named cookie */ | ||
void deleteCookie(Cookie cookie) { | ||
deleteCookie(cookie.name) | ||
deleteCookie(cookie.name, cookie.domain) | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.