コード例 #1
0
ファイル: app.py プロジェクト: tmoi29/tenaciousTurtles
def login():
    # type: () -> Response
    form = request.form
    username = form['username']
    if not database.authenticate(username, form['password']):
        return reroute_to(login_page)
    session[UID_KEY] = username
    return reroute_to(profile)
コード例 #2
0
ファイル: app.py プロジェクト: tmoi29/tenaciousTurtles
def create_account():
    # type: () -> Response
    form = request.form
    username = form['username']
    if not database.add_account(username, form['password1'], form['password2'],
                                False):
        return reroute_to(create_account_page)
    session[UID_KEY] = username
    return reroute_to(profile)
コード例 #3
0
def set_options():
    # type: () -> Response
    """Set the user's question options from the form submitted in choose_options()."""
    try:
        get_user().set_options(request.form)
    except InvalidQuestionOptionException as e:
        flash(e.message)
        return reroute_to(choose_options)
    return reroute_to(answer_question)
コード例 #4
0
def auth_or_signup(db_user_supplier):
    # type: (Callable[[unicode, unicode], User]) -> Response
    """
    Auth or signup with the username and password in the form
    and given the DB function that gets the user from the DB,
    possibly inserting the new user.
    """
    if is_logged_in():
        reroute_to(answer_question)
    username, password = get_user_info()
    with db:
        try:
            user = db_user_supplier(username, password)
        except db.exception as e:
            e = e  # type: db.exception
            flash(e.message)
            print(e, file=stderr)
            return reroute_to(login)
    set_user(user)
    return reroute_to(answer_question)
コード例 #5
0
def check_answer():
    # type: () -> Response
    """Check the answer to the question the user has submitted."""
    user = get_user()
    answer = request.form['answer']
    with db:
        question = db.get_question(user.last_question_id)
        if answer != question.answer:
            flash(u'{} is the wrong answer'.format(answer))
        else:
            db.complete_question(user, question)
            print(u'{}\'s points: {}'.format(user.username, user.points))
    return reroute_to(answer_question)
コード例 #6
0
ファイル: app.py プロジェクト: kkysen/MongoRestaurants
def query_movies():
    # type: () -> Response
    """
    Parse an $and query in the form of a dict[query method name, query args]
    in request.form['query'] and return the result of the mongo query.
    
    :return: jsonified Cursor from movies collection in Mongo DB
    """
    query = json.loads(request.form['query'])  # type: Dict[str, Any]
    print(query)
    for query_name, query_args in query.viewitems():
        query_func = getattr(movies, query_name, None)
        if query_func is None \
                or not hasattr(query_func, 'is_query')\
                or not isinstance(query_args, list)\
                or len(query_args) != len(inspect.getargspec(query_func).args) - 1:
            return reroute_to(bad_request)
    for query_name, query_args in query.viewitems():
        getattr(movies, query_name)(*query_args)
    return json_util.dumps(movies.fetch())
コード例 #7
0
ファイル: app.py プロジェクト: tmoi29/tenaciousTurtles
def logout():
    # type: () -> Response
    del session[UID_KEY]
    flash('Yay! Successfully logged out!')
    return reroute_to(index)
コード例 #8
0
ファイル: app.py プロジェクト: tmoi29/tenaciousTurtles
def login_page():
    # type: () -> Response
    if is_logged_in():
        return reroute_to(index)
    return render_template('login.html')
コード例 #9
0
def login():
    # type: () -> Response
    """Render the login page or reroute to answer_questions if already logged in."""
    if is_logged_in():
        return reroute_to(answer_question)
    return render_template('login.html')
コード例 #10
0
def logout():
    # type: () -> Response
    """Log the user out."""
    remove_user()
    return reroute_to(welcome)
コード例 #11
0
def register():
    # type: () -> Response
    """Render the page for registering a new account."""
    if is_logged_in():
        return reroute_to(answer_question)
    return render_template('signup.html')