示例#1
0
	def get_or_create_user_from_authid( self, auth_id, email = None, allow_create = True ):
		user = None
		user_with_same_auth_id = enki.libuser.get_EnkiUser_by_auth_id( auth_id )
		if user_with_same_auth_id:
			# if a user with the same auth id already exists but has a blank email: add the email to the account.
			# note: if the account has an email or they've removed their email, we don't overwrite it.
			if email and user_with_same_auth_id.email == None:
				user = self.set_email( email, user_with_same_auth_id.key.id())
			else:
				user = user_with_same_auth_id
		if not user and allow_create:
			# create a new user
			user = EnkiModelUser( email = email, auth_ids_provider = [ auth_id ])
			user.put()
		return user
示例#2
0
 def set_email(self, email, user_id=None):
     # set or change a user's email address
     user_key = EnkiModelUser.get_key_by_email(email)
     if email and (not user_key or user_key.id() == user_id):
         # if the email doesn't exist in the db or already belongs to the user:
         if user_id == None:
             # create a new user
             user = EnkiModelUser(email=email)
         else:
             # update existing user
             user = ndb.Key(EnkiModelUser, user_id).get()
             user.email = email
         user.put()
         return user
     else:
         return None
示例#3
0
	def set_email( self, email, user_id = None ):
	# set or change a user's email address
		user_key = enki.libuser.get_key_EnkiUser( email )
		if email and (not user_key or user_key.id() == user_id):
		# if the email doesn't exist in the db or already belongs to the user:
			if user_id == None:
				# create a new user
				user = EnkiModelUser( email = email )
			else:
				# update existing user
				user = ndb.Key( EnkiModelUser, user_id ).get()
				user.email = email
			user.put()
			return user
		else:
			return None
示例#4
0
 def get_or_create_user_from_authid(self,
                                    auth_id,
                                    email=None,
                                    allow_create=True):
     user = None
     user_with_same_auth_id = EnkiModelUser.get_by_auth_id(auth_id)
     if user_with_same_auth_id:
         # if a user with the same auth id already exists but has a blank email: add the email to the account.
         # note: if the account has an email or they've removed their email, we don't overwrite it.
         if email and user_with_same_auth_id.email == None:
             user = self.set_email(email, user_with_same_auth_id.key.id())
         else:
             user = user_with_same_auth_id
     if not user and allow_create:
         # create a new user
         user = EnkiModelUser(email=email, auth_ids_provider=[auth_id])
         user.put()
     return user
示例#5
0
	def get_or_create_user_from_authid( self, authId, email = None, allow_create = False ):
		user = None
		user_with_same_auth_id = EnkiModelUser.query( EnkiModelUser.auth_ids_provider == authId ).get()
		if user_with_same_auth_id:
			# if a user with the same auth id already exists but has a blank email: add the email to the account.
			# note: if the account has an email, we don't overwrite it.
			if email and user_with_same_auth_id.email == None:
				user = self.set_email( email, user_with_same_auth_id.key.id())
			else:
				user = user_with_same_auth_id
		elif email:
			# no user with the same auth id, but there is a user with the same email: add the auth id to the account
			user_with_same_email = EnkiModelUser.query( EnkiModelUser.email == email ).get()
			if user_with_same_email:
				colon = authId.find( ':' )
				provider_name = str( authId[ :colon ])
				provider_uid = str( authId[ colon+1: ])
				self.send_email( email, MSG.SEND_EMAIL_AUTH_NEW_SUBJECT(), MSG.SEND_EMAIL_AUTH_NEW_BODY( enki.libutil.get_local_url( 'profile' ), provider_name, provider_uid ) )
				user = self.set_authid( authId, user_with_same_email.key.id())
		if not user and allow_create:
			# create a new user
			user = EnkiModelUser( email = email, auth_ids_provider = [ authId ])
			user.put()
		return user