from flask import Flask, redirect, render_template, url_for, request
from flask_login import (
                            LoginManager, UserMixin, login_user, 
                            logout_user, current_user                 
                        )

app = Flask(__name__)
app.secret_key = 'secret'

login_manager = LoginManager()
login_manager.init_app(app)

users = {
            '<EMAIL>':{'senha':'vitor1998', 'nome':'<NAME>'}, 
            '<EMAIL>':{'senha':'joao1234', 'nome':'<NAME>'}
        }
class User(UserMixin):
    pass

@login_manager.user_loader
def user_loader(email):
    user = User()
    user.id = email
    user.nome = users[email]['nome']
    return user

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/paginaprotegida')
def paginaprotegida():
    if current_user.is_authenticated:
        return render_template('paginaprotegida.html')
    else:
        return render_template('aviso.html')

@app.route('/logout')
def logout():
    logout_user()
    return redirect(url_for('login'))

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        email = request.form['email']
        senha = request.form['password']
        
        if email in users:
            if senha == users[email]['senha']:
                login_user(user_loader(email))
                return redirect(url_for('paginaprotegida'))    
        
        return render_template('login.html')

    return render_template('login.html')

if __name__ == '__main__':
    app.run(debug=True)

from flask import Flask, redirect, render_template, url_for, request
from flask_login import (
                            LoginManager, UserMixin, login_user, 
                            logout_user, current_user                 
                        )

app = Flask(__name__)
app.secret_key = 'secret'

login_manager = LoginManager()
login_manager.init_app(app)

users = {
            '<EMAIL>':{'senha':'vitor1998', 'nome':'<NAME>'}, 
            '<EMAIL>':{'senha':'joao1234', 'nome':'<NAME>'}
        }
class User(UserMixin):
    pass

@login_manager.user_loader
def user_loader(email):
    user = User()
    user.id = email
    user.nome = users[email]['nome']
    return user

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/paginaprotegida')
def paginaprotegida():
    if current_user.is_authenticated:
        return render_template('paginaprotegida.html')
    else:
        return render_template('aviso.html')

@app.route('/logout')
def logout():
    logout_user()
    return redirect(url_for('login'))

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        email = request.form['email']
        senha = request.form['password']
        
        if email in users:
            if senha == users[email]['senha']:
                login_user(user_loader(email))
                return redirect(url_for('paginaprotegida'))    
        
        return render_template('login.html')

    return render_template('login.html')

if __name__ == '__main__':
    app.run(debug=True)
