Esempio n. 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
Esempio n. 2
0
def whitelist():
	cur_user = current_user()
	if cur_user:
		if cur_user.is_admin:
			if request.method == 'POST':
				domain = request.form["domain"].lower()
				whitelistDomain = Whitelist.query(Whitelist.domain==domain).get()			
				if not whitelistDomain:
					whitelistDomain = Whitelist(domain=domain)
					whitelistDomain.put()
			return render_response("whitelist.html")
		else:
			logging.info("User is not admin, cannot access whitelist")
			return redirect(url_for("index"))