Пример #1
0
    def post(self):
        inpt = self.parser.parse_args()
        user = UserModels.find_by_username(inpt["username"])
        if user:
            return {"message": "username has used, try again"}, 400

        try:
            user = UserModels(name=inpt["name"],
                              username=inpt["username"],
                              mode=0,
                              email=inpt["email"],
                              password=inpt["password"],
                              avatar=None)
            user.create_user()
            return {"message": "user has been created."}, 202
        except:
            return {"message": "something wrong in server."}, 500
Пример #2
0
    def post(self):
        inpt = self.parser.parse_args()
        user = UserModels.find_by_username(inpt["username"])

        if user:
            if safe_str_cmp(user.password, inpt["password"]):
                return {
                    "access_token": user.access_token,
                    "refresh_token": user.refresh_token
                }, 202
            return {"message": "invalid credentials"}, 401
        return {"message": "username not found"}, 404
Пример #3
0
 def put(self):
     username = get_jwt_identity()
     inpt = self.parser.parse_args()
     user = UserModels.find_by_username(username)
     data = {
         "name": inpt["name"],
         "email": inpt["email"],
     }
     try:
         user.update_user(**data)
         return {"message": "user has been updated."}, 202
     except:
         return {"message": "something wrong in server."}, 500
Пример #4
0
    def get(self):
        username = get_jwt_identity()
        user = UserModels.find_by_username(username)

        if not user:
            return {"message": "username not found"}, 404

        return {
            "name": user.name,
            "username": user.username,
            "email": user.email,
            "avatar": user.avatar
        }, 202
Пример #5
0
 def delete(self):
     username = get_jwt_identity()
     try: 
         user = UserModels.find_by_username(username)
         if (user.avatar) is None:
             return {"message": "Avatar is none, nothing was deleted."}, 202                
         
         AvatarModels.delete(user)
         return {
             "message": "Avatar has been deleted"
             }, 202
     except Exception:
         traceback.print_exc()
         return {"message": "Something Wrong in server"}, 500
Пример #6
0
    def post(self):
        inpt = self.parser_i_n.parse_args()
        mycol = Tools.get_collection()
        try:
            user = UserModels.find_by_email(inpt["member"])
            if user is None:
                user = UserModels.find_by_username(inpt["member"])
                if user is None:
                    return {"message": "username or email not found"}, 404

            x = mycol.update({"_id": ObjectId(inpt["_id"])}, {
                "$push": {
                    "members": {
                        "username": user.username,
                        "color": inpt["color"],
                    }
                }
            })
            if x["nModified"]:
                return {"message": "Member has been added."}, 202
            else:
                return {"message": "Failed add member"}, 404
        except:
            return {"message": "something wrong in server."}, 500
Пример #7
0
    def put(self):
        username = get_jwt_identity()
        try: 
            file = request.files["image"]
            user = UserModels.find_by_username(username)
            avatar = AvatarModels(user, file)

            if (avatar.extension not in AVATAR_EXTENSIONS):
                return {"message": "file with extension {} disallowed".format(avatar.extension)}, 403
            if (avatar.size_in_bytes > AVATAR_MAX_BYTES):
                return {'message': "photo cannot exceed 5 MB"}, 403

            avatar.upload()
            return {"message": "Avatar has been updated"}, 202
        except Exception:
            traceback.print_exc()
            return {"message": "Something Wrong in server"}, 500
Пример #8
0
 def get(self):
     inpt = self.parser.parse_args()
     try:
         org = Org.find_by_id(inpt["id_org"])
         db = Database()
         result = db.execute(
             "SELECT id, username, start, finish, notes FROM timeline WHERE id_organization=%s AND id_inventory=%s",
             (inpt["id_org"], inpt["id_inv"]))
         data = list()
         for i in result:
             user = UserModels.find_by_username(i[1])
             row = {
                 "id_task": i[0],
                 "username": i[1],
                 "name": user.name,
                 "color": org.get_color_from_username(i[1]),
                 "start": i[2],
                 "finish": i[3],
                 "note": i[4]
             }
             data.append(row)
         return {"tasks": data}, 202
     except:
         return {"message": "Something wrong in server."}, 500
Пример #9
0
 def post(self):
     username = get_jwt_identity()
     user = UserModels.find_by_username(username)
     if user:
         return {"access_token": user.access_token_refresher}, 202
     return {"message": "username not found"}, 404