async def save(cls, user, activity): exists = await cls.find_one({"activity.id": activity["id"]}) if exists: if user.name in exists['users']: return False else: users = exists['users'] users.append(user.name) await cls.update_one( {'_id': exists.id}, {'$set': { "users": users, "updated": datetime.now() }}) await cls.cache.clear() else: # TODO validate actor and activity pg_id = random_object_id() # TODO how to get single object from inbox # activity = copy.deepcopy(activity) # activity["pg_id"] = pg_id await cls.insert_one({ "_id": pg_id, "users": [user.name], "activity": activity, "label": make_label(activity), "deleted": False, "first_user": user.name, "created": datetime.now() }) await cls.cache.clear() return True
async def setup_cached_user(app, loop): exists = await User.find_one(dict(name="cached")) if not exists: await User.create( { 'username': '******', 'password': random_object_id() }, app.base_url)
async def token_get(request, user): if not check_password_hash(user.password, request.json["password"]): return response.json({"zrada": "password incorrect"}, status=401) token = getattr(user, "token") if not token: token = random_object_id() #TODO make token expire await User.update_one({'name': request.json["username"]}, {'$set': { 'token': token }}) return response.json({'token': token})
async def token_get(request): user = await User.find_one( dict(name=request.json["username"].lower().lstrip('@'))) if not user: raise exceptions.NotFound("User not found") if not check_password_hash(user.password, request.json["password"]): return response.json({"error": "password incorrect"}, status=401) token = getattr(user, "token") if not token: token = random_object_id() #TODO make token expire await User.update_one({'name': request.json["username"]}, {'$set': { 'token': token }}) return response.json({'access_token': token})
def __init__(self, user, activity): super().__init__(user, activity) self.id = random_object_id() activity["id"] = f"{user.uri}/activity/{self.id}"
def __init__(self, user, activity): self.id = random_object_id() self.render = activity self.user = user activity["id"] = f"{user.uri}/activity/{self.id}"