Beispiel #1
0
def check_user():
    name = request.form.get('name', '')
    password = request.form.get('password', '')

    user = User.get_by_name(name) or User.get_by_email(name)
    if not (user and user.check_password(password)):
        return jsonify({'message': 'no'}), 403
    return jsonify({'message': 'yes'}), 200
Beispiel #2
0
def login():
    if request.method == 'GET':
        if not g.user:
            return render_template('/login.html')
        return redirect(url_for('ui.index'))

    name = request.form['name']
    password = request.form['password']
    if not (name and password):
        flash(u'你有些忘记填了', 'error')
        return render_template('/login.html')

    u = User.get_by_name(name) or User.get_by_email(name)
    if not (u and u.check_password(password)):
        flash(u'密码错了, 或者你就不存在啊', 'error')
        return render_template('/login.html')

    login_user(u)

    redir = request.values.get('redirect', url_for('ui.index'))
    return redirect(redir)
Beispiel #3
0
def get_token():
    name = request.form['name']
    user = User.get_by_name(name)
    if user:
        return user.token, 200
    return '', 400