app/soc/logic/accounts.py
changeset 1519 eb70b27696de
parent 1308 35b75ffcbb37
child 1520 ac407f5b10dc
equal deleted inserted replaced
1518:f6f43a1675eb 1519:eb70b27696de
    76     # currently logged-in user, so there is no conclusive way to check the
    76     # currently logged-in user, so there is no conclusive way to check the
    77     # Administration->Developers list in the App Engine console
    77     # Administration->Developers list in the App Engine console
    78     return False
    78     return False
    79   
    79   
    80   return user.is_developer
    80   return user.is_developer
    81 
       
    82 
       
    83 def isAccountAvailable(new_account,
       
    84                        existing_user=None, existing_key_name=None):
       
    85   """Returns True if Google Account is available for use by existing User.
       
    86   
       
    87   Args:
       
    88     new_account: a Google Account (users.User) object with a (possibly)
       
    89       new email
       
    90     existing_user: an existing User entity; default is None, in which case
       
    91       existing_key_name is used to look up the User entity
       
    92     existing_key_name: the key_name of an existing User entity, used
       
    93       when existing_user is not supplied; default is None
       
    94   """
       
    95   if not existing_user:
       
    96     existing_user = models.user.logic.getFromKeyName(existing_key_name)
       
    97 
       
    98   if existing_user:
       
    99     old_email = existing_user.account.email()
       
   100   else:
       
   101     old_email = None
       
   102 
       
   103   if new_account.email().lower() == old_email.lower():
       
   104     # "new" email is same as existing User wanting it, so it is "available"
       
   105     return True
       
   106   # else: "new" email truly is new to the existing User, so keep checking
       
   107 
       
   108   if not models.user.logic.getForFields({'account': new_account},
       
   109                                         unique=True):
       
   110     # new email address also does not belong to any other User,
       
   111     # so it is available
       
   112     return True
       
   113 
       
   114   # email does not already belong to this User, but to some other User
       
   115   return False