def get_user(self, invite_code_name=None): user = None google_user = users.get_current_user() # not logged in to google if google_user == None: self.redirect(users.create_login_url(self.request.uri)) return None user = User.get_by_google_user(google_user) # user was not in our database, so its a first-time login if user == None: user = User(google_user = google_user, first_name='', last_name='', email=google_user.email() ) user.put() # now we have a user, but are they whitelisted # or do they have an invite? if invite_code_name != None: invite_code = InviteCode.get_by_name(invite_code_name) # is this code valid? if invite_code != None and invite_code.use_code() == True: user.is_whitelisted = True user.put() else: user = None elif user.is_whitelisted != True: user = None # this enables admins to see pages in any user's context if self.request.get('admin', None) == 'true' and user.email in admins: user_email = self.request.get('user_email') user = User.get_by_email(user_email) # if we've gotten this far and the user is none, it means this user is # not whitelisted if user == None: self.redirect(users.create_logout_url('/no-invite')) return user
def get(self): google_user = users.get_current_user() if google_user != None: user = User.get_by_google_user(google_user) if user != None and user.is_whitelisted: self.redirect('/dashboard'); else: self.redirect(users.create_logout_url('/no-invite')) f = open('ui/html/home.html') html = f.read() login_url = users.create_login_url(self.request.uri) params = { 'login_url': login_url, 'template_metrics': TemplateMetric.json_list() } html = html % params self.response.out.write(html)