def management(): """Provides a quick management screen for users, clients and tokens.""" if request.method == 'POST' and request.form['submit'] == 'Add User': # Create a new user if the 'Add User' form has been sent. User.save(request.form['username'], request.form['password']) if request.method == 'POST' and request.form['submit'] == 'Add Client': # Create a new client if the 'Add Client' form has been sent. Client.generate() # Show the management page. return render_template( 'management.html', users=User.all(), clients=Client.all(), tokens=Token.all() )
def lookup_token(self, token_type, token): if token_type == 'request': token_type = Token.REQUEST elif token_type == 'access': token_type = Token.ACCESS logger.warning("!!! In GAEOAuthDataStore.lookup_token key_:%s, token_type: %s"%(token,token_type)) request_tokens = Token.all()\ .filter('key_ =',token)\ .filter('token_type =',token_type).fetch(1000) if len(request_tokens) == 1: self.request_token = request_tokens[0] return self.request_token elif len(request_tokens) == 0: return None else: raise Exception('More then one %s token matches token "%s"'%(token_type,token))
def sync(request): """ It's the cron job that gets run every 2 minutes (or on request). Iterates over users and queues tasks to sync. Will only 'iterate' over the current user if called by a logged in user. """ tokens = [] if (request.user.is_anonymous()): tokens = Token.all().fetch(1000) else: tokens.append(Token.gql( "WHERE user = :1", str(request.user) ).get()) for t in tokens: taskqueue.add(url='/syncworker/?user=%s' % str(t.user), method='GET') """ We cannot return a redirect when called anonymously as a cron job. Google App Engine will complain about 'Too many continues.' """ if (request.user.is_anonymous()): return render_to_response('firecheckin/index.html') else: return redirect( "/" )