Exemple #1
0
def view_frontend(path=None):
    return render_template('index.html',
        page_attributes=u' '.join(page_attributes() + ['issue-tracker-app']),
        user=current_user.to_dict() if is_logged_in() else None,
        current_user=jsonify(current_user.to_dict() if is_logged_in() else None),
        anonymous_gravatar=gravatar(''),
        issues=jsonify([create_issue_read_dict(issue, last_read) for (issue,last_read) in uncompleted_issues()]),
        labels=jsonify([label.to_dict() for label in labels()]))
Exemple #2
0
def view_frontend(path=None):
    return render_template(
        'index.html',
        page_attributes=u' '.join(page_attributes() + ['issue-tracker-app']),
        user=current_user.to_dict() if is_logged_in() else None,
        current_user=jsonify(
            current_user.to_dict() if is_logged_in() else None),
        anonymous_gravatar=gravatar(''),
        issues=jsonify([issue.to_dict() for issue in uncompleted_issues()]),
        labels=jsonify([label.to_dict() for label in labels()]))
Exemple #3
0
def page_attributes():
    attributes = []

    if is_logged_in():
        attributes.append(u'user-logged-in')
    else:
        attributes.append(u'user-not-logged-in')

    if is_admin():
        attributes.append(u'user-is-admin')
    else:
        attributes.append(u'user-is-not-admin')

    return attributes
Exemple #4
0
def page_attributes():
    attributes = []

    if is_logged_in():
        attributes.append(u'user-logged-in')
    else:
        attributes.append(u'user-not-logged-in')

    if is_admin():
        attributes.append(u'user-is-admin')
    else:
        attributes.append(u'user-is-not-admin')

    return attributes
Exemple #5
0
def make_admin(user_id):
    form = ConfirmPasswordForm()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.password.data):
            user.admin = not user.admin
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else: 
            form.password.errors.append('Wrong password')
    return render_template('confirm.html',
        user=current_user.to_dict() if is_logged_in() else None, 
        form=form,
        title='Change Admin Status',
        target=url_for('make_admin', user_id=user_id))
Exemple #6
0
def make_admin(user_id):
    form = ConfirmPasswordForm()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.password.data):
            user.admin = not user.admin
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else:
            form.password.errors.append('Wrong password')
    return render_template(
        'confirm.html',
        user=current_user.to_dict() if is_logged_in() else None,
        form=form,
        title='Change Admin Status',
        target=url_for('make_admin', user_id=user_id))
Exemple #7
0
def change_password(user_id=None):
    form = ChangePasswordForm()
    if user_id is not None and not is_admin():
        return 'You are not authorised', 403
    if user_id is None:
        user_id = current_user.get_id()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.current_password.data):
            user.set_password(form.new_password.data)
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else: 
            form.current_password.errors.append('Wrong password')
    return render_template('user_change_password.html',
        form=form,
        user=current_user.to_dict() if is_logged_in() else None,
        user_id=user_id)
Exemple #8
0
def change_password(user_id=None):
    form = ChangePasswordForm()
    if user_id is not None and not is_admin():
        return 'You are not authorised', 403
    if user_id is None:
        user_id = current_user.get_id()
    user = User.query.filter_by(id=user_id).first_or_404()
    if form.validate_on_submit():
        if current_user.check_password(form.current_password.data):
            user.set_password(form.new_password.data)
            db.session.commit()
            return redirect(url_for('view_frontend'))
        else:
            form.current_password.errors.append('Wrong password')
    return render_template(
        'user_change_password.html',
        form=form,
        user=current_user.to_dict() if is_logged_in() else None,
        user_id=user_id)
    def handle_submission():
        if session.is_logged_in():
            json_request = request.get_json()

            if json_request is None:
                return jsonify(standard_responses.REQUEST_ISNT_JSON)

            try:
                sess = db.make_session()
                chart = db.get_chart_by_hash(sess, json_request['chart_sha256'])
                client = db.get_client_by_name_and_key(sess,
                                                            json_request["client"],
                                                            json_request["key_name"])

                if not chart:
                    chart = db.add_chart_from_score(sess, json_request)

                if client:
                    if score_is_valid(json_request):
                        user = db.get_user_by_username(sess, session.get_username())
                        db.add_score(sess, user, chart, client, json_request)
                        sess.commit()
                    else:
                        return jsonify(standard_responses.SCORE_REJECTED)
                else:
                    return jsonify(standard_responses.INVALID_CLIENT_KEY)

            except Exception as e:
                sess.rollback()
                db.app.logger.error("Error adding score: {}".format(e))
                traceback.print_tb(e.__traceback__)
                return jsonify(standard_responses.MALFORMED_REQUEST)
        else:
            return jsonify(standard_responses.UNAUTHORIZED)

        return jsonify(standard_responses.OK)
Exemple #10
0
def list_users():
    users = User.query.all()
    return render_template(
        'users.html',
        user=current_user.to_dict() if is_logged_in() else None,
        users=users)
Exemple #11
0
def list_users():
    users = User.query.all()
    return render_template('users.html',
        user=current_user.to_dict() if is_logged_in() else None, 
        users=users)