-1

Could someone please point to where I can see how to check in the register route if a username already exists in the database and also whether the user entered the same password in the confirmation field as in the first password field? And as for my current code, here:

@app.route("/register", methods=["GET", "POST"])
def register():
    """Register user."""

    #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")

        if session["username"] == "" or session["password"]:
            return apology("must provide username and password")

Here's my register.html file, which I just wrote:

{ % extends "layout.html" % }

{ % block title % }
    Register
{ % endblock % }

{ % block main % }
    <form action="{{ url_for('register') }}" method="post">
        <fieldset>
            <div class="form-group">
                <input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text"/>
            </div>
            <div class="form-group">
                <input class="form-control" name="password" placeholder="Password" type="password"/>
            </div>
            <div class="form-group">
                <input class="form-control" name="password" placeholder="Confirm Password" type="password"/>
            </div>
            <div class="form-group">
                <input class="btn btn-default" type="submit" value="Register"/>
            </div>
        </fieldset>
    </form>
{ % endblock % }

Is this fine?

Edit: The above code is outdated. I have the updated code in my Pastebin; here's the register route: http://pastebin.com/dh92n3Lz and here's the one for register.html: http://pastebin.com/UHNAfhFh. Firstly, would it be a good idea for me to keep the session.clear() line in my register route?

4
  • I've completed my implementation of register now and am ready to move onto quote. So I want to mark this as "solved" now, but I don't know what to say if I answer it myself. Should I jus say I've finished quote and leave it at that? It'd be bad to show my solution here, after all, right? Mar 10 '17 at 22:29
  • Since you have found a solution, please post an answer (not a comment) with a description of your solution. Self-answers are highly encouraged. Most importantly, accept your answer by clicking the check mark in order to remove the question from the unanswered question pool. Congrats on finding a solution.
    – Cliff B
    Mar 16 '17 at 0:17
  • I'm not sure if I should post an answer. Would it not spoil it for others? Mar 16 '17 at 2:36
  • can explain how u solved this problem?I am having a similar problem and can't add users to the database
    – Leroi
    Apr 1 '17 at 9:15
0

Press the star key to mark as solved

3
  • Mark as favorite? Or is that not what you mean? Mar 10 '17 at 22:45
  • when you log in to your question, is there not a up arrow, a number, a down arrow and underneath the down arrow is something right? You click on that to say it's been answered.
    – cfdphd
    Mar 10 '17 at 22:49
  • This question has been answered by the poster.
    – cfdphd
    Mar 11 '17 at 1:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .