Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

get users email address

  • Loading branch information...
commit ae055cb7fcdd7fca375ce5af5f59d00885e11354 1 parent c8ddb31
@nsb authored
Showing with 35 additions and 8 deletions.
  1. +6 −0 example.html
  2. +29 −8 unfriended.py
View
6 example.html
@@ -10,6 +10,12 @@
{% if current_user %}
<p><a href="{{ current_user.profile_url }}"><img src="http://graph.facebook.com/{{ current_user.id }}/picture?type=square"/></a></p>
<p>Hello, {{ current_user.name|escape }}</p>
+ {% if not current_user.email %}
+ <form method="post" action="">
+ <input type="text" name="email" />
+ <input type="submit" value="Add email" />
+ </form>
+ {% endif %}
{% endif %}
<div id="fb-root"></div>
View
37 unfriended.py
@@ -30,7 +30,7 @@
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
-
+from google.appengine.api import mail
class User(db.Model):
id = db.StringProperty(required=True)
@@ -39,6 +39,7 @@ class User(db.Model):
name = db.StringProperty(required=True)
profile_url = db.StringProperty(required=True)
access_token = db.StringProperty(required=True)
+ email = db.EmailProperty(required=False)
class Friend(db.Model):
id = db.StringProperty(required=True)
@@ -79,6 +80,15 @@ def current_user(self):
self._current_user = user
return self._current_user
+class NotifyUnfriendedWorker(webapp.RequestHandler):
+ """
+ Notify on unfriended
+ """
+ def post(self):
+ key = self.request.get('key')
+ friend = Friend.get_by_key_name(key)
+ logging.info('unfriended:%s' % friend.name)
+
class SyncFriendsWorker(webapp.RequestHandler):
"""
To activate worker:
@@ -92,11 +102,11 @@ def post(self):
friend_ids = set((f["id"] for f in friends))
# check for unfriends
- for friend in user.friends:
+ for friend in user.friends.filter("unfriended =", False):
if friend.id not in friend_ids:
- logging.info('unfriend:%s' % friend.name)
- else:
- logging.info('friend:%s' % friend.name)
+ friend.unfriended = True
+ friend.put()
+ taskqueue.add(url='/notifyunfriended', params={'key': friend.key()})
# update all friends
for friend in friends:
@@ -118,15 +128,26 @@ def get(self):
self.response.out.write(template.render(path, args))
def post(self):
+
key = self.request.get('key')
+ if key:
+ taskqueue.add(url='/syncfriends', params={'key': key})
+
+ email = self.request.get('email')
+ if mail.is_email_valid(email):
+ # prompt user to enter a valid address:
+ self.current_user.email = email
+ self.current_user.put()
- # Add the task to the default queue.
- taskqueue.add(url='/syncfriends', params={'key': key})
self.redirect('/')
def main():
logging.getLogger().setLevel(logging.DEBUG)
- util.run_wsgi_app(webapp.WSGIApplication([(r"/", HomeHandler), (r"/syncfriends", SyncFriendsWorker),]))
+ util.run_wsgi_app(webapp.WSGIApplication([
+ (r"/", HomeHandler),
+ (r"/syncfriends", SyncFriendsWorker),
+ (r"/notifyunfriended", NotifyUnfriendedWorker),
+ ]))
if __name__ == "__main__":
main()
Please sign in to comment.
Something went wrong with that request. Please try again.