def show(user_id): found_user = User.query.get_or_404(user_id) if request.method == b'PATCH': form = UserForm(request.form) if form.validate(): try: form.populate_obj(found_user) db.session.add(found_user) db.session.commit() flash("You edited this user.") return redirect(url_for('users.show', user_id=found_user.id)) #if violates unique field for username/email except IntegrityError as e: if (str(e.orig.pgerror).find('username_key') != -1): flash( "Please enter a different username. This user already exists." ) else: flash( "Please enter a different email. This email already exists." ) db.session.rollback() #if form isn't validating return render_template('users/edit.html', user=found_user, form=form) if request.method == b'DELETE': db.session.delete(found_user) db.session.commit() flash("You deleted the user: " + found_user.username) return redirect(url_for('users.index')) return render_template('users/show.html', user=found_user)
def show(id): user = User.query.get(id) delete_form = DeleteForm(request.form) form = UserForm(request.form) if request.method == b'PATCH': if form.validate(): user.email = form.data['email'] user.password = bcrypt.generate_password_hash( form.data['password']).decode('UTF-8') db.session.add(user) db.session.commit() flash("You have successfully changed your account details!") return redirect(url_for('lists.index', user_id=user.id)) else: flash( "Something went wrong in editing your account details. Please try again." ) return render_template('users/edit.html', user=user, form=form, delete_form=delete_form) if request.method == b'DELETE': if delete_form.validate(): db.session.delete(user) db.session.commit() flash("You have successfully deleted your account.") logout_user() return redirect(url_for('users.index')) else: flash( "Something went wrong in deleting your account. Please try again." ) return redirect(url_for('users.edit', id=user.id)) return render_template('users/show.html', user=user)
def index(): if request.method == 'POST': form = UserForm(request.form) if form.validate(): try: new_user = User(form.username.data, form.email.data, form.first_name.data, form.last_name.data) db.session.add(new_user) db.session.commit() flash("You added the user: "******"Please enter a different username. This user already exists." ) else: flash( "Please enter a different email. This email already exists." ) return render_template('users/new.html', form=form) users = User.query.all() return render_template('users/index.html', users=users)
def show(id): found_user = User.query.get(id) if (request.method == 'GET' or current_user.is_anonymous or current_user.get_id() != str(id)): return render_template('users/show.html', user=found_user) if request.method == b"PATCH": form = UserForm(request.form) if form.validate(): if User.authenticate(found_user.username, form.password.data): found_user.username = form.username.data found_user.email = form.email.data found_user.image_url = form.image_url.data found_user.name = form.name.data found_user.location = form.location.data found_user.bio = form.bio.data found_user.header_image_url = form.header_image_url.data db.session.add(found_user) db.session.commit() return redirect(url_for('users.show', id=id)) flash({ 'text': "Wrong password, please try again.", 'status': 'danger' }) return render_template('users/edit.html', form=form, user=found_user) if request.method == b"DELETE": logout_user() db.session.delete(found_user) db.session.commit() return redirect(url_for('users.signup'))
def show(id): selected_user = User.query.get(id) # Use b"PATCH" because Flask Modus makes request.method a bytes literal if request.method == b"PATCH": user_form = UserForm(request.form) if user_form.validate(): selected_user.first_name = request.form['first_name'] selected_user.last_name = request.form['last_name'] selected_user.username = request.form['username'] selected_user.password = bcrypt.generate_password_hash( request.form['password']).decode('UTF-8') db.session.add(selected_user) db.session.commit() flash("User Updated!") return redirect(url_for('users.users')) else: flash("Form Error: User Not Updated") return render_template('users/edit.html', user=selected_user, user_form=user_form, delete_form=DeleteForm()) if request.method == b"DELETE": delete_form = DeleteForm(request.form) if delete_form.validate(): db.session.delete(selected_user) db.session.commit() flash("User Deleted!") return redirect(url_for('users.users')) else: flash("Form Error: User Not Deleted") return redirect(url_for('users.users')) return render_template('users/show.html', user=selected_user)
def signup(): form = UserForm() if request.method == "POST": if not form.errors: if form.validate(): try: new_user = User(username=form.username.data, password=form.password.data) if form.avatar.data: new_user.avatar = form.avatar.data db.session.add(new_user) db.session.commit() login_user(new_user) except IntegrityError as e: flash({ 'text': "Username already taken", 'status': 'danger' }) return render_template('users/signup.html', form=form) flash({ 'text': "Oh hey {}, welcome to Bartinder!".format( new_user.username), 'status': 'success' }) return redirect(url_for('root')) flash({ 'text': str(list(form.errors.values())).replace('[', '').replace(']', ''), 'status': 'danger' }) return render_template('users/signup.html', form=form)
def signup(): form = UserForm() if request.method == "POST": if form.validate(): try: new_user = User(email=form.email.data, username=form.username.data, name=form.name.data, address=form.address.data, city=form.city.data, state=form.state.data, zipcode=form.zipcode.data, password=form.password.data) if form.image_url.data: new_user.image_url = form.image_url.data db.session.add(new_user) db.session.commit() login_user(new_user) except IntegrityError as e: flash({ 'text': "Username or email already taken", 'status': 'danger' }) return render_template('users/signup.html', form=form) return redirect(url_for('root')) return render_template('users/signup.html', form=form)
def new_user(): form = UserForm(request.form) if form.validate(): db.session.add( User(request.form["first_name"], request.form["last_name"])) db.session.commit() return redirect(url_for("users.index")) return render_template("users/new.html", form=form)
def login(): form = UserForm(request.form) if request.method == "POST" and form.validate(): user = User.authenticate(form.data["username"], form.data["password"]) if user: session["user_id"] = user.id flash("You've successfully logged in!") return redirect(url_for("users.welcome")) return render_template("login.html", form=form)
def signup(): form = UserForm(request.form) if request.method == 'POST': user = User.query.filter( func.lower(User.username) == func.lower( form.username.data)).first() if user: flash({'text': "Username already use", 'status': 'danger'}) return render_template('users/signup.html', form=form) if form.validate(): try: payload = { 'key': os.environ.get('API_KEY'), 'steamids': form.steamID.data } r = requests.get( 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/', params=payload) p = r.json() if not p['response']['players']: flash({'text': "Invalid steamID", 'status': 'danger'}) return render_template('users/signup.html', form=form) url = p['response']['players'][0]['avatarfull'] if not form.carry.data and not form.support2.data and not form.support1.data and not form.offlane.data and not form.mid.data: flash({ 'text': "Please choose at least one position", 'status': 'danger' }) return render_template('users/signup.html', form=form) new_user = User(username=form.username.data, email=form.email.data, steamID=form.steamID.data, password=form.password.data, mmr=form.mmr.data, support2=form.support2.data, support1=form.support1.data, offlane=form.offlane.data, mid=form.mid.data, carry=form.carry.data) new_user.img_url = url db.session.add(new_user) db.session.commit() login_user(new_user) except IntegrityError as e: flash({ 'text': "Email, or steamID already use", 'status': 'danger' }) return render_template('users/signup.html', form=form) flash({ 'text': "You have successfully signed up!", 'status': 'success' }) return redirect(url_for('root')) return render_template('users/signup.html', form=form)
def edit_user(id): form = UserForm(request.form) if form.validate(): user = User.query.get(id) user.first_name = request.form["first_name"] user.last_name = request.form["last_name"] db.session.add(user) db.session.commit() return redirect(url_for("users.index")) return render_template("users/show.html", user=user)
def index(): if request.method == "POST": form = UserForm(request.form) if form.validate(): new_user = User(form.first_name.data, form.last_name.data) db.session.add(new_user) db.session.commit() flash('User Created!') return redirect(url_for('users.index')) return render_template('users/new.html', form=form) return render_template('users/index.html', users=User.query.all())
def signup(): form = UserForm(request.form) if request.method == "POST" and form.validate(): try: new_user = User(form.data['username'], form.data['password']) db.session.add(new_user) db.session.commit() except IntegrityError as e: return render_template('signup.html', form=form) return redirect(url_for('users.login')) return render_template('signup.html', form=form)
def index(): if request.method == "POST": form = UserForm(request.form) if form.validate(): new_user = User(request.form['username'], request.form['email'], request.form['first_name'], request.form['last_name']) db.session.add(new_user) db.session.commit() return redirect(url_for('users.index')) return render_template('users/new.html', form=form) return render_template('users/index.html', users=User.query.all())
def login(): form = UserForm(request.form) if request.method == "POST": if form.validate(): user = User.authenticate(form.data['username'], form.data['password']) if user: login_user(user) flash("You've successfully logged in!") return redirect(url_for('users.welcome')) flash("Invalid credentials. Please try again.") return render_template('login.html', form=form)
def signup(): form = UserForm(request.form) if request.method == "POST" and form.validate(): try: new_user = User(form.data["username"], form.data["password"]) db.session.add(new_user) db.session.commit() except IntegrityError as e: flash("Invalid submission. Please try again") return render_template("signup.html", form=form) return redirect(url_for("users.login")) return render_template("signup.html", form=form)
def users(): if request.method == "POST": form = UserForm(request.form) if form.validate(): new_user = User(request.form["first_name"], request.form["last_name"]) db.session.add(new_user) db.session.commit() flash("User Created!") else: flash("Form Error: User Not Created") return render_template('new.html', form=form) return render_template('index.html', users=User.query.all())
def signup(): form = UserForm(request.form) if request.method == 'POST': if form.validate(): try: new_user = User(form.data['email'], form.data['password']) db.session.add(new_user) db.session.commit() login_user(new_user) except IntegrityError as e: flash("That e-mail address is already taken.") return render_template('signup.html', form=form) flash("You have successfully created an account!") return redirect(url_for('users.welcome')) return render_template('users/signup.html', form=form)
def index(): if request.method == "POST": form = UserForm(request.form) if form.validate(): new_user = User(request.form.get("first_name"), request.form.get("last_name"), request.form.get("username"), request.form.get("password")) db.session.add(new_user) db.session.commit() return redirect(url_for("users.index")) else: return render_template("users/new.html", form=form) all_users = User.query.all() return render_template("users/index.html", users=all_users)
def index(): delete_form = DeleteForm() if request.method == "POST": form = UserForm(request.form) if form.validate(): new_user = User(request.form['first_name'], request.form['last_name']) db.session.add(new_user) db.session.commit() flash('User Created!') return redirect(url_for('users.index')) else: return render_template('/users/new.html', form=form) return render_template('users/index.html', users=User.query.all(), delete_form=delete_form)
def signup(): form = UserForm(request.form) if request.method == "POST" and form.validate(): try: new_user = User(form.data['first_name'], form.data['last_name'], form.data['username'], form.data['password']) db.session.add(new_user) db.session.commit() # Log user in after registration login_user(new_user) except IntegrityError as e: flash("Username already taken") return render_template('users/signup.html', form=form) flash('User Created!') return redirect(url_for('users.users')) return render_template('users/signup.html', form=form)
def signup(): form = UserForm() if request.method == "POST": if form.validate(): try: new_user = User(username=form.username.data, email=form.email.data, password=form.password.data) db.session.add(new_user) db.session.commit() login_user(new_user) except IntegrityError as e: flash({'text': "Username already taken", 'status': 'danger'}) return render_template('users/signup.html', form=form) return redirect(url_for('root')) return render_template('users/signup.html', form=form)
def new(): form = UserForm(request.form) if request.method == "POST": if form.validate(): try: flash("You have succesfully created a new user!") new_user = User(request.form.get('first_name'),request.form.get('last_name'),request.form.get('image_url'),request.form.get('username'),request.form.get('email'),request.form.get('password')) db.session.add(new_user) db.session.commit() login_user(new_user) except IntegrityError as e: flash("Username already taken.") return render_template('users/new.html', form=form) return redirect(url_for('users.index')) flash("Invalid submission. Please try again.") return render_template('users/new.html', form=form)
def show(id): found_user = User.query.get(id) if request.method == b"PATCH": form = UserForm(request.form) if form.validate(): found_user.first_name = request.form['first_name'] found_user.last_name = request.form['last_name'] db.session.add(found_user) db.session.commit() return redirect(url_for('users.index')) return render_template('users/edit.html', form=form, owner=found_user) if request.method == b"DELETE": db.session.delete(found_user) db.session.commit() return redirect(url_for('users.index')) return render_template('users/show.html', owner=found_user)
def show(id): user = User.query.get(id) form = UserForm(obj=user) if request.method == b"PATCH" and form.validate(): user.username = form.data['username'] user.password = form.data['password'] user.email = form.data['email'] db.session.add(user) db.session.commit() return redirect(url_for('index.html')) return redirect(url_for('users.edit', form=form, id=user.id)) if request.method == b"DELETE": db.session.delete(user) db.session.commit() logout_user() return redirect(url_for('users.signup')) return redirect('users/index.html')
def new_user(): form = UserForm(request.form) if form.validate(): try: new_user = User( form.first_name.data, form.last_name.data, form.user_name.data, form.password.data, ) db.session.add(new_user) db.session.commit() session["user_id"] = new_user.id flash("User Created!") return redirect(url_for("users.show", id=new_user.id)) except IntegrityError: flash("Username already taken!") return render_template("users/new.html", form=form)
def show(id): found_user = User.query.get(id) if request.method == b"PATCH": form = UserForm(request.form) if form.validate(): found_user.username = request.form['username'] found_user.password = bcrypt.generate_password_hash( request.form['password']).decode('UTF-8') found_user.avatar = request.form['avatar'] db.session.add(found_user) db.session.commit() return redirect(url_for('users.home')) return render_template('users/edit.html', form=form, user=found_user) if request.method == b"DELETE": db.session.delete(found_user) db.session.commit() logout_user() return redirect(url_for('users.home')) return render_template('users/show.html', user=found_user)
def signup(): form = UserForm(request.form) if request.method == "POST": if form.validate(): try: new_user = User( form.first_name.data, form.last_name.data, form.username.data, form.password.data, ) db.session.add(new_user) db.session.commit() session['user_id'] = new_user.id flash('User Created!') return redirect(url_for('users.index')) except IntegrityError as e: flash("Username already taken") return render_template('users/signup.html', form=form) return render_template('users/signup.html', form=form)
def signup(): form = UserForm(request.form) if request.method == "POST": if form.validate(): try: new_user = User( request.form['username'], request.form['password'], request.form['name'], request.form['email'] ) db.session.add(new_user) db.session.commit() login_user(new_user) flash("Welcome {}!".format(new_user.username)) return redirect(url_for('users.index')) except IntegrityError as e: flash("Username has been taken") return render_template('users/signup.html', form=form) return render_template('users/signup.html', form=form)
def show(id): found_user = User.query.get(id) if request.method == b"PATCH": form = UserForm(request.form) if form.validate(): found_user.first_name = form.first_name.data found_user.last_name = form.last_name.data found_user.username = form.username.data found_user.password = bcrypt.generate_password_hash( form.password.data).decode('UTF-8') db.session.add(found_user) db.session.commit() return redirect(url_for('users.index')) return render_template('users/edit.html', form=form, owner=found_user) if request.method == b"DELETE": db.session.delete(found_user) db.session.commit() session.pop('user_id') flash('User Deleted') return redirect(url_for('users.login')) return render_template('users/show.html', owner=found_user)