コード例 #1
0
ファイル: auth.py プロジェクト: subrays/subrays.me
def login():
    if 'username' in session:
        flash('Already logged in.')
        return redirect(url_for('home'))

    if request.method == "GET":
        return render_template('login.html')

    username = request.form['username']
    password = request.form['password']

    if len(username)<4 or len(password)<6:
        flash('Invalid format')
        return render_template('login.html')

    try:
        user = User.get(username, password)
    except Exception as e:
        flash(type(e).__name__)
        return render_template('login.html')

    if user:
        resp = make_response(redirect(url_for('home')))
        session['username'] = user.username
        return resp

    return render_template('login.html')
コード例 #2
0
ファイル: auth.py プロジェクト: subrays/subrays.me
def signup():
    if request.method == 'GET':
        return render_template('signup.html')

    username = request.form['username']
    password = request.form['password']

    if len(username)<4 or len(password)<6:
        flash('Invalid format')
        return render_template('signup.html')

    try:
        user = User.get(username, password)
    except UserNotExist:
        user = User.new(username, password)
        resp = make_response(redirect(url_for('home')))
        session['username'] = user.username
        return resp
    except:
        flash('Username Exist.')

    return render_template('signup.html')