Esempio n. 1
0
    def verify_user(steam_id):
        """Verify or un-verify an user

        Args:
            steam_id: user targeted.
        Returns:
            The user detail page.
        """
        steam_id = int(steam_id)
        target_user = db.session().query(User).filter_by(id=steam_id).first()
        if target_user is not None and current_user.has_permission(
                constants.PERMISSION_ADMIN):
            target_user.verified = not target_user.verified
            db.session().commit()
        return redirect(url_for('user_blueprint.user', steam_id=steam_id))
Esempio n. 2
0
    def force_out(steam_id):
        """Admin tool to force a player out of a specific match.

        Args:
            steam_id: user targeted.
        Returns:
            The user detail page.
        """
        steam_id = int(steam_id)
        target_user = db.session().query(User).filter_by(id=steam_id).first()
        if target_user is not None and current_user.has_permission(
                constants.PERMISSION_ADMIN):
            target_user.current_match = None
            db.session().commit()
        return redirect(url_for('user_blueprint.user', steam_id=steam_id))
Esempio n. 3
0
    def user(steam_id):
        """Access to the page with details of a user.

        Args:
            steam_id: user ID to return the detailed page of.
        Returns:
            Page with the detailed information of the user.
        """
        user_requested = db.session().query(User).filter_by(
            id=steam_id).first()
        if user_requested is None:
            abort(404)
        if current_user.is_authenticated and current_user.id == user_requested.id and \
                (current_user.profile_scan_info is None or
                             datetime.utcnow() - current_user.profile_scan_info.last_scan_request > timedelta(
                         minutes=5)):
            scan_possible = True
        else:
            scan_possible = False
        user_banned = user_requested.ban_date is not None and user_requested.ban_date > datetime.utcnow(
        )
        return render_template('user_details.html',
                               user=user_requested,
                               scan_possible=scan_possible,
                               user_banned=user_banned)
Esempio n. 4
0
    def user_permission(steam_id, permission, give):
        """Modify user permission of a specific user.

        Args:
            steam_id: user ID of the `User` to modify.
            permission: `str` permission to change.
            give: `Boolean` to specify a permission addition or removal.
        """
        give = give == 'True'
        target_user = db.session().query(User).filter_by(id=steam_id).first()
        if target_user is None:
            return redirect(url_for('user_blueprint.user', steam_id=steam_id))

        if current_user.has_permission(constants.PERMISSION_ADMIN):
            target_user.give_permission(permission, give)
            db.session().commit()
        return redirect(url_for('user_blueprint.user', steam_id=steam_id))
Esempio n. 5
0
    def nickname_delete(steam_id):
        """Tool for an admin to delete a user nickname. Force to choose a new one.

        Args:
            steam_id: user targeted.
        Returns:
            The user detail page.
        """
        steam_id = int(steam_id)
        target_user = db.session().query(User).filter_by(id=steam_id).first()
        if target_user is not None and current_user.has_permission(
                constants.PERMISSION_ADMIN):
            target_user.nickname = None
            target_user.verified = False
            target_user.section = None
            db.session().commit()
        return redirect(url_for('user_blueprint.user', steam_id=steam_id))
Esempio n. 6
0
    def match(match_id):
        """Page to give details of a match.

        Args:
            match_id: match ID to return the detailed page of.
        Returns:
            The page generated with the match details.
        """
        match = db.session().query(Match).filter(Match.id == match_id).first()
        return render_template('ladder_match.html', match=match)
Esempio n. 7
0
    def mix_edit():
        """Access the mix edit page or post a change.

        Methods;
            GET: access the mix edit page.
                Returns:
                    The page to edit the mix of the current user.
            POST: update the mix details.
                Args:
                    enabled: `Boolean` if the user wants the ad visible or not.
                    title: `str` title of the ad.
                    goal: `str` aim of the ad.
                    level: `str` level of the ad.
                    description: `str` Markdown description of the ad.
                Returns:
                    Redirect to the page with the mix details of the current user..
        """
        mix_requested = current_user.user_mix_detail

        if request.method == 'GET':
            return render_template('mix_edit.html', mix=mix_requested)
        elif request.method == 'POST':

            if mix_requested is None:
                mix_requested = UserMixDetail()
                current_user.user_mix_detail = mix_requested
            mix_requested.title = request.form.get('title') or ''
            mix_requested.goal = request.form.get('goal') or ''
            mix_requested.level = request.form.get('level') or ''
            mix_requested.description = request.form.get('description') or ''
            mix_requested.enabled = request.form.get('add') is not None

            mix_requested.refresh_date = datetime.utcnow()

            db.session().commit()

            if mix_requested.enabled:
                return redirect(
                    url_for('mix_blueprint.mix', mix_id=current_user.id))
            else:
                return render_template('mix_edit.html', mix=mix_requested)
Esempio n. 8
0
    def api_users():
        """API endpoint for the datatable to request users.

        Parameters:
            draw: request identifier, returned in the answer.
            length: entries to return.
            start: offset for the entry.
        Returns:
            `JSON` containing user entries sorted with the following design
             {
                "draw": <draw parameter>
                "recordsTotal": <total entries>
                "recordsFiltered": <total entries>
                "data": [ entry.data ]
            }
        """
        draw = request.args.get('draw', '1')
        search = request.args.get('search[value]', '')
        length = int(request.args.get('length', '20'))
        start = int(request.args.get('start', '0'))

        query = db.session().query(User) \
            .order_by(User.nickname) \
            .filter(User.nickname.isnot(None))

        if search != '':
            query = query.filter(User.nickname.ilike('%' + search + '%'))

        count = query.count()

        query = query.offset(start) \
            .limit(length)

        data = []
        for user in query.all():
            permissions = {
                'verified':
                user.verified,
                constants.PERMISSION_ADMIN:
                user.has_permission(constants.PERMISSION_ADMIN)
            }
            data.append([
                user.avatar, permissions, user.nickname,
                str(user.id), user.solo_mmr, user.section
            ])
        results = {
            "draw": draw,
            "recordsTotal": count,
            "recordsFiltered": count,
            "data": data
        }
        return jsonify(results)
Esempio n. 9
0
    def select_nickname():
        if current_user.nickname is not None:
            return jsonify({
                'status': 'ko',
                'message': "L'utilisateur a déjà un nickname."
            }), 200

        data = request.get_json(silent=False, force=True)
        posted_nickname = data['nickname']

        error = validate_nickname(posted_nickname)
        if error is not None:
            return jsonify({'status': 'ko', 'message': error}), 200

        if db.session().query(User).filter_by(
                nickname=posted_nickname).first() is not None:
            return jsonify({
                'status': 'ko',
                'message': 'Le pseudo est déjà utilisé.'
            }), 200
        current_user.nickname = posted_nickname
        db.session().commit()

        return jsonify({'status': 'ok'}), 200
Esempio n. 10
0
    def api_scoreboard(ladder):
        """API endpoint for the datatable to request scoreboards.

        Args:
            ladder: ladder name (cf. constants).
        Parameters:
            draw: request identifier, returned in the answer.
            length: entries to return.
            start: offset for the entry.
        Returns:
            `JSON` containing scoreboard entries sorted with the following design
             {
                "draw": <draw parameter>
                "recordsTotal": <total entries>
                "recordsFiltered": <total entries>
                "data": [ entry.data ]
            }
        """
        draw = request.args.get('draw', '1')
        length = int(request.args.get('length', '20'))
        start = int(request.args.get('start', '0'))
        if ladder not in [constants.LADDER_HIGH, constants.LADDER_LOW, constants.LADDER_MEDIUM]:
            ladder = constants.LADDER_HIGH

        query = db.session().query(User, Scoreboard) \
            .filter(User.id == Scoreboard.user_id) \
            .filter(Scoreboard.ladder_name == ladder) \
            .filter(User.nickname.isnot(None)) \
            .order_by(Scoreboard.points.desc(), User.solo_mmr.desc())

        count = query.count()

        query = query.offset(start) \
            .limit(length)

        data = []
        place = start
        for user, scoreboard in query.all():
            place += 1
            data.append([user.avatar, place, user.nickname, str(user.id), scoreboard.points, user.solo_mmr,
                         scoreboard.matches, scoreboard.win, scoreboard.loss, scoreboard.dodge, scoreboard.leave])
        results = {
            "draw": draw,
            "recordsTotal": count,
            "recordsFiltered": count,
            "data": data
        }
        return jsonify(results)
Esempio n. 11
0
    def api_mixs():
        """API endpoint for the datatable to request mixs.

        Parameters:
            draw: request identifier, returned in the answer.
            length: entries to return.
            start: offset for the entry.
        Returns:
            `JSON` containing mix entries sorted with the following design
             {
                "draw": <draw parameter>
                "recordsTotal": <total entries>
                "recordsFiltered": <total entries>
                "data": [ entry.data ]
            }
        """
        draw = request.args.get('draw', '1')
        length = int(request.args.get('length', '20'))
        start = int(request.args.get('start', '0'))

        date_limit = datetime.utcnow() - timedelta(days=7)

        query = db.session().query(User, UserMixDetail)\
            .filter(UserMixDetail.id == User.id)\
            .filter(UserMixDetail.refresh_date > date_limit.isoformat())\
            .filter(UserMixDetail.enabled)\
            .order_by(UserMixDetail.refresh_date.desc())\

        count = query.count()

        query = query.offset(start)\
            .limit(length)

        data = []
        for user, mix_details in query.all():
            data.append([
                str(user.id), user.avatar, user.nickname, mix_details.title,
                mix_details.goal, mix_details.level
            ])
        results = {
            "draw": draw,
            "recordsTotal": count,
            "recordsFiltered": count,
            "data": data
        }
        return jsonify(results)
Esempio n. 12
0
    def queue_in_out():
        data = request.get_json(silent=False, force=True)
        in_out = data['in'] == '1'
        modes = data['modes']

        if current_user.current_match is None and current_user.section is not None:
            remove_queue = QueuedPlayer.query.filter_by(id=current_user.id).first()

            if not in_out and remove_queue is not None:
                db.session().delete(remove_queue)
                db.session().commit()
            elif in_out and remove_queue is None:
                new_queue = QueuedPlayer(current_user.id, current_user.section, modes)
                db.session().add(new_queue)
                db.session().commit()

                query = QueuedPlayer.query.filter_by(queue_name=current_user.section) \
                    .order_by(QueuedPlayer.added).limit(10)
                if query.count() >= 10:
                    # Create a game
                    players = []
                    votes = []
                    for player in query.all():
                        players.append(player.id)
                        votes.append(player.mode_vote)
                        db.session().delete(player)
                    new_match = Match(players, current_user.section, votes)
                    db.session().add(new_match)
                    db.session().commit()
                    for player in new_match.players:
                        player.player.current_match = new_match.id
                    db.session.commit()

                    job_queue.produce(JobCreateGame(match_id=new_match.id))

        return queue_details()