Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route("/register", methods=["GET","POST"])
- def register():
- # forget any user_id
- session.clear()
- # if user reached route via POST (as by submitting a form via POST)
- if request.method == "POST":
- # ensure username was submitted
- if not request.form.get("username"):
- return apology("must provide username")
- # ensure password was submitted
- if not request.form.get("password"):
- return apology("must provide password")
- #ensure again password submitted
- if not request.form.get("again_password"):
- return apology("must provide password again")
- #ensure both password match
- if request.form.get("password") == request.form.get("again_password"):
- #query database for username
- rows = db.execute("SELECT * FROM users WHERE username = :username", username=request.form.get("username"))
- #Ensure usename don't exist already
- if len(rows) == 0:
- #insert username and password to SQL data base
- db.execute("INSERT INTO users (username, hash) VALUES(:username, :password)", username=request.form["username"], password=pwd_context.encrypt("password"))
- #return to login.html page to login after successful register
- return render_template("login.html")
- else:
- #return apology if username already exist
- return apology("Username already exist")
- else:
- #return apology if both password don't match with each other
- return apology("both password should match")
- #Return to register.html and use post mathod
- else:
- return render_template("register.html")
Add Comment
Please, Sign In to add comment