Skip to content

Commit

Permalink
Merge pull request #10 from donbeave/master
Browse files Browse the repository at this point in the history
Improved delete cookie method.
  • Loading branch information
Dale Wiggins committed Jun 21, 2014
2 parents f7d15e2 + 27f2be7 commit f63d4df
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 181 deletions.
68 changes: 41 additions & 27 deletions CookieGrailsPlugin.groovy
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)
}
}

}
}
8 changes: 4 additions & 4 deletions application.properties
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
42 changes: 8 additions & 34 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -1,47 +1,21 @@
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.class.dir = 'target/classes'
grails.project.test.class.dir = 'target/test-classes'
grails.project.test.reports.dir = 'target/test-reports'

grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]

grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolver = 'maven'
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
inherits('global')
log 'warn'
repositories {
grailsCentral()
mavenLocal()
mavenCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.24'
}

}
plugins {
build(":release:3.0.0",
":rest-client-builder:1.0.3") {
build(':release:3.0.1', ':rest-client-builder:2.0.1') {
export = false
}
}
Expand Down
31 changes: 11 additions & 20 deletions grails-app/conf/Config.groovy
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'
}
45 changes: 0 additions & 45 deletions grails-app/conf/DataSource.groovy

This file was deleted.

13 changes: 0 additions & 13 deletions grails-app/conf/UrlMappings.groovy

This file was deleted.

Empty file.
29 changes: 26 additions & 3 deletions grails-app/services/com/dalew/CookieService.groovy
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 */
Expand Down Expand Up @@ -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)
}

/**
Expand Down
16 changes: 15 additions & 1 deletion grails-app/taglib/com/dalew/CookieTagLib.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
/*
* 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


class CookieTagLib {

static namespace = 'cookie'
Expand Down
10 changes: 0 additions & 10 deletions scripts/_Install.groovy

This file was deleted.

5 changes: 0 additions & 5 deletions scripts/_Uninstall.groovy

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/_Upgrade.groovy

This file was deleted.

9 changes: 0 additions & 9 deletions web-app/js/application.js

This file was deleted.

0 comments on commit f63d4df

Please sign in to comment.