コード例 #1
0
ファイル: app.py プロジェクト: carc1n0gen/tutorial-apps
def signin():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        user = get_user(username)
        # Check that a user matching the username exists, and that the password matches
        if user is not None and checkpw(password.encode('utf-8'),
                                        user['password']):
            session['user_id'] = user['id']
            return redirect(url_for('dashboard'))
        flash('Invalid username or password')
    return render_template('signin.html')
コード例 #2
0
ファイル: app.py プロジェクト: carc1n0gen/tutorial-apps
def signup():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        if username and password:
            user = get_user(username)
            # Check that this username is not taken
            if not user:
                # Hash the password when inserting a new user
                insert_user(username,
                            hashpw(password.encode('utf-8'), gensalt()))
                return redirect(url_for('signin'))
            flash('Username is taken')
    return render_template('signup.html')
コード例 #3
0
def signup():
    if request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        if username and password:
            user = get_user(username)
            # Check that this username is not taken
            if not user:
                # Hash the password when inserting a new user
                insert_user(username, generate_password_hash(password))
                flash('Signup successful, please signin now.')
                return redirect(url_for('signin'))
            flash('Username is taken')
    return render_template('signup.html')
コード例 #4
0
ファイル: app.py プロジェクト: carc1n0gen/tutorial-apps
def is_loggedin():
    user_id = session.get('user_id')
    user = get_user(user_id=user_id)
    return user is not None