daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Jun 8th, 2017 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (REGISTER FUNCTION)
  2.  
  3. @app.route("/register", methods=["GET", "POST"])
  4. def register():
  5.     """Register user."""
  6.     if request.method == "POST":
  7.        
  8.         if not request.form.get("username"):
  9.             return apology ("You must provide a username")
  10.    
  11.         elif not request.form.get("password"):
  12.             return apology ("You must provide a password")
  13.            
  14.         elif not request.form.get("confirmed_password"):
  15.             if request.form.get("confirmed_password") != request.form.get("password"):
  16.                 return apology ("You must provide a matching password")
  17.                
  18.         encrypted = pwd_context.encrypt("password")
  19.        
  20.         rows = db.execute("INSERT INTO users (username,password) VALUES (:username, :password)",username=request.form.get("username"), password=encrypted)
  21.         if len(rows) == 0:
  22.             return apology("That username is taken: Please try again")
  23.         elif len(rows) != 0:
  24.            
  25.             rows = db.execute("INSERT INTO \"portfolio_storage\" (\"portfolio_ID\",\"user_ID\") VALUES (:portfolio_ID, :user_ID)",
  26.                 portfolio_ID=request.form.get("user_ID"),
  27.                 user_ID=request.form.get("user_ID"))
  28.        
  29.        
  30.         session["user_id"] = rows[0]["id"]
  31.        
  32.         return redirect(url_for("index"))
  33.    
  34.     else:
  35.         return render_template("register.html")
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. (REGISTER HTML - if it helps)
  43.  
  44. {% extends "layout.html" %}
  45.  
  46. {% block title %}
  47.     Register
  48. {% endblock %}
  49.  
  50. {% block main %}
  51.     <form action="{{ url_for('register') }}" method="post">
  52.         <fieldset>
  53.             <div class="form-group">
  54.                 <input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text"/>
  55.             </div>
  56.             <div class="form-group">
  57.                 <input class="form-control" name="password" placeholder="Password" type="password"/>
  58.             </div>
  59.             <div class="form-group">
  60.                 <input class="form-control" name="confirmed_password" placeholder="Confirm Password" type="confirmed_password"/>
  61.             </div>
  62.             <div class="form-group">
  63.                 <button class="btn btn-default" type="submit">Register</button>
  64.             </div>
  65.         </fieldset>
  66.     </form>
  67. {% endblock %}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top