예제 #1
0
    def follow(self, target, valid=False):


        """
        The current user follows the target account. 
        
        target: An instance of User
        valid: Boolean to force a valid Follow. This means that the user
                doesn't have to accept the follow
        """

        from models.followers import FollowerRelation

        FollowerRelation.create(user = self, follows =target, valid=valid)
        followers_increment = UserProfile.update({UserProfile.followers_count: UserProfile.followers_count + 1}).where(UserProfile.id == target.id)
        following_increment = UserProfile.update({UserProfile.following_count: UserProfile.following_count + 1}).where(UserProfile.id == self.id)

        following_increment.execute()
        followers_increment.execute()
예제 #2
0
def handle_follow(activity):
    followed = User.get_or_none(ap_id=activity.object)
    print("=> Handling follow")
    if followed:
        if isinstance(activity.actor, activities.Actor):
            ap_id = activity.actor.id
        elif isinstance(activity.actor, str):
            ap_id = activity.actor

        follower = ActivityPubId(ap_id).get_or_create_remote_user()
        FollowerRelation.create(
            user = follower,
            follows = followed
        )

        response = {'Type': 'Accept','Object':activity}


    else:
        print("error handling follow")
예제 #3
0
    def on_post(self, req, resp, username):
        user = User.get_or_none(username == username)

        if req.context['user'].username != username:
            resp.status = falcon.HTTP_401
            resp.body = json.dumps({"Error": "Access denied"})

        payload = req.get_param('data')
        activity = json.loads(payload, object_hook=as_activitystream)

        if activity.object.type == "Note":
            obj = activity.object
            activity = activities.Create(to=user.uris.followers,
                                         actor=user.uris.id,
                                         object=obj)

        activity.validate()

        if activity.type == "Create":
            if activity.object.type != "Note":
                resp.status = falcon.HTTP_500
                resp.body = json.dumps({"Error": "You only can create notes"})

                activity.object.id = photo.uris.id
                activity.id = store(activity, user)
                #deliver(activity)
                resp.body = json.dumps({"Success": "Delivered successfully"})
                resp.status = falcon.HTTP_200

                #Convert to jpeg

            else:
                resp.status = falcon.HTTP_500
                resp.body = json.dumps({"Error": "No photo attached"})

        if activity.type == "Follow":

            followed = ActivityPubId(
                activity.object).get_or_create_remote_user()
            user = req.context["user"]
            #print(followed.ap_id, user.username, followed.username)
            f = FollowerRelation.create(user=user, follows=followed)

            activity.actor = user.uris.id
            activity.to = followed.uris.id
            #activity.id = store(activity, user)
            deliver(activity)

            resp.body = json.dumps({"Success": "Delivered successfully"})
            resp.status = falcon.HTTP_200
예제 #4
0
connect()
create_tables()

passw = Argon2().generate_password_hash("test")

#yab = User.create(username="******")
yab, created = User.get_or_create(username="******",
                                  defaults={
                                      'password':passw,
                                      'preferredUsername': "******",
                                      "name": "Yabir Test",
                                      'email':"*****@*****.**",
                                      'confirmation_sent_at':datetime.datetime.now(),
                                      'last_sign_in_at':1
                                  })

lol, created = User.get_or_create(username="******", password=passw, email="*****@*****.**", confirmation_sent_at=datetime.datetime.now(),last_sign_in_at=1)
FollowerRelation.create(
    user = lol,
    follows = yab,
    valid = True
)
"""
photos = (Status.select().where(Status.upload_date >= datetime.date.today()))

for photo in photos:
    print(photo)
    print(photo.json())

"""