def get(cls, endpoint): # TODO: To be refactored id_ = cls.get_arg('id') if id_: sprite = cls.find_one({'id': id_}) sprite['vote'] = SpriteVote.get_vote(sprite['id']) sprite['votes'] = SpriteVote.get_sprite_votes(sprite['id']) if not sprite: return json_response({'error': 'not found'}, code=404) return sprite offset = int(cls.get_arg('offset', 0)) limit = min(int(cls.get_arg('limit', 15)), 15) sort = cls.get_arg('sort', 'top') if sort == 'top': return SpriteVote.get_top(offset, limit) cursor = cls.find({}).sort('created_on', cls.DESCENDING) cursor = cursor.skip(offset).limit(limit) retval = list(cursor) for s in retval: s['vote'] = SpriteVote.get_vote(s['id']) s['votes'] = SpriteVote.get_sprite_votes(s['id']) return retval
def decorated_function(self, resource, *args, **kwargs): if resource not in self.resources.keys(): return json_response({'error': 'resource not found'}, code=404) resource = self.resources[resource] if hasattr(resource, func.__name__): return getattr(resource, func.__name__)(self, *args, **kwargs) return func(self, resource, *args, **kwargs)
def post(self): """Logs a user in""" email = self.get_arg('email') password = self.get_arg('password', '') user = User.authenticate(email, password) if not user: return json_response({'error': 'not authenticated'}, code=401) return set_user(user)
def post(self): """Register a user""" user = User.find_one({'email': self.get_arg('email')}) if user: return json_response({'error': 'email unavailable'}, code=400) # Username registration user = User.get_or_create( email=self.get_arg('email'), password=self.get_arg('password'), ) # Logging in return set_user(user)
def delete(cls, endpoint): return json_response({'error': 'not authorized'}, code=401)
def decorated_function(self, *args, **kwargs): missing = [a for a in required_args if self.get_arg(a) is None] if len(missing) > 0: return json_response({'missing': missing}, code=400) return func(self, *args, **kwargs)
def get(self): """Check if a user is logged in""" user = get_user() if not user: return json_response({'error': 'not logged in'}, code=401) return user
def get(self): """Check email existence""" user = User.find_one({'email': self.get_arg('email')}) return json_response({'availability': not bool(user)}, code=401)