def get(self, id): try: user = User.get_by_id(id) except AttributeError as e: return error(e, 400) except ValueError as e: return error(e, 404) return user.json()
def is_valid(self): """ Check if Like is valid Returns: True if user and post exist and the user is not the owner of the post """ user = User.get_by_id(self.user.id()) post = Post.get_by_id(self.post.id()) if user and post and not (post.user.id() == user.key.id()): return True return False
def verify_user_cookie(): """ Verifies the current user cookie Return: if current user id exist and hash cookie is verified """ if bool(request.cookies.get('user_id')): user_id = request.cookies.get('user_id').split('|')[0] key = User.get_by_id(long(user_id)) return bool(key) and hash_cookie(user_id) == request.cookies.get('user_id') return False
def get(self): """ REST get method Returns: A JSON object of the user with out their password Raises: LoginException: if user is not logged in """ if is_login(): user = User.get_by_id(current_user_id()) return jsonify(**user.to_safe_dict()) raise LoginException('not logged in')