Exemplo n.º 1
0
 async def get(self, request: Request):
     bots = await dbManger.execute(RobotModel.select())
     bots = [bot.to_dict() for bot in bots]
     return Response(data=bots, status=200, message="ok")
Exemplo n.º 2
0
def info_save():
    args = request.json
    return Response.success(DailyInfoService.save(args))
Exemplo n.º 3
0
def error_handler(exception: Exception):
    if exception:
        log.error(traceback.format_exc())
        return Response.failed(msg=f'{exception}')
Exemplo n.º 4
0
def get_log_content():
    log_path = request.args.get('log_path')
    assert id is not None
    return Response.success(data=BuildService.get_log_content(log_path))
Exemplo n.º 5
0
 def get(self, request, *args, **kwargs):
     response = self.list(request, *args, **kwargs)
     return Response(data=response.data, status=200)
Exemplo n.º 6
0
def change_password():
    """Change the current password

    ---
    put:
      tags:
        - auth
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                user_id:
                  type: integer
                  required: true
                current_password:
                  type: string
                  required: true
                new_password:
                  type: string
                  required: true
                confirm_password:
                  type: string
                  required: true
      responses:
        200:
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: int
                    example: 200
                  success:
                    type: dict
                    example: {message: password changes successfully}
                  error:
                    type: dict
                    example: {message: error occurred}
        400:
          description: bad request
    """
    app.logger.info("change password")

    if not request.is_json:
        response_body = {"message": "Missing JSON in request"}
        return Response(400).wrap(response_body), HTTPStatus.BAD_REQUEST

    _mandatory_fields = [
        "user_id",
        "current_password",
        "new_password",
        "confirm_password",
    ]
    req_data = request.json
    try:
        validation_data_check(_mandatory_fields, req_data)
        user_id, current_password, new_password, confirm_password = fetch_change_pass_req_body(
            req_data=request.json)

        user = User.query.filter_by(id=user_id).first()
        app.logger.info(
            f"password mismatch {pwd_context.verify(current_password, user.password)}"
        )
        if user is None or not pwd_context.verify(current_password,
                                                  user.password):
            response_body = {"message": "unauthorized"}
            return Response(401).wrap(response_body), HTTPStatus.UNAUTHORIZED

        check_new_password_confirm_password(new_password, confirm_password)
        app.logger.info(get_jwt_identity())
        update_data = {
            "password": pwd_context.hash(new_password)
            # "updated_by": get_jwt_identity().get("username"),
            # "updated_on": datetime.datetime.now().isoformat(),
        }
        obj = UserSchema().load(update_data, instance=user, partial=True)
        db.session.add(obj)
        db.session.commit()
        response_body = {"message": "password changed successfully"}
        return Response(200).wrap(response_body), HTTPStatus.OK

    except ValueError as e:
        response_body = {"message": e.args[0]}
        return Response(400).wrap(response_body), HTTPStatus.BAD_REQUEST

    except SQLAlchemyError as e:
        app.logger.error(f"error occured while returned {str(e)}")
        response_body = {"message": f"{str(e)}"}
        return (
            Response(500).wrap(response_body),
            HTTPStatus.INTERNAL_SERVER_ERROR,
        )
Exemplo n.º 7
0
def say(client, message, clients, header):
    user = UsersTool.current_user(client)
    user['message'] = message
    Response(header=header, data=user).response(clients=clients)
Exemplo n.º 8
0
def china_detail():
    date = request.args.get('date')
    return Response.success(SummaryService.china_detail(date))
Exemplo n.º 9
0
def overseas():
    date = request.args.get('date')
    return Response.success(SummaryService.overseas(date))
Exemplo n.º 10
0
def like_article():
    args = request.json
    article_id = args.get('article_id')
    user_name = g.user.name
    assert article_id is not None
    return Response.success(ArticleService.like_article(article_id, user_name))
Exemplo n.º 11
0
def summary_china():
    date = request.args.get('date')
    return Response.success(SummaryService.china_summary(date))
Exemplo n.º 12
0
def article_detail():
    id = request.args.get('id')
    assert id is not None
    return Response.success(ArticleService.article_detail(id, g.user.name))
Exemplo n.º 13
0
def article_list():
    is_published = request.args.get('is_published') == 'true'
    return Response.success(
        ArticleService.article_list(g.user.name, is_published))
Exemplo n.º 14
0
    async def post(self, request: Request):
        form_data = request.form



        return Response(data=None, status=200, message="ok")
Exemplo n.º 15
0
Arquivo: album.py Projeto: LianGee/zed
def delete():
    id = request.args.get('id')
    return Response.success(AlbumService.delete_album(id))
Exemplo n.º 16
0
def history():
    return Response.success(SummaryService.history())
Exemplo n.º 17
0
def login():
    """Authenticate user and return tokens

    ---
    post:
      tags:
        - auth
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                  example: admin
                  required: true
                password:
                  type: string
                  example: admin
                  required: true
      responses:
        200:
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    example: myaccesstoken
                  refresh_token:
                    type: string
                    example: myrefreshtoken
        400:
          description: bad request
      security: []
    """
    if not request.is_json:
        response_body = {"message": "Missing JSON in request"}
        return (
            Response(400).wrap(response_body=response_body),
            HTTPStatus.BAD_REQUEST,
        )

    username = request.json.get("username", None)
    password = request.json.get("password", None)
    if not username or not password:
        response_body = {"message": "Missing username or password"}
        return (
            Response(400).wrap(response_body=response_body),
            HTTPStatus.BAD_REQUEST,
        )

    try:
        user = User.query.filter_by(username=username).first()
        if user is None:
            response_body = {"message": "User not found"}
            return (
                Response(401).wrap(response_body=response_body),
                HTTPStatus.UNAUTHORIZED,
            )

    except Exception as e:
        app.logger.error(str(e))
        db.session.rollback()
        response_body = {"message": f"error occurred{str(e)}"}
        return (
            Response(500).wrap(response_body=response_body),
            HTTPStatus.INTERNAL_SERVER_ERROR,
        )

    if user is None or not pwd_context.verify(password, user.password):
        response_body = {"message": "Unauthorized"}
        return (
            Response(401).wrap(response_body=response_body),
            HTTPStatus.UNAUTHORIZED,
        )

    ret = create_response_body(user)
    response_body = {"data": ret}
    return Response(200).wrap(response_body=response_body), HTTPStatus.OK
Exemplo n.º 18
0
 def leave(self, data):
     room_id, p_id = data.get('room_id', None), data.get('p_id', None)
     room = RoomTool.leave_room(self.client, room_id, p_id)
     Response('room.leave', data={}).response(self.client)
     Response('room.info', data=room).response(clients=self.clients)
Exemplo n.º 19
0
def reset_password():
    """Change the current password

    ---
    put:
      tags:
        - auth
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                  required: true
                password:
                  type: string
                  required: true
      responses:
        200:
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: int
                    example: 200
                  success:
                    type: dict
                    example: {message: password changes successfully}
                  error:
                    type: dict
                    example: {message: error occurred}
        400:
          description: bad request
    """
    if not request.is_json:
        response_body = {"message": "Missing JSON in request"}
        return (
            Response(400).wrap(response_body=response_body),
            HTTPStatus.BAD_REQUEST,
        )
        # return jsonify({"msg": "Missing JSON in request"}), HTTPStatus.BAD_REQUEST

    _mandatory_fields = ["username", "password"]
    req_data = request.json

    try:
        validation_data_check(_mandatory_fields, req_data)
        authorized_user = validation_authority(
            get_jwt_identity().get("username"))
        if authorized_user == "authorized":
            username = req_data["username"]
            password = req_data["password"]
            current_time = datetime.datetime.now().isoformat()
            current_user = get_jwt_identity().get("username")
            user = User.query.filter_by(username=username).first()

            if user is None:
                response_body = {"message": "user is not present"}
                return (
                    Response(401).wrap(response_body),
                    HTTPStatus.UNAUTHORIZED,
                )

            update_data = {
                "password": pwd_context.hash(password),
                # "updated_by": current_user,
                # "updated_on": current_time,
            }
            obj = UserSchema().load(update_data, instance=user, partial=True)
            db.session.add(obj)
            db.session.commit()
            response_body = {"message": "password reset successfully"}
            return Response(200).wrap(response_body), HTTPStatus.OK
        elif authorized_user == "unauthorized":
            response_body = {"message": "unauthorized"}
            return (
                Response(401).wrap(response_body=response_body),
                HTTPStatus.UNAUTHORIZED,
            )
        else:
            response_body = {"message": authorized_user}
            return (
                Response(500).wrap(response_body=response_body),
                HTTPStatus.INTERNAL_SERVER_ERROR,
            )
    except ValueError as e:
        response_body = {"message": e.args[0]}
        return Response(400).wrap(response_body), HTTPStatus.BAD_REQUEST

    except SQLAlchemyError as e:
        app.logger.error(f"error occured while returned {str(e)}")
        response_body = {"message": f"{str(e)}"}
        return (
            Response(500).wrap(response_body),
            HTTPStatus.INTERNAL_SERVER_ERROR,
        )
Exemplo n.º 20
0
    def login(self, data):

        data = UsersTool.login(client=self.client, data=data)
        Response('user.login', data=data).response(self.client)
Exemplo n.º 21
0
def get_logs():
    return Response.success(data=BuildService.get_logs(g.user.name))
Exemplo n.º 22
0
 def create_room(self, data=None):
     user_id = redis_obj.db.get(get_w_key(self.client))
     room = RoomTool.init_room(user_id, self.client, BattleType.freestyle,
                               GameType.offline)
     Response("room.create", room).response(self.client)
Exemplo n.º 23
0
def recent_build():
    return Response.success(data=BuildService.recent_build(g.user.name))
Exemplo n.º 24
0
Arquivo: album.py Projeto: LianGee/zed
def get_album_list():
    user_name = g.user.name
    is_public = request.args.get('is_public') == 'true'
    return Response.success(AlbumService.album_list(user_name, is_public))
Exemplo n.º 25
0
def has_done():
    return Response.success(DailyInfoService.has_done(g.user.name))
Exemplo n.º 26
0
Arquivo: album.py Projeto: LianGee/zed
def get_img_list():
    album_id = request.args.get('album_id')
    user_name = g.user.name
    return Response.success(AlbumService.img_list(user_name, album_id))
Exemplo n.º 27
0
def daily_info_statistic():
    start = request.args.get('start')
    end = request.args.get('end')
    return Response.success(DailyInfoService.query(start, end))
Exemplo n.º 28
0
Arquivo: album.py Projeto: LianGee/zed
def public_album():
    id = request.json.get('id')
    assert id is not None
    return Response.success(AlbumService.public_album(id))
Exemplo n.º 29
0
def save():
    id = request.json.get('id')
    name = request.json.get('name')
    user_name = g.user.name
    return Response.success(WorkspaceService.save(user_name, id, name))
Exemplo n.º 30
0
Arquivo: tag.py Projeto: LianGee/zed
def delete_tag():
    id = request.args.get('id')
    assert id is not None
    return Response.success(TagService.delete(id))