forked from Anteros-Code-Mentoria/poc-mvc-ocr
Ajustando telas de login
This commit is contained in:
parent
32e4770ac7
commit
f0ea5b282b
49
app/app.py
Normal file
49
app/app.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
from flask import Flask, render_template, request, redirect, url_for, session, flash
|
||||||
|
import os
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.secret_key = 'segredo-super-seguro'
|
||||||
|
|
||||||
|
# Rota de login
|
||||||
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
|
def login():
|
||||||
|
if request.method == 'POST':
|
||||||
|
email = request.form['email']
|
||||||
|
password = request.form['password']
|
||||||
|
if email == 'admin@admin.com' and password == '123456':
|
||||||
|
session['user'] = 'Admin'
|
||||||
|
return redirect(url_for('dashboard'))
|
||||||
|
else:
|
||||||
|
flash('Credenciais inválidas.', 'danger')
|
||||||
|
return render_template('login.html')
|
||||||
|
|
||||||
|
# Rota protegida
|
||||||
|
@app.route('/dashboard')
|
||||||
|
def dashboard():
|
||||||
|
if 'user' not in session:
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
return render_template('dashboard.html', user_name=session['user'])
|
||||||
|
|
||||||
|
# Rota de upload
|
||||||
|
@app.route('/upload', methods=['GET', 'POST'])
|
||||||
|
def upload():
|
||||||
|
if 'user' not in session:
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
if request.method == 'POST':
|
||||||
|
file = request.files['file']
|
||||||
|
if file:
|
||||||
|
filepath = os.path.join('uploads', file.filename)
|
||||||
|
os.makedirs('uploads', exist_ok=True)
|
||||||
|
file.save(filepath)
|
||||||
|
flash('Arquivo enviado com sucesso!', 'success')
|
||||||
|
return render_template('upload.html')
|
||||||
|
|
||||||
|
# Logout
|
||||||
|
@app.route('/logout')
|
||||||
|
def logout():
|
||||||
|
session.clear()
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True, port=5003)
|
||||||
27
app/statics/css/style.css
Normal file
27
app/statics/css/style.css
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
body {
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
h3 {
|
||||||
|
color: #343a40;
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
background: #fff;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0px 3px 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-brand {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.btn {
|
||||||
|
transition: background-color 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.btn:hover {
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
21
app/templates/base.html
Normal file
21
app/templates/base.html
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pt-br">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{% block title %}OCR App{% endblock %}</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark px-4">
|
||||||
|
<a class="navbar-brand" href="#">OCR App</a>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container mt-4">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -1,13 +1,9 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "base.html" %}
|
||||||
<html lang="pt">
|
|
||||||
<head>
|
{% block title %}Dashboard - OCR App{% endblock %}
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
{% block content %}
|
||||||
<title>Dashboard</title>
|
<h3>Bem-vindo(a), {{ user_name }}</h3>
|
||||||
</head>
|
<p>Escolha uma ação no menu ou envie um novo documento para OCR.</p>
|
||||||
<body>
|
<a href="/upload" class="btn btn-outline-primary">Enviar novo documento</a>
|
||||||
<h1>Bem-vindo ao Dashboard!</h1>
|
{% endblock %}
|
||||||
<p>Usuário logado: {{ user_email }}</p>
|
|
||||||
<a href="{{ url_for('login_form.login') }}">Sair</a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|||||||
@ -1,32 +1,22 @@
|
|||||||
<!DOCTYPE html>
|
{% extends "base.html" %}
|
||||||
<html lang="pt">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
<title>Login</title>
|
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="login-container">
|
|
||||||
<h2>Login</h2>
|
|
||||||
|
|
||||||
{% with messages = get_flashed_messages(with_categories=True) %}
|
|
||||||
{% if messages %}
|
|
||||||
{% for category, message in messages %}
|
|
||||||
<div class="alert alert-{{ category }}">{{ message }}</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
{% endwith %}
|
|
||||||
|
|
||||||
<form method="POST">
|
{% block title %}Login - OCR App{% endblock %}
|
||||||
<label for="email">E-mail:</label>
|
|
||||||
<input type="email" name="email" required>
|
|
||||||
|
|
||||||
<label for="password">Senha:</label>
|
{% block content %}
|
||||||
<input type="password" name="password" required>
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-md-4">
|
||||||
<button type="submit">Entrar</button>
|
<h3 class="mb-4">Login</h3>
|
||||||
|
<form method="POST" action="/login">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label>Email:</label>
|
||||||
|
<input type="email" name="email" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label>Senha:</label>
|
||||||
|
<input type="password" name="password" class="form-control" required>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-primary w-100" type="submit">Entrar</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</div>
|
||||||
</html>
|
{% endblock %}
|
||||||
|
|||||||
14
app/templates/upload.html
Normal file
14
app/templates/upload.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Upload de Arquivo - OCR App{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h3>Upload de Documento</h3>
|
||||||
|
<form method="POST" action="/upload" enctype="multipart/form-data">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="file" class="form-label">Selecionar Arquivo</label>
|
||||||
|
<input class="form-control" type="file" id="file" name="file" accept=".pdf,.jpg,.png,.jpeg" required>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-success" type="submit">Enviar</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in New Issue
Block a user