Example #1
0
def login():
    reason = 'Unknown error.'
    redir = request.args.get('next')

    if redir is None:
        redir = ''
    else:
        redir = '?next={}'.format(redir)

    if not event_start(EVENT_DATA):
        if ENV_DEV:
            pass
        else:
            return redirect('/')

    if request.method == "POST":
        try:
            uname = request.form.get('uname').strip()
            pword = request.form.get('pword').strip()

            if validate_user(get_db().cursor(), uname, pword):
                auth_user = User(uname)
                login_user(auth_user)

                if request.args.get('next') is None:
                    if current_user.is_authenticated:
                        return redirect(
                            routing(
                                EVENT_DATA,
                                get_user_level(get_db().cursor(),
                                               current_user.id), 'path'))

                if is_safe_url(request, request.args.get('next')):
                    return redirect(request.args.get('next'))
                else:
                    abort(400)
            else:
                reason = 'Incorrect username or password.'
                raise GameException
        except GameException:
            return render_template(
                'login.html',
                event="NETWORK TREASURE HUNT",
                social="https://www.instagram.com/acespvg/?hl=en",
                host="ACESPVG",
                error=True,
                reason=reason,
                year=YEAR,
                next=redir)
    else:
        return render_template(
            'login.html',
            event="NETWORK TREASURE HUNT",
            social="https://www.instagram.com/acespvg/?hl=en",
            host="ACESPVG",
            error=False,
            reason='',
            next=redir,
            year=YEAR)
Example #2
0
def tracker():
    '''
    Method to track leaderboard scores.
    '''
    if not event_start(EVENT_DATA):
        if ENV_DEV:
            pass
        else:
            return jsonify({'users': []}), 403

    data = {'users': []}
    players = trackr(get_db().cursor(), APP_CONFIG['trackr'])
    for player in players:
        data['users'].append({'name': player[0], 'level': player[1]})

    return jsonify(data)
Example #3
0
def level(path):
    '''
    Display, the question, validate answers, hints and increment user level.
    '''
    if is_banned(get_db().cursor(), current_user.id):
        print 'here'
        return redirect('/logout')

    if not event_start(EVENT_DATA):
        if ENV_DEV:
            pass
        else:
            return redirect('/')

    level_index = routing(EVENT_DATA, path, 'index')
    user_index = get_user_level(get_db().cursor(), current_user.id)

    if level_index > user_index:
        return redirect(routing(EVENT_DATA, user_index, 'path'))

    data = get_level_data(EVENT_DATA, path)
    if data is None:
        return redirect('/')

    if request.method == 'POST':
        answer = request.form.get('answer')
        correct, hint, text = validate_answer(data, answer)
        if correct:
            if user_index == level_index:
                increment(get_db(), current_user.id, (level_index + 1))

            if (level_index + 1) > len(EVENT_DATA['levels']):
                return redirect('/congratulations')

            return redirect(routing(EVENT_DATA, (level_index + 1), 'path'))

        elif hint:
            return render_template('level.html',
                                   year=YEAR,
                                   event=EVENT_DATA['name'],
                                   host=EVENT_DATA['host'],
                                   faq=EVENT_DATA['faq'],
                                   social=EVENT_DATA['social'],
                                   discuss=EVENT_DATA['discuss'],
                                   user=current_user.id,
                                   media=data['media'],
                                   hint=hint,
                                   hint_text=text,
                                   text=data['text'],
                                   level=level_index,
                                   title=data['title'],
                                   source=data['source'])

        return render_template('level.html',
                               year=YEAR,
                               event=EVENT_DATA['name'],
                               host=EVENT_DATA['host'],
                               faq=EVENT_DATA['faq'],
                               social=EVENT_DATA['social'],
                               discuss=EVENT_DATA['discuss'],
                               user=current_user.id,
                               media=data['media'],
                               hint=False,
                               hint_text='',
                               text=data['text'],
                               level=level_index,
                               title=data['title'],
                               source=data['source'])

    else:
        return render_template('level.html',
                               year=YEAR,
                               event=EVENT_DATA['name'],
                               host=EVENT_DATA['host'],
                               faq=EVENT_DATA['faq'],
                               social=EVENT_DATA['social'],
                               discuss=EVENT_DATA['discuss'],
                               user=current_user.id,
                               media=data['media'],
                               hint=False,
                               hint_text='',
                               text=data['text'],
                               level=level_index,
                               title=data['title'],
                               source=data['source'])
Example #4
0
def login():
    reason = 'Unknown error.'
    redir = request.args.get('next')

    if redir is None:
        redir = ''
    else:
        redir = '?next={}'.format(redir)

    if not event_start(EVENT_DATA):
        if ENV_DEV:
            pass
        else:
            return redirect('/')

    if request.method == "POST":
        try:
            uname = request.form.get('uname').strip()
            pword = request.form.get('pword').strip()

            if validate_user(get_db().cursor(), uname, pword):
                auth_user = User(uname)
                login_user(auth_user)

                if request.args.get('next') is None:
                    if current_user.is_authenticated:
                        return redirect(
                            routing(
                                EVENT_DATA,
                                get_user_level(get_db().cursor(),
                                               current_user.id), 'path'))

                if is_safe_url(request, request.args.get('next')):
                    return redirect(request.args.get('next'))
                else:
                    abort(400)
            else:
                reason = 'Incorrect username or password.'
                raise GameException
        except GameException:
            return render_template('login.html',
                                   event=EVENT_DATA['name'],
                                   host=EVENT_DATA['host'],
                                   faq=EVENT_DATA['faq'],
                                   discuss=EVENT_DATA['discuss'],
                                   social=EVENT_DATA['social'],
                                   error=True,
                                   reason=reason,
                                   year=YEAR,
                                   next=redir)
    else:
        return render_template('login.html',
                               event=EVENT_DATA['name'],
                               host=EVENT_DATA['host'],
                               faq=EVENT_DATA['faq'],
                               social=EVENT_DATA['social'],
                               discuss=EVENT_DATA['discuss'],
                               error=False,
                               reason='',
                               next=redir,
                               year=YEAR)