示例#1
0
def join(account, remember=False):
	# If this is the first user account, then allow to create and make admin
	users = UserAccount.query().fetch()
	if not users:
		logging.info("First user account, creating user as admin", account._User__email)
		user = UserAccount.create_user(account,make_admin=True)
		if user and flasklogin.login_user(user, remember):
			return True
	# First check domain in whitelist
	domain = account._User__email[account._User__email.index('@')+1:]
	logging.info("Checking domain %s for whitelist", domain)
	whitelistUser = Whitelist.query(Whitelist.domain==domain.lower()).get()
	if whitelistUser:
		logging.info("Domain %s is whitelisted, creating user account %s", domain, account._User__email)
		user = UserAccount.create_user(account)
		if user and flasklogin.login_user(user, remember):
			return True
	else:
		# Domain not in whitelist, check email address
		logging.info("Checking email address %s for whitelist", account._User__email)
		whitelistUser = Whitelist.query(Whitelist.domain==account._User__email.lower()).get()
		if whitelistUser:
			logging.info("Email address %s is whitelisted, creating user account", account._User__email)
			user = UserAccount.create_user(account)
			if user and flasklogin.login_user(user, remember):
				return True
	return False