예제 #1
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None

        if not username:
            error = 'Username is required.'
        elif not password:
            error = 'Password is required.'
        elif db.execute(
            'SELECT id FROM user WHERE username = ?', (username,)
        ).fetchone() is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            db.execute(
                'INSERT INTO user (username, password) VALUES (?, ?)',
                (username, password)
            )
            db.commit()
            return redirect(url_for('iauth.login'))

        flash(error)

    return render_template('iauth/register.html')
예제 #2
0
def load_logged_in_user():
    user_id = session.get('user_id')
    table = session.get('table')

    if user_id is None or table is None:
        g.user = None
    else:
        g.user = get_db().execute(
            'SELECT * FROM ' + table + ' WHERE id = ?', (user_id,)
        ).fetchone()
예제 #3
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute(
            'SELECT id FROM user WHERE username = "******" and password = "******"'
        ).fetchone()

        if user is None:
            error = 'Unknown username'

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            session['table'] = 'user'
            return redirect(url_for('home'))

        flash(error)

    return render_template('iauth/login.html')
예제 #4
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute(
            'SELECT * FROM shuser WHERE username = ?', (username,)
        ).fetchone()

        if user is None:
            error = 'Incorrect username.'
        elif not check_password_hash(user['password'], password):
            error = 'Incorrect password.'

        if error is None:
            session.clear()
            session['user_id'] = user['id']
            session['table'] = 'shuser'
            return redirect(url_for('home'))

        flash(error)

    return render_template('shauth/login.html')