def register(): """Return a friendly HTTP greeting.""" if request.method == 'GET': return render_template('register.html', errortype=None) else: name = request.form['name'] lastName = request.form['lastname'] email = request.form['email'] knd = request.form['kind'] pasw = request.form['pssw'] paswc = request.form['psswc'] terms = request.form['terms'] # Agregar comprobación de usuario existente if name and lastName and email and pasw and paswc and terms and knd: if terms == "True": if pasw == paswc: query = 'INSERT INTO usuarios (Nombre, Apellido, email, knd, pasw) VALUES ("%s", "%s", "%s", "%s", "%s");' % ( name, lastName, email, knd, pasw) print run_query(query) session['email'] = email session['nombre'] = name session['kind'] = knd return redirect('/') else: return render_template('/register.html', errortype=2) else: return render_template('/register.html', errortype=1) else: return render_template('/register.html', errortype=0)
def inicioBiblioteca(): if request.method == "GET": return render_template('inicioB.html', creadores=creadores) try: #c, conn = connection() #query = 'INSERT INTO cuerpo (ojo, boca) VALUES ("%s", "%s")' %(ojo, boca) #query = 'UPDATE cuerpo SET boca = "de Sandra" WHERE ojo = "azul" ' query = 'SELECT Autor FROM Libros WHERE ISSN = "2530-1039" ' print run_query(query) return ("Operacion exitosa") except Exception as e: return (str(e))
def messasgesave(): """Return a friendly HTTP greeting.""" if request.method == 'POST': id_tema = request.form['tema_id'] print id_tema mensaje = request.form['mensaje'] print mensaje run_query( 'INSERT INTO mensajes (email, id_tema, fecha, mensaje) VALUES ("%s", "%s", NOW(), "%s");' % (session['email'], id_tema, mensaje)) url = '/foro/mensajes:%s%s' % (id_tema, session['email']) return redirect(url) return "metodo post"
def register_page(): user = "******" nombre = "Francisco" eCorreo = "*****@*****.**" Contrasena = "1234" try: #c, conn = connection() #query = 'INSERT INTO usuarios (Usuario, Nombre, eCorreo, Contrasena) VALUES ("%s", "%s", "%s", "%s")' %(user, nombre, eCorreo, Contrasena) #query = 'UPDATE usuarios SET Nombre = "Sandra" WHERE Contrasena = "" ' query = 'SELECT Nombre FROM usuarios WHERE contrasena = "" ' print run_query(query) return("Operacion exitosa") except Exception as e: return(str(e))
def foro_contenido(tema_id, user): """Return a friendly HTTP greeting.""" if request.method == 'GET': info_tema = run_query('SELECT * FROM foro WHERE id_tema = "%s";' % tema_id) info_mensajes = run_query( 'SELECT * FROM mensajes WHERE id_tema = "%s";' % tema_id) if info_tema: return rendering_template( JINJA_ENVIRONMENT.get_template('mensajes_foro.html').render({ 'info_tema': info_tema, 'info_mensajes': info_mensajes }), " ", " ") else: return rendering_template( JINJA_ENVIRONMENT.get_template('mensajes_foro.html').render(), "", "") return "metodo post"
def login(): """Return a friendly HTTP greeting.""" if request.method == 'GET': return render_template('/login.html') email = request.form['email'] pasw = request.form['pssw'] consulta = 'SELECT email, pasw, Nombre, knd FROM usuarios WHERE email = "%s";' % email result = run_query(consulta) if result: if result[0][0] == email and result[0][1] == pasw: session['email'] = email session['nombre'] = result[0][2] session['kind'] = result[0][3] return redirect('/')
def foro_nuevo(): """Return a friendly HTTP greeting.""" if request.method == 'GET': return rendering_template( JINJA_ENVIRONMENT.get_template('form_nu_foro.html').render(), "Foros de discusion", 'Crear nuevo tema') tema = request.form['subject'] mensaje = request.form['message'] fecha = time.strftime("%x") if run_query( 'INSERT INTO foro (autor, titulo, mensaje, fecha) VALUES ("%s", "%s", "%s", NOW());' % (session['email'], tema, mensaje)): return rendering_template( JINJA_ENVIRONMENT.get_template('form_nu_foro.html').render(), "Foros de discusion", 'Resulva cualquier duda') return rendering_template( JINJA_ENVIRONMENT.get_template('success.html').render(), "Foros de discusion", 'Tema creado exitosamente')
def foro_modificar(): """Return a friendly HTTP greeting.""" if request.method == 'GET': consulta = 'SELECT * FROM foro WHERE autor = "%s";' % session['email'] resultados = run_query(consulta) if resultados: template = JINJA_ENVIRONMENT.get_template('foro_temas.html') html_content = {'resultado': resultados} #print html_content return rendering_template(template.render(html_content), "Foros de Discusion", "Actualice la informacion o elimine") #return "pass" #rendering_template(JINJA_ENVIRONMENT.get_template('foro_temas.html').render(), "Foros de discusion", 'Resulva cualquier duda') else: template = JINJA_ENVIRONMENT.get_template('foro_temas.html') html_content = {'resultado': False} return rendering_template(template.render(html_content), "Foros de Discusion", " ") #nombre = request.form['idioma'] return redirect("/")