def signup(): form = UserSignup() if form.validate_on_submit(): # If all input is valid when you hit submit will go to "welcome.html" return render_template("login.html", form=form, title="Welcome") # If any of input is not valid when you hit submit will go back to "signup.html" return render_template("signup.html", form=form, title="Signup")
def signup(): form = UserSignup() errors = "Duplicate Data Entered. Data already in Database" if request.method == "POST" and form.validate_on_submit(): # validation #Add data to database by what was entered into the signup form fields username = form.username.data email = form.email.data password = form.password.data #We want to now take the infor that was added by the above and query it to check credetials #can use filter_by().first() if have one column that is unique #ChecK if user already exsist: existing_user = User.query.filter_by(username=username).first() #If don't exsist will create that user if not existing_user: new_user = User(username=username, email=email, password=password) db.session.add(new_user) db.session.commit() session['username'] = username #If user exsist will: return redirect("/newpost") else: # errors = "Duplicate Data Enter. Data already in Database" return render_template("signup.html", form=form, title="Signup", errors=errors) return render_template("signup.html", form=form, title="Signup")
def signup(): """Display signup page""" form = UserSignup() if form.validate_on_submit(): try: # signup user with User classmethod user = User.signup(display_name=form.display_name.data, username=form.username.data, password=form.password.data, caption=form.caption.data) db.session.commit() flash("Account created! Please sign-in to get started.", 'success') return redirect("/login") except IntegrityError: flash("Username is already taken, try something else!", 'danger') return render_template('/users/signup.html', form=form)
def edit_user(user_id): """Display form to edit user""" user = User.query.get(user_id) if user.id == session['_user_id']: # display user edit form form = UserSignup(obj=user) if form.validate_on_submit(): user.username = form.username.data user.display_name = form.display_name.data user.caption = form.caption.data db.session.commit() flash('User information updated!', 'success') return redirect(f"/users/{user.username}") return render_template('/users/edit_user.html', user=user, form=form) else: flash("You do not have permission to make changes to this user!") return redirect('/users')