-
Notifications
You must be signed in to change notification settings - Fork 0
/
views_user.py
30 lines (25 loc) · 983 Bytes
/
views_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from main import app
from flask import Flask, render_template, request, redirect, session, flash, url_for
from models import Usuarios
from helpers import FormularioUsuario
@app.route('/login')
def login():
proxima = request.args.get('proxima')
return render_template('login.html', proxima=proxima)
@app.route('/autenticar', methods=['POST', ])
def autenticar():
usuario = Usuarios.query.filter_by(nickname=request.form['usuarios']).first()
if usuario:
if request.form['senha'] == usuario.senha:
session['usuario_logado'] = usuario.nickname
flash(usuario.nickname + ' logado com sucesso!')
proxima_pagina = request.form['proxima']
return redirect(proxima_pagina)
else:
flash('Usuário não logado.')
return redirect(url_for('login'))
@app.route('/logout')
def logout():
session['usuario_logado'] = None
flash('Logout efetuado com sucesso!')
return redirect(url_for('index'))