You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

from flask import request
from flask import render_template
from flask import redirect
from main import app
from morsel_util import *
def session_start(form):
resp = redirect("/", code=303)
resp.set_cookie('username', form['username'])
resp.set_cookie('token', crypt(form['password'], str(int(time()))))
return resp
@app.route('/login', methods=['POST', 'GET'])
def login():
error = None
if request.method == 'POST':
if passchk(request.form['username'], request.form['password']):
return session_start(request.form)
error = 'Invalid username/password'
if "success" in request.args:
error = "Successfully registered your account!"
return render_template('login.html', error=error)
def logout():
resp = redirect("/login", code=303)
return resp
@app.route('/reg', methods=['POST', 'GET'])
def register():
error = None
if request.method == 'POST':
if ((not uexist(request.form['username'])) and len(request.form['password']) >= 8
and request.form['username'].strip() != "" and not any(illegal_character in request.form['username'] for illegal_character in "%&.+?;")):
newuser(request.form['username'], request.form['password'])
return redirect('/login?success', 303)
elif len(request.form['password']) < 8:
error = "Password must be at least 8 characters."
error = "Username already taken."
return render_template('register.html', error=error)