diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-01 06:04:47 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2010-07-01 06:04:47 +0000 |
commit | 69c5921fb2472f5cafa050dae088120ad17ed23a (patch) | |
tree | db2bbd8dc4439139b6278408c82cec495b06d0d9 /sca-cpp/trunk | |
parent | 8e35575af73a89217bc5f9dc14dd59428f5ee39a (diff) |
Support user and email properties in WSGI integration.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@959523 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk')
-rw-r--r-- | sca-cpp/trunk/modules/wsgi/scdl.py | 21 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/Makefile.am | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/app.yaml | 2 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/domain-frontend.composite | 15 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/domain-single.composite | 1 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/domain.composite | 1 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/htdocs/store.html | 16 | ||||
-rw-r--r-- | sca-cpp/trunk/samples/store-gae/shopping-cart.py | 12 |
8 files changed, 46 insertions, 24 deletions
diff --git a/sca-cpp/trunk/modules/wsgi/scdl.py b/sca-cpp/trunk/modules/wsgi/scdl.py index 2a4a667173..a50bba3b7a 100644 --- a/sca-cpp/trunk/modules/wsgi/scdl.py +++ b/sca-cpp/trunk/modules/wsgi/scdl.py @@ -96,7 +96,7 @@ def properties(e): return () if match(car(e), "start", "property") == False: return properties(cdr(e)) - return cons(text(car(e)), properties(cdr(e))) + return cons((att(car(e))["name"], text(car(e))), properties(cdr(e))) # Return the list of services under a SCDL component element def services(e): @@ -189,17 +189,26 @@ def evalReference(r, comps): # value. The user and email properties are configured with the values # from the HTTP request, if any def evalProperty(p): - if (isTaggedList(p, "user")): + if car(p) == "user": return lambda: userProperty(cadr(p)) - if (isTaggedList(p, "email")): + if car(p) == "email": return lambda: emailProperty(cadr(p)) - return lambda: p + return lambda: cadr(p) + +def currentUser(): + try: + from google.appengine.api import users + return users.get_current_user() + except: + return None def userProperty(v): - return "nobody" + user = currentUser() + return user.user_id() if user else v def emailProperty(v): - return "nobody@nowhere.com" + user = currentUser() + return user.email() if user else v # Evaluate a component, resolve its implementation, references and # properties diff --git a/sca-cpp/trunk/samples/store-gae/Makefile.am b/sca-cpp/trunk/samples/store-gae/Makefile.am index 59a8b82ce7..98e5814dca 100644 --- a/sca-cpp/trunk/samples/store-gae/Makefile.am +++ b/sca-cpp/trunk/samples/store-gae/Makefile.am @@ -27,7 +27,7 @@ target.stamp: app.yaml *.py *.composite $(top_builddir)/modules/wsgi/*.py htdocs cp app.yaml *.py *.composite `ls $(top_builddir)/modules/wsgi/*.py | grep -v "\-test"` target mkdir -p target/htdocs cp -R htdocs/* target/htdocs - mkdir target/htdocs/js + mkdir -p target/htdocs/js cp -R $(top_builddir)/modules/server/htdocs/js/* target/htdocs/js touch target.stamp diff --git a/sca-cpp/trunk/samples/store-gae/app.yaml b/sca-cpp/trunk/samples/store-gae/app.yaml index e5807c233a..6a4e6a2fab 100644 --- a/sca-cpp/trunk/samples/store-gae/app.yaml +++ b/sca-cpp/trunk/samples/store-gae/app.yaml @@ -45,8 +45,10 @@ handlers: static_files: htdocs/\1
upload: htdocs/(.*\.(html|png))
secure: always
+ login: required
- url: /.*
script: composite.py
secure: always
+ login: required
diff --git a/sca-cpp/trunk/samples/store-gae/domain-frontend.composite b/sca-cpp/trunk/samples/store-gae/domain-frontend.composite index a183c84a76..f84b9ba500 100644 --- a/sca-cpp/trunk/samples/store-gae/domain-frontend.composite +++ b/sca-cpp/trunk/samples/store-gae/domain-frontend.composite @@ -27,15 +27,9 @@ <service name="Widget"> <t:binding.http uri="store"/> </service> - <reference name="catalog"> - <t:binding.http uri="https://sca-store-backend.appspot.com/catalog"/> - </reference> - <reference name="shoppingCart"> - <t:binding.http uri="https://sca-store-backend.appspot.com/shoppingCart"/> - </reference> - <reference name="shoppingTotal"> - <t:binding.http uri="https://sca-store-backend.appspot.com/shoppingCart"/> - </reference> + <reference name="catalog" target="Catalog"/> + <reference name="shoppingCart" target="ShoppingCart/Cart"/> + <reference name="shoppingTotal" target="ShoppingCart/Total"/> </component> <component name="Catalog"> @@ -49,7 +43,7 @@ <component name="ShoppingCart"> <t:implementation.python script="shopping-cart.py"/> - <service name="ShoppingCart"> + <service name="Cart"> <t:binding.atom uri="shoppingCart"/> </service> <service name="Total"> @@ -58,6 +52,7 @@ <reference name="cache"> <t:binding.http uri="https://sca-store-backend.appspot.com/cache"/> </reference> + <property name="email">anonymous@example.com</property> </component> <component name="CurrencyConverter"> diff --git a/sca-cpp/trunk/samples/store-gae/domain-single.composite b/sca-cpp/trunk/samples/store-gae/domain-single.composite index ce9c601a32..2863838e18 100644 --- a/sca-cpp/trunk/samples/store-gae/domain-single.composite +++ b/sca-cpp/trunk/samples/store-gae/domain-single.composite @@ -50,6 +50,7 @@ <t:binding.jsonrpc uri="total"/> </service> <reference name="cache" target="Cache"/> + <property name="email">anonymous@example.com</property> </component> <component name="CurrencyConverter"> diff --git a/sca-cpp/trunk/samples/store-gae/domain.composite b/sca-cpp/trunk/samples/store-gae/domain.composite index ce9c601a32..2863838e18 100644 --- a/sca-cpp/trunk/samples/store-gae/domain.composite +++ b/sca-cpp/trunk/samples/store-gae/domain.composite @@ -50,6 +50,7 @@ <t:binding.jsonrpc uri="total"/> </service> <reference name="cache" target="Cache"/> + <property name="email">anonymous@example.com</property> </component> <component name="CurrencyConverter"> diff --git a/sca-cpp/trunk/samples/store-gae/htdocs/store.html b/sca-cpp/trunk/samples/store-gae/htdocs/store.html index 4e2ee6795a..d52dd1adaf 100644 --- a/sca-cpp/trunk/samples/store-gae/htdocs/store.html +++ b/sca-cpp/trunk/samples/store-gae/htdocs/store.html @@ -51,8 +51,14 @@ }
document.getElementById('catalog').innerHTML=catalog;
catalogItems = items;
-
- shoppingTotal.apply("gettotal", shoppingTotal_gettotalResponse);
+ }
+
+ function shoppingCart_getemailResponse(email, exception) {
+ if(exception) {
+ alert(exception.message);
+ return;
+ }
+ document.getElementById('email').innerHTML = email;
}
function shoppingCart_getResponse(feed) {
@@ -76,6 +82,8 @@ }
}
}
+
+ shoppingTotal.apply("gettotal", shoppingTotal_gettotalResponse);
}
function shoppingTotal_gettotalResponse(total,exception) {
@@ -132,6 +140,7 @@ try {
catalog.apply("getcatalog", catalog_getcatalogResponse);
+ shoppingCart.apply("getemail", shoppingCart_getemailResponse);
shoppingCart.get("", shoppingCart_getResponse);
}
catch(e){
@@ -145,6 +154,7 @@ <body onload="init()">
<h1>Store</h1>
+<p>You're signed in as: <span id="email"></span><br/><a href="/_ah/login?continue=/store.html&action=Logout">Sign out</a></p>
<div id="store">
<h2>Catalog</h2>
<form name="catalogForm">
@@ -155,7 +165,7 @@ <br>
- <h2>Your Shopping Cart</h2>
+ <h2>Your Shopping Cart</h2>
<form name="shoppingCartForm">
<div id="shoppingCart"></div>
<br>
diff --git a/sca-cpp/trunk/samples/store-gae/shopping-cart.py b/sca-cpp/trunk/samples/store-gae/shopping-cart.py index d124ce8517..04ad729585 100644 --- a/sca-cpp/trunk/samples/store-gae/shopping-cart.py +++ b/sca-cpp/trunk/samples/store-gae/shopping-cart.py @@ -30,7 +30,7 @@ def getcart(id, cache): return cart # Post a new item to the cart, create a new cart if necessary -def post(collection, item, cache): +def post(collection, item, cache, email): id = str(uuid.uuid1()) cart = ((item[0], id, item[2]),) + getcart(cartId, cache) cache("put", (cartId,), cart) @@ -46,13 +46,13 @@ def find(id, cart): return find(id, cart[1:]) # Get items from the cart -def get(id, cache): +def get(id, cache, email): if id == (): return ("Your Cart", cartId) + getcart(cartId, cache) return find(id[0], getcart(cartId, cache)) # Delete items from the cart -def delete(id, cache): +def delete(id, cache, email): if id == (): return cache("delete", (cartId,)) return True @@ -68,7 +68,11 @@ def sum(items): return price(items[0]) + sum(items[1:]) # Return the total price of the items in the cart -def gettotal(cache): +def gettotal(cache, email): cart = getcart(cartId, cache) return sum(cart) +# Return the email of the cart owner +def getemail(cache, email): + return email() + |