def post(self):
        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            unfollow = self.request.get('unfollow')

            if unfollow != "":

                current_user = User.query(User.email == user.email())
                other_user = User.query(User.email == unfollow)

                current_user = current_user.get()
                other_user = other_user.get()

                # remove users from lists
                other_user.followers.remove(current_user.email)
                current_user.follow.remove(other_user.email)

                other_user.put()
                time.sleep(1)
                current_user.put()
                time.sleep(1)
    def post(self):

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            follow = self.request.get('follow')

            if follow != "":
                current_user = User.query(User.email == user.email())
                other_user = User.query(User.email == follow)

                current_user = current_user.get()
                other_user = other_user.get()

                # add users to corresponding lists
                if current_user.email not in other_user.followers:
                    other_user.followers.append(current_user.email)

                if follow not in current_user.follow:
                    current_user.follow.append(follow)

                other_user.put()
                time.sleep(1)
                current_user.put()
                time.sleep(1)
Exemple #3
0
    def get(self):

        # get users nickname
        def getNickname(email):
            query = User.query(User.email == email)
            nickname = query.get().nickname

            return nickname

        # get users nickname to add on search list
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)

            user_list = json.dumps(toret)

            return user_list

        jinja = jinja2.get_jinja2(app=self.app)
        user = users.get_current_user()
        if user == None:
            self.redirect(users.create_login_url("/"))
        else:
            user_id = user.user_id()
            user_info = User.query(User.id_user == user_id)
            user_atributes = user_info.get()

            #get user categories to not return duplicates
            user_categories = set(user_atributes.categories)

            # create nickname followers list
            toretFollowers = []
            for x in user_atributes.followers:
                toretFollowers.append(getNickname(x))

            # create nickname following list
            toretFollow = []
            for x in user_atributes.follow:
                toretFollow.append(getNickname(x))

            # get following user images
            imgs = []
            for nickname in toretFollow:
                follow_user = User.query(User.nickname == nickname)
                users_info = follow_user.get()
                imgs.append(Image.query(Image.autor == users_info.id_user))

            labels = {
                "user_logout": users.create_logout_url("/"),
                "user_info": user_info,
                "categories": user_categories,
                "current_user": True,
                "usersearch": getUsers(),
                "following": toretFollow,
                "followers": toretFollowers,
                "images": imgs
            }
            self.response.write(jinja.render_template("index.html", **labels))
Exemple #4
0
        def checkEmail(user_name):
            stored_user = User.query(User.email == user_name)
            toret = True
            if stored_user.count() == 0:
                toret = False

            return toret
 def getUsers():
     us = User.query()
     toret = []
     for u in us:
         toret.append(u.nickname)
     user_list = json.dumps(toret)
     return user_list
    def post(self):
        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            # get user nickname (its posible that he would change it)
            user_query = User.query(User.email == user.email())
            user_info = user_query.get()
            nick = user_info.nickname

            # receiving data
            comment = self.request.get('comment')
            id = self.request.get('id')

            if id == "":
                self.redirect(
                    "/error?msg=An error ocurred&handler=/search?user="******"":
                self.redirect(
                    "/error?msg=An error ocurred&handler=/search?user=" + nick)
                return
            else:

                comment = Comment(autor=nick, comment=comment, image=id)
                comment.put()
                time.sleep(1)
Exemple #7
0
    def get(self):
        jinja = jinja2.get_jinja2(app=self.app)

        def checkEmail(user_name):
            stored_user = User.query(User.email == user_name)
            toret = True
            if stored_user.count() == 0:
                toret = False

            return toret

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_login_url("/"))
        elif (checkEmail(user.email())):
            self.redirect("/main")
        else:
            user = User(id_user=user.user_id(),
                        nickname=user.nickname(),
                        email=user.email())
            user.put()
            time.sleep(1)

            self.redirect("/main")
    def post(self):
        jinja = jinja2.get_jinja2(app=self.app)

        def checkNickname(nickname, id):
            toret = False
            for p in User.query(User.id_user != id):
                if p.nickname == nickname:
                    toret = True
            return toret

        # return user id
        def id(user_info):
            for user in user_info:
                id = user.id_user
            return id

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            current_user = User.query(User.email == user.email())
            current_user = current_user.get()

            id = current_user.id_user;
            nickname = self.request.get('nick_name')

            # get avatar to load in the view
            image = self.request.get('img')
            if image == "":
                if current_user.avatar != None:
                    image = current_user.avatar
                else:
                    image = None


            if (checkNickname(nickname,id)):
                self.redirect("/error?msg=User nickname already exist&handler=/profile")
                return

            print(image)



            current_user.nickname = self.request.get('nick_name')
            current_user.description = self.request.get('description')
            current_user.avatar = image
            current_user.put()
            time.sleep(1)

            self.redirect("/profile?msg=information_message")
    def post(self):

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:
            autor = self.request.get('autor')
            id = self.request.get('id')

            if id == "":
                self.redirect("/error?msg=Unexpected error&handler=/")
                return

            if autor == "":
                self.redirect("/error?msg=Unexpected error&handler=/")
                return

            #check autor
            user_info = User.query(User.email == user.email())
            user_info = user_info.get()

            if user_info.id_user != autor:
                self.redirect(
                    "/error?msg=You dont have permissions here&handler=/")
                return
            else:
                #prepare deleting
                image_info = Image.query(Image.id_image == id)
                image_info = image_info.get()

                comment = Comment.query(Comment.image == id)

                #delete publication
                user_info.publications = user_info.publications - 1

                # delete image category in User entity
                user_info.categories.remove(image_info.category)
                user_info.put()
                time.sleep(1)

                #delete image comments in Comment entity
                for comments in comment:
                    comments.key.delete()

                #delete image
                image_info.key.delete()
                time.sleep(1)
Exemple #10
0
    def post(self):

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            if self.request.get('img') == "":
                self.redirect("/error?msg=Image is mandatory&handler=/upload")
                return

            if self.request.get('title') == "":
                self.redirect("/error?msg=Title is mandatory&handler=/upload")
                return

            current_user = User.query(User.email == user.email())
            current_user = current_user.get()

            #add category in user
            category = self.request.get('category')
            category = category.lower()

            current_user.publications = current_user.publications + 1
            current_user.categories.append(category)

            current_user.put()
            time.sleep(1)

            #prepare image id
            if "@" in current_user.nickname:
                nickname = user.nickname().split("@")
                nickname = nickname[0]

            else:
                nickname = current_user.nickname
            img = Image(title=self.request.get('title'),
                        comment=self.request.get('comment'),
                        autor=user.user_id(),
                        category=category,
                        image_info=self.request.get('img'),
                        id_image=nickname + str(time.time()).replace(".", ""))

            img.put()
            time.sleep(1)

            self.redirect("/myphotos")
Exemple #11
0
    def post(self, headers):
        print(headers['userID'])
        #需要判断该用户是否有增加新用户的权限
        json_data = request.get_json(force=True)
        if not json_data:
            return {'message': 'No input data provided'}, 400
        print(json_data)
        # data, errors = UserSchema().load(json_data, session=session)
        # if errors:
        #     return errors,422
        user = User.query.filter_by(username=json_data['username']).first()
        if user:
            return {'message': 'user already exists'}, 400

        #变量如果没有会怎样
        user = User(username=json_data['username'],
                    userRealName=json_data['userRealName'],
                    password=json_data['password'],
                    userEmail=json_data['userEmail'],
                    isAdmin=False,
                    userAccountStatus=json_data['userAccountStatus'],
                    userLastLoginTime=None)
        session.add(user)
        session.commit()

        if "userInvolvedProjectsID" in json_data:
            db.session.execute(
                userProject.__table__.insert(),
                [{
                    "userID": user.userID,
                    "projectID": json_data["userInvolvedProjectsID"][i],
                    "userType": "2"
                } for i in range(len(json_data["userInvolvedProjectsID"]))])
            db.session.commit()
        if 'userCanManageProjectsID' in json_data:
            db.session.execute(
                userProject.__table__.insert(),
                [{
                    "userID": user.userID,
                    "projectID": json_data['userCanManageProjectsID'][i],
                    "userType": "1"
                } for i in range(len(json_data["userCanManageProjectsID"]))])
            db.session.commit()
        sendMail("新用户创建成功", user.userEmail, user.userRealName, user.username,
                 user.password)
        return {"statusCode": "1"}
Exemple #12
0
    def get(self):

        # get users nickname to add on list search
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)

            user_list = json.dumps(toret)

            return user_list

        jinja = jinja2.get_jinja2(app=self.app)

        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            current_user = User.query(User.email == user.email())

            labels = {
                "categories": [
                    "culture", "extreme sports", "motor", "social",
                    "videogames", "other"
                ],
                "user_info":
                current_user,
                "usersearch":
                getUsers(),
                "user_logout":
                users.create_logout_url("/"),
            }

        self.response.write(jinja.render_template("upload.html", **labels))
    def get(self):

        # get users nickname to add on list search
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)

            user_list = json.dumps(toret)

            return user_list

        jinja = jinja2.get_jinja2(app=self.app)
        user = users.get_current_user()
        user_id = user.user_id()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:
            msg =self.request.get("msg")

            if msg == "":
                msg = None

            user_info = User.query(User.id_user == user_id)

            labels = {
                "user_info" : user_info,
                "user_logout": users.create_logout_url("/"),
                "usersearch": getUsers(),
                "msg": msg

            }

        self.response.write(jinja.render_template("profile.html", **labels))
        def getNickname(email):
            query = User.query(User.email == email)
            nickname = query.get().nickname

            return nickname
    def get(self):

        # get users nickname
        def getNickname(email):
            query = User.query(User.email == email)
            nickname = query.get().nickname

            return nickname

        # get users nickname to add on list search
        def getUsers():
            us = User.query()
            toret = []
            for u in us:
                toret.append(u.nickname)

            user_list = json.dumps(toret)

            return user_list

        jinja = jinja2.get_jinja2(app=self.app)
        user = users.get_current_user()

        if user == None:
            self.redirect(users.create_logout_url("/"))
        else:

            id_image = self.request.get('id')

            if id_image == "":
                self.redirect("/error?msg=Image id mandatory&handler=/main")
                return
            else:

                image_info = Image.query(Image.id_image == id_image)
                if image_info.count() == 0:
                    self.redirect(
                        "/error?msg=Image does not exist&handler=/main")
                    return
                else:
                    # get autor name
                    image_autor = image_info.get()
                    image_autor = image_autor.autor

                    # get autor attributes
                    user_info = User.query(User.id_user == image_autor)
                    if user_info.count() == 0:
                        self.redirect(
                            "/error?msg=Unexpected error&handler=/main")
                        return
                    else:
                        autor_attributes = user_info.get()
                        autor_name = autor_attributes.nickname
                        autor_email = autor_attributes.email

                        # check current user to reload data
                        current_user = False
                        if autor_name == getNickname(user.email()):
                            current_user = True

                        # check followers
                        if users.get_current_user().email(
                        ) in autor_attributes.followers:
                            follow = True
                        else:
                            follow = False

                        # get image comments
                        comments = Comment.query(
                            Comment.image == id_image).order(Comment.date)

                        labels = {
                            "image_info": image_info,
                            "autor": autor_name,
                            "current_user": current_user,
                            "user": user.email(),
                            "autor_email": autor_email,
                            "comments": comments,
                            "follow": follow,
                            "usersearch": getUsers(),
                            "user_logout": users.create_logout_url("/")
                        }

                    self.response.write(
                        jinja.render_template("image.html", **labels))
 def checkNickname(nickname, id):
     toret = False
     for p in User.query(User.id_user != id):
         if p.nickname == nickname:
             toret = True
     return toret