-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from LMOlivera/dev
Actualización 0.2
- Loading branch information
Showing
24 changed files
with
385 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
-- http://www.phpmyadmin.net | ||
-- | ||
-- Servidor: localhost | ||
-- Tiempo de generación: 21-02-2019 a las 23:16:09 | ||
-- Tiempo de generación: 02-03-2019 a las 18:45:09 | ||
-- Versión del servidor: 5.5.24-log | ||
-- Versión de PHP: 5.4.3 | ||
|
||
|
@@ -57,6 +57,14 @@ CREATE TABLE IF NOT EXISTS `empresa` ( | |
PRIMARY KEY (`id`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8; | ||
|
||
-- | ||
-- Volcado de datos para la tabla `empresa` | ||
-- | ||
|
||
INSERT INTO `empresa` (`id`, `nombre`) VALUES | ||
(3, 'Empresa Falsa 1'), | ||
(4, 'Empresa Falsa 2'); | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
|
@@ -110,6 +118,14 @@ CREATE TABLE IF NOT EXISTS `turista` ( | |
`pais_origen` varchar(100) NOT NULL | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8; | ||
|
||
-- | ||
-- Volcado de datos para la tabla `turista` | ||
-- | ||
|
||
INSERT INTO `turista` (`id`, `edad`, `pais_origen`) VALUES | ||
(1, 25, 'Tangamandapio'), | ||
(2, 31, 'Nosedonde'); | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
|
@@ -125,7 +141,17 @@ CREATE TABLE IF NOT EXISTS `usuario` ( | |
`tipo` varchar(100) NOT NULL, | ||
PRIMARY KEY (`id_usuario`), | ||
UNIQUE KEY `email` (`email`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; | ||
|
||
-- | ||
-- Volcado de datos para la tabla `usuario` | ||
-- | ||
|
||
INSERT INTO `usuario` (`id_usuario`, `email`, `nombre`, `contrasena`, `foto`, `tipo`) VALUES | ||
(1, '[email protected]', 'Fulano de Tal', 'contrasenia', NULL, 'Turista'), | ||
(2, '[email protected]', 'Sultano de Tal', 'pass', NULL, 'Turista'), | ||
(3, '[email protected]', 'Senior de Negocios', 'passempresa', NULL, 'Empresa'), | ||
(4, '[email protected]', 'Seniora de Empresa', 'passempresa2', NULL, 'Empresa'); | ||
|
||
-- -------------------------------------------------------- | ||
|
||
|
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.01 KB
(110%)
Prototipo - Interfaz de Usuario/2-A Vista Turista - dentro de categoria.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from flask import Flask | ||
from config import Config | ||
|
||
app = Flask(__name__) | ||
app.config.from_object(Config) | ||
|
||
from app import routes | ||
|
||
from app import routes |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from flask_wtf import FlaskForm | ||
from wtforms import StringField, PasswordField, BooleanField, SubmitField | ||
from wtforms.validators import DataRequired | ||
from wtforms.fields.html5 import EmailField | ||
# Este archivo contiene todos los formularios del sistema. | ||
|
||
class LoginForm(FlaskForm): | ||
# validators argument es para validaciones. | ||
# DataRequired chequea que no estén vacíos, aunque existen más validaciones. | ||
email = EmailField('Email', validators=[DataRequired()]) | ||
password = PasswordField('Contraseña', validators=[DataRequired()]) | ||
submit = SubmitField("Iniciar sesión") | ||
|
||
class RegisterForm(FlaskForm): | ||
email = EmailField('Email') | ||
nombre = StringField('Nombre y apellido') | ||
password = PasswordField('Contraseña') | ||
# foto? | ||
tipo = StringField('Tipo') | ||
# TURISTA | ||
edad = StringField('Edad') | ||
pais = StringField('País de origen') | ||
# EMPRESA | ||
nombreEmpresa = StringField('Nombre de la empresa') | ||
submit = SubmitField("Crear usuario") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,143 @@ | ||
from flask import render_template | ||
from flask import render_template, flash, redirect, session, request | ||
from app import app | ||
from app.forms import LoginForm, RegisterForm | ||
import pymysql.cursors | ||
|
||
@app.route('/') | ||
@app.route('/index') | ||
# Connect to the database | ||
connection = pymysql.connect(host='localhost', | ||
user='root', | ||
password='', | ||
db='uruguia_bd_test', | ||
charset='utf8mb4', | ||
cursorclass=pymysql.cursors.DictCursor) | ||
|
||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
@app.route('/index', methods=['GET', 'POST']) | ||
def bienvenido(): | ||
return render_template('bienvenido.html') | ||
if session.get('logueado'): | ||
return redirect('/principal') | ||
else: | ||
form = LoginForm() # Formulario de forms.py, se importa | ||
if form.validate_on_submit(): #Al submitear data se corre esto | ||
with connection.cursor() as cursor: | ||
email=form.email.data | ||
password=form.password.data | ||
query = "SELECT id_usuario, email, nombre, tipo FROM usuario WHERE email=%s AND contrasena=%s" | ||
cursor.execute(query,(email,password)) | ||
userdata = cursor.fetchone() | ||
results = cursor.rowcount | ||
if results==0: | ||
flash('Usuario y/o contraseña inválidos') | ||
session['invalid_user']="true" | ||
return redirect('/') | ||
else: | ||
session.pop('invalid_user', None) | ||
session['logueado']=True | ||
session['id_usuario'] = userdata['id_usuario'] | ||
session['email'] = userdata['email'] | ||
session['nombre'] = userdata['nombre'] | ||
session['tipo'] = userdata['tipo'] | ||
return redirect('/principal') | ||
return render_template('bienvenido.html', form=form) | ||
|
||
@app.route('/index/registro') | ||
@app.route('/index/registro', methods=['GET', 'POST']) | ||
def registro(): | ||
return render_template('registro.html') | ||
if session.get('logueado'): | ||
return redirect('/principal') | ||
else: | ||
nuevo = request.args.to_dict() | ||
form = RegisterForm() | ||
if form.validate_on_submit(): | ||
try: | ||
with connection.cursor() as cursor: | ||
email = form.email.data | ||
nombre = form.nombre.data | ||
password = form.password.data | ||
tipo = nuevo['tipo'] | ||
query = """ | ||
INSERT INTO usuario | ||
(email,nombre,contrasena,tipo) | ||
VALUES | ||
(%s,%s,%s,%s) | ||
""" | ||
cursor.execute(query,(email,nombre,password,tipo)) | ||
query = """ | ||
SELECT id_usuario FROM usuario | ||
WHERE email=%s | ||
""" | ||
cursor.execute(query,(email)) | ||
userdata = cursor.fetchone() | ||
id_usuario=userdata['id_usuario'] | ||
|
||
if nuevo['tipo']=='turista': | ||
edad = form.edad.data | ||
pais = form.pais.data | ||
query = """ | ||
INSERT INTO turista | ||
(id,edad,pais_origen) | ||
VALUES | ||
(%s,%s,%s) | ||
""" | ||
cursor.execute(query,(id_usuario,edad,pais)) | ||
else: | ||
nombreEmpresa = form.nombreEmpresa.data | ||
query = """ | ||
INSERT INTO empresa | ||
(id,nombre) | ||
VALUES | ||
(%s,%s) | ||
""" | ||
cursor.execute(query,(id_usuario,nombreEmpresa)) | ||
connection.commit() | ||
session.clear() | ||
return redirect('/index') | ||
except NameError: | ||
print('Algo malo acaba de ocurrir: ' + NameError) | ||
return render_template('registro.html', form=form,tipo=nuevo['tipo']) | ||
|
||
@app.route('/principal') | ||
def index(): | ||
if session.get('logueado'): | ||
print('ok') | ||
else: | ||
session.clear() | ||
return redirect('/') | ||
return render_template('principal.html') | ||
|
||
@app.route('/principal/usuario') | ||
def usuario(): | ||
if session.get('logueado'): | ||
print('ok') | ||
else: | ||
session.clear() | ||
return redirect('/') | ||
return render_template('usuario.html') | ||
|
||
|
||
@app.route('/logout') | ||
def logout(): | ||
try: | ||
idu = request.args.to_dict() | ||
iduINT = int(idu['id_usuario']) | ||
ses = int(session['id_usuario']) | ||
with connection.cursor() as cursor: | ||
query = """ | ||
DELETE FROM usuario WHERE id_usuario=%s | ||
""" | ||
cursor.execute(query,(ses)) | ||
if session['tipo']=='turista': | ||
query = """ | ||
DELETE FROM turista WHERE id=%s | ||
""" | ||
cursor.execute(query,(ses)) | ||
else: | ||
query = """ | ||
DELETE FROM empresa WHERE id=%s | ||
""" | ||
cursor.execute(query,(ses)) | ||
connection.commit() | ||
except: | ||
print("Logout") | ||
session.clear() | ||
return redirect('/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#danger-zone{ | ||
background-color: tomato; | ||
color: white; | ||
padding: 5px; | ||
} | ||
|
||
#confirmar-borrar-usuario{ | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
{% if title %} | ||
{% else %} | ||
{% endif %} | ||
<title>{{ title }}</title> | ||
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='css/style.css') }}"> | ||
|
||
</head> | ||
<body> | ||
<div id='navbar'> | ||
Microblog: <a href="/exit">Home</a> | ||
<div> | ||
Microblog: | ||
<a href="{{ url_for('index') }}">Home</a> | ||
<a href="{{ url_for('test') }}">Login</a> | ||
</div> | ||
<hr> | ||
{% with messages = get_flashed_messages() %} | ||
{% if messages %} | ||
<ul> | ||
{% for message in messages %} | ||
<li>{{ message }}</li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endwith %} | ||
{% block content %}{% endblock %} | ||
</body> | ||
</html> |
Oops, something went wrong.