def home(): if request.method == "GET": return render_template("home.html") else: button = request.form['button'] if button == "Create Account": newUser = request.form['newUser'] newPass = request.form['newPass'] newPassC = request.form['newPassC'] #password match check if (newPass == newPassC): #username and password lengths check if len(newUser) < 4: return render_template( 'home.html', error2="Username must be longer than 4 characters") if len(newPass) < 4: return render_template( 'home.html', error2="Password must be longer than 4 characters") #account created successfully if module.newUser(newUser, newPass): return render_template('home.html', success="Account created!") #username taken error else: return render_template('home.html', error2="Username taken") else: return render_template('home.html', error2="Passwords do not match!") #Login #if credentials valid, log them in with session if button == "Login": uname = request.form['username'] pword = request.form['password'] if module.authenticate(uname, pword): if 'n' not in session: session['n'] = uname return redirect(url_for('home')) #else renders login w/ error message else: return render_template("home.html", error="Invalid Username or Password")
def home(): if request.method=="GET": return render_template("home.html") else: button = request.form['button'] if button == "Create Account": newUser = request.form['newUser'] newPass = request.form['newPass'] newPassC = request.form['newPassC'] #password match check if (newPass == newPassC): #username and password lengths check if len(newUser)<4: return render_template('home.html',error2="Username must be longer than 4 characters") if len(newPass)<4: return render_template('home.html',error2="Password must be longer than 4 characters") #account created successfully if module.newUser(newUser,newPass): return render_template('home.html',success="Account created!") #username taken error else: return render_template('home.html',error2="Username taken") else: return render_template('home.html',error2="Passwords do not match!") #Login #if credentials valid, log them in with session if button == "Login": uname = request.form['username'] pword = request.form['password'] if module.authenticate(uname,pword): if 'n' not in session: session['n'] = uname return redirect(url_for('home')) #else renders login w/ error message else: return render_template("home.html",error="Invalid Username or Password")
def registration_handler(): user_key = module.generate_code(config.users, 'user_key', 64) database.insert_info(config.users, module.newUser(user_key)) return jsonify({'ok': True, 'user_key': user_key})