views:

41

answers:

3

Is there a way to derive a user's email given his user_id?

+1  A: 

You can build a relationship between the email and the user_id,and then retrieve it as needed. If the user is logged in you can easily access both properties separately. http://code.google.com/intl/en/appengine/docs/python/users/userclass.html

Jorge
+1  A: 

However the user_id is not a hashed version of the email that can be reconstructed using some kind of algorithm.

mplungjan
A: 

It seems like it's not possible to derive an email from a user id. If you want to go from user_id to email, you must store both when the user is logged in, and then, when the user is not logged in, do a lookup to convert. Eg.

class Email(db.model):
  '''keyed by user_id'''
  email=db.EmailProperty()

def save_user():
  u=users.get_current_user()
  k=db.Key.from_path('Email',u.user_id())
  e=Email.get(k)
  if not e:
    Email(key=k, email=u.email()).put()

def get_email_from_user_id(id):
  '''No way to derive email without a lookup.'''
  k=db.Key.from_path('Email',id)
  return Email.get(k).email # raises exception if email is not found 
dpatru