Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tags to the tag lib to be able to check if connected or disconn…

…ected and show content based on that.
  • Loading branch information...
commit 3928098f6504f5cb1db4636c16ad124ed4c8079b 1 parent 8fb3440
@ssherriff ssherriff authored
View
38 grails-app/taglib/uk/co/desirableobjects/oauth/scribe/OauthTagLib.groovy
@@ -1,11 +1,14 @@
package uk.co.desirableobjects.oauth.scribe
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
+import org.scribe.model.Token
class OauthTagLib {
static namespace = 'oauth'
+ OauthService oauthService
+
def connect = { attrs, body ->
String provider = attrs.provider
@@ -19,4 +22,39 @@ class OauthTagLib {
}
+ def connected = { attrs, body ->
+
+ String provider = attrs.provider
+
+ if (!provider) {
+ throw new GrailsTagException('No provider specified for <oauth:connect /> tag. Try <oauth:connect provider="your-provider-name" />')
+ }
+
+ String sessionKey = oauthService.findSessionKeyForAccessToken(provider)
+ Token oauthToken = session[sessionKey]
+
+ if (oauthToken) {
+ out << body()
+ }
+
+ }
+
+ def disconnected = { attrs, body ->
+
+ String provider = attrs.provider
+
+ if (!provider) {
+ throw new GrailsTagException('No provider specified for <oauth:connect /> tag. Try <oauth:connect provider="your-provider-name" />')
+ }
+
+ String sessionKey = oauthService.findSessionKeyForAccessToken(provider)
+ Token oauthToken = session[sessionKey]
+
+ if (!oauthToken) {
+
+ out << body()
+ }
+
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.