1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 08:38:59 +00:00

logging in done

This commit is contained in:
Lynne Megido 2019-09-01 17:30:00 +10:00
parent f2f9dc5cff
commit 20b0c46046

View file

@ -1,5 +1,6 @@
from flask import Flask, render_template, session, request, redirect, url_for from flask import Flask, render_template, session, request, redirect, url_for
from flask_mysqldb import MySQL from flask_mysqldb import MySQL
import MySQLdb
import bcrypt import bcrypt
import json, hashlib import json, hashlib
@ -93,3 +94,17 @@ def do_signup():
def do_signout(): def do_signout():
session.clear() session.clear()
return redirect(url_for("home")) return redirect(url_for("home"))
@app.route("/do/login", methods=['POST'])
def do_login():
pw_hashed = hashlib.sha256(request.form['password'].encode('utf-8')).digest()
c = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
c.execute("SELECT * FROM users WHERE email = %s", (request.form['email'],))
data = c.fetchone()
c.close()
if bcrypt.checkpw(pw_hashed, data['password']):
session['userid'] = data['id']
return redirect(url_for("home"))
else:
return "invalid login"