예제 #1
0
    def create_project(cls,
                       name,
                       description,
                       user_ID,
                       tags=None,
                       user_token='',
                       type='project',
                       **kwargs):
        """
        Create a new project

        :param name: str
        :param description: str
        :param user_ID: ObjectId
        :param type: string (app/module/dataset)
        :param tags: list of string
        :param user_token: string
        :return: a new created project object
        """
        if tags is None:
            tags = []
        project_type = type
        user = UserBusiness.get_by_user_ID(user_ID)
        # message = "{}创建了app{}".format(user.name, name)
        # world_business.system_send(channel=cls.channel, message=message)
        project = cls.business.create_project(name=name,
                                              description=description,
                                              type=type,
                                              tags=tags,
                                              user=user,
                                              user_token=user_token,
                                              **kwargs)
        from server3.service.user_service import UserService
        UserService.action_entity(user_ID=project.user.user_ID,
                                  entity_id=project.id,
                                  action='favor',
                                  entity=project.type)

        from server3.service.world_service import WorldService
        from server3.business.statistics_business import StatisticsBusiness
        # 记录历史记录
        statistics = StatisticsBusiness.action(user_obj=user,
                                               entity_obj=project,
                                               entity_type=type,
                                               action="create")
        # 记录世界频道消息  # 推送消息
        world = WorldService.system_send(
            channel=CHANNEL.request,
            message=f"用户{project.user.user_ID}创建了{project_type}: {project.name}"
        )

        return project
예제 #2
0
파일: user_route.py 프로젝트: StoneXue/mo
def set_action_entity(entity_id):
    """
    在用户和api下都存一份
    用户存api_id
    api存 user_ID
    :return:
    :rtype:
    """
    user_ID = get_jwt_identity()
    data = request.get_json()
    action = data.pop("action")
    entity = data.pop("entity")

    result = UserService.action_entity(
        user_ID=user_ID, entity_id=entity_id, action=action, entity=entity)

    if result:
        return jsonify({
            'message': "success",
            'response': {
                "entity": json_utility.convert_to_json(
                    result.entity.to_mongo()),
                "user": json_utility.convert_to_json(result.user.to_mongo())
            }
        }), 200
    else:
        return jsonify({'response': "failed"}), 400
예제 #3
0
파일: user_route.py 프로젝트: StoneXue/mo
def send_verification_code_to_email(email):
    user_ID = get_jwt_identity()
    try:
        from server3.business.user_business import UserBusiness
        from server3.service.user_service import UserService
        UserService.send_captcha_to_email(user_ID, email)
        return jsonify({
            "response": "success"
        }), 200
    except Error as e:
        print("e.args[0]", e.args[0])
        return jsonify({
            "response": {
                "error": e.args[0]
            }
        }), 400
예제 #4
0
def update_request_answer_votes():
    data = request.get_json()
    user_ID = get_jwt_identity()
    request_answer_id = data["request_answer_id"]
    # votes_user_id = data["votes_user_id"]
    result = UserService.action_entity(user_ID=user_ID,
                                       entity_id=request_answer_id,
                                       action='vote_up',
                                       entity='answer')
    # result = user_service.update_answer_vote(request_answer_id, votes_user_id)
    result = json_utility.convert_to_json(result.entity.to_mongo())
    return jsonify({'response': result}), 200
예제 #5
0
파일: user_route.py 프로젝트: StoneXue/mo
def update_user_account():
    user_ID = get_jwt_identity()
    data = request.get_json()
    token_for_update_info = data['tokenForUpdateInfo']
    phone = data.get('phone', None)
    email = data.get('email', None)
    password = data.get('password', None)
    captcha = data.get('captcha', None)
    payload = jwt.decode(token_for_update_info, UPDATE_USER_INFO_SK,
                         algorithm='HS256')
    if payload['user_ID'] != user_ID or payload['expireTime'] < time.time():
        return jsonify({'response': {'error': 'tokenError'}}), 400
    elif phone:
        # 更改手机
        # 验证手机 验证码
        try:
            if UserBusiness.get_by_phone(phone):
                return jsonify({
                    "response": {'error': "手机号已被注册,请更换手机号"}
                }), 400
            res = user_service.verify_code(code=captcha, phone=phone)
            user = UserBusiness.get_by_user_ID(user_ID)
            user.phone = phone
            user.save()
            return jsonify({'response': {
                "user": json_utility.convert_to_json(user.to_mongo())
            }}), 200
        except Error as e:
            return jsonify({
                "response": {'error': "验证码错误"}
            }), 400
    elif email:
        # 更改邮箱
        # 验证邮箱 验证码
        if UserBusiness.get_by_email(email):
            return jsonify({
                "response": {'error': "邮箱已被注册,请更换邮箱"}
            }), 400
        try:
            user = UserService.update_user_email(user_ID, email, captcha)
            return jsonify({'response': {
                "user": json_utility.convert_to_json(user.to_mongo())
            }}), 200
        except Error as e:
            return jsonify({
                "response": {'error': e.args[0]}
            }), 400
    elif password:
        UserBusiness.update_password(user_ID, password)
    else:
        return jsonify({'response': {'error': 'unkownError'}}), 400
    return jsonify({'response': 'ok'}), 200
예제 #6
0
파일: request_route.py 프로젝트: zjn0224/mo
def update_user_request_star():
    data = request.get_json()
    user_request_id = data["user_request_id"]
    # star_user_id = data["star_user_id"]
    user_ID = get_jwt_identity()
    # result = user_service.update_request_star(user_request_id, star_user_id)
    result = UserService.action_entity(user_ID=user_ID,
                                       entity_id=user_request_id,
                                       action='star',
                                       entity='request')

    result = json_utility.convert_to_json(result.entity.to_mongo())
    return jsonify({'response': result}), 200
예제 #7
0
파일: user_route.py 프로젝트: StoneXue/mo
def get_statistics():
    user_ID = get_jwt_identity()
    page_no = int(request.args.get('page_no', 1))
    page_size = int(request.args.get('page_size', 5))
    action = request.args.get("action")
    entity_type = request.args.get("entity_type")
    statistics = UserService.get_statistics(user_ID, page_no, page_size, action,
                                            entity_type)

    for _object in statistics.objects:
        _object.app_obj_user_ID = _object.app.user.user_ID
    return jsonify({
        'response': {
            "objects": json_utility.objs_to_json_with_args(statistics.objects,
                                                           ["app", "caller"]),
            "page_size": statistics.page_size,
            "page_no": statistics.page_no,
            "count": statistics.count,
        }
    })
예제 #8
0
파일: user_route.py 프로젝트: StoneXue/mo
def update_user_avatar():
    user_ID = get_jwt_identity()
    data = request.get_json()
    base64_str = data.get('dataUrl', None)
    UserService.update_user_avatar(user_ID, base64_str)
    return jsonify({'response': 'ok'}), 200
예제 #9
0
def get_user_info(user_ID):
    result = UserService.get_user_info(user_ID=user_ID)
    print('result')
    print(result)
    return jsonify({'response': result}), 200