Пример #1
0
    def post(self, gameKey: int) -> Response:
        payload: dict = request.json
        game: GameModel = GameModel.objects(game_key=gameKey).first()
        if not game:
            return Response('', 204)

        user: UserModel = UserModel.objects(user_id=payload['id'],
                                            game=game).first()
        if user:
            if check_password_hash(user.password, payload['password']):
                return jsonify({
                    'accessToken':
                    create_access_token(payload['id'],
                                        expires_delta=timedelta(days=10))
                })

            else:
                return Response('', 205)

        default_team: TeamModel = TeamModel.objects(game=game,
                                                    team_id=0).first()
        UserModel(game, payload['id'], payload['email'],
                  generate_password_hash(payload['password']),
                  default_team).save()
        return jsonify({
            'accessToken':
            create_access_token(payload['id'],
                                expires_delta=timedelta(days=10))
        })
Пример #2
0
def a():
    teams = TeamModel.objects(teamName__ne='empty')
    for booth in BoothModel.objects():
        t = choice(teams)
        booth.own_team = t
        booth.save()
    return '', 200
Пример #3
0
 def _create_booth(self):
     default_team = TeamModel.objects(team_id=0).first()
     for i in range(5):
         BoothModel(
             game=self.test_game,
             booth_name=f'booth{i}',
             own_team=default_team,
         ).save()
Пример #4
0
    def get(self) -> Response:
        team_objects: List[TeamModel] = TeamModel.objects(game=g.game)
        result = {'teamCount': len(team_objects)}

        for team in team_objects:
            result[str(team.team_id)] = {
                'member': [user.user_id for user in UserModel.objects(team=team)],
                'teamColor': team.team_color
            }

        return jsonify(result)
Пример #5
0
 def get(self):
     user = AdminUserModel.objects(userId=get_jwt_identity()).first()
     return uni_json([
         {
             "bootName":
             booth.boothName,
             "ownTeam":
             TeamModel.objects(game=user.game,
                               teamId=booth.ownTeam.teamId).first().teamId
             # "ownTeam": booth.ownTeam.id
         } for booth in BoothModel.objects(game=user['game'])
     ])
Пример #6
0
    def post(self) -> Response:
        if not g.user:
            abort(403)

        if g.user.team.team_id != 0:
            return Response('', 204)

        team: TeamModel = TeamModel.objects(team_id=int(request.args.get('team'))).first()
        if (not team) or len(UserModel.objects(team=team)) > 5:
            return Response('', 205)

        g.user.team = team
        g.user.save()

        return Response('', 201)
Пример #7
0
    def post(self):
        edits_ = request.json['edits']  # boothName
        user = AdminUserModel.objects(userId=get_jwt_identity()).first()
        game = user['game'].id

        if not user:
            abort(401)
        else:
            for array in edits_:
                BoothModel(game=game,
                           boothName=array['boothName'],
                           ownTeam=TeamModel.objects(teamId=0).first()).save()

            return {
                "status": "Successfully inserted problem information."
            }, 201
Пример #8
0
    def get(self):
        ret = []
        user = AdminUserModel.objects(userId=get_jwt_identity()).first()

        total_ = len(BoothModel.objects(
            game=user['game']))  # user의 현재 게임 내에 있는 총 부스의 개수
        for team in TeamModel.objects(game=user['game']):
            # temp 는 해당 team 이 점령한 부스의 개수를 지칭
            temp = len(BoothModel.objects(ownTeam=team))
            ret.append({
                "teamId": team.teamColor,
                "ownCount": temp,
                "percent": temp / total_ * 100
            })

        return ret, 201  # for 문이 끝나고 ret 반환
Пример #9
0
    def get(self) -> Response:
        if not g.user:
            return abort(403)

        default_team: TeamModel = TeamModel.objects(team_id=0,
                                                    game=g.game).first()
        map_: dict = {
            'map': {},
            'myTeam': g.user.team.team_id,
            'myTeamColor': g.user.team.team_color
        }
        booths: List[BoothModel] = BoothModel.objects(game=g.game)

        for booth in booths:
            if booth.own_team == default_team:
                map_['map'][booth.booth_name] = -1
            elif booth.own_team == g.user.team:
                map_['map'][booth.booth_name] = 1
            else:
                map_['map'][booth.booth_name] = 0

        return jsonify(map_)
Пример #10
0
 def _create_team(self, team_count=4):
     for i in range(team_count + 1):
         TeamModel(game=self.test_game,
                   team_id=i,
                   team_color=hex(i * 333333)).save()