Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
@app.route("/user/create", methods=["GET","POST"])
def create():
""" Create a new account,
we will redirect to a homepage here
"""
if flask.request.method == "GET":
return flask.render_template("create_account.html")
#Get the form data
email = flask.request.form.get("email")
password = flask.request.form.get("password")
password2 = flask.request.form.get("password2")
#Sanity check do we have a name, email and password
if not email or not password:
flask.flash("Not all info supplied")
return flask.render_template("create_account.html",
email = email)
#fix 1
if password != password2:
flask.flash("The password re-entered is different")
return flask.render_template("create_account.html",
email = email)
#fix 2
if len(password ) < 6:
flask.flash("The password length should be at least 6 characters")
return flask.render_template("create_account.html",
email = email)
#Otherwise we can add the user
theQry = "Select * FROM User WHERE email = '{0}'".format(email)
userQry = query_db(theQry, one=True)
if userQry:
flask.flash("A User with that Email Exists")
return flask.render_template("create_account.html",
name = email,
email = email)
else:
#Crate the user
app.logger.info("Create New User")
#fix 3
import hashlib
salt='salt'
passwd_salt = (salt + password).encode('utf-8')
hashed_password = hashlib.md5(passwd_salt).hexdigest()
theQry = f"INSERT INTO user (id, email, password) VALUES (NULL, '{email}', '{hashed_password}')"
userQry = write_db(theQry)
flask.flash("Account Created, you can now Login")
return flask.redirect(flask.url_for("login"))