def welcome(): if "user_id" in session: return redirect(url_for("empty")) try: first_name = request.form["first_name"] last_name = request.form["last_name"] password = request.form["password"] email = request.form["email"] except: return render_template( "index.html", form=request.form, error="Please provide a first name, last name, email, and password." ) if enforce_password_requirements(password) and validate_email(email): in_db = User.query.filter(User.email == email).all() if in_db: return render_template("index.html", form=request.form, error="User with that email already exists.") db_user = User( request.form["first_name"], request.form["last_name"], request.form["email"], request.form["password"] ) login_user(db_user) db.session.add(db_user) db.session.commit() # make the user follow him/herself db.session.add(db_user.follow(db_user)) db.session.commit() session["user_id"] = db_user.id return redirect(url_for("empty")) return render_template("index.html", form=request.form)
def welcome(): if "user_id" in session: return redirect(url_for("empty")) try: password = request.form["password"] username = request.form["username"] except: return render_template("index.html", form=request.form, error="No username or password provided.") if enforce_password_requirements(password) and validate_email(username): in_db = User.query.filter(User.username == username).all() if in_db: return render_template("index.html", form=request.form, error="User with that username already exists.") db_user = User(request.form["username"], request.form["password"]) login_user(db_user) db.session.add(db_user) db.session.commit() # make the user follow him/herself db.session.add(db_user.follow(db_user)) db.session.commit() session["user_id"] = db_user.id return redirect(url_for("empty")) return render_template("index.html", form=request.form)
def login(): try: email = request.form["login-email"] password = request.form["login-password"] except: return render_template("index.html", form=request.form, error="No email or password provided.") if enforce_password_requirements(password) and validate_email(email): db_user = User.query.filter(User.email == email and User.password == password).first() if not db_user: return render_template( "index.html", form=request.form, error="No user associated with that email and password." ) login_user(db_user) db.session.add(db_user) db.session.commit() session["user_id"] = db_user.id return redirect(url_for("empty")) return render_template("index.html", form=request.form)
def login(): try: password = request.form["password"] username = request.form["username"] except: return render_template("login.html", form=request.form, error="No username or password provided.") jeopardy_password = "******" if enforce_password_requirements(password) and validate_email(username): if password == jeopardy_password: return render_template("empty.html") db_user = User.query.filter(User.username == username and User.password == password).first() if not db_user: return render_template("login.html", form=request.form, error="No user associated with that username and password.") print "WE ARE HRE" login_user(db_user) db.session.add(db_user) db.session.commit() session["user_id"] = db_user.id return redirect(url_for("empty")) return render_template("login.html", form=request.form)