def setUp(self): db.create_all() user1 = User("Brian") user2 = User("Jenny") user3 = User("Grayson") db.session.add_all([user1, user2, user3]) db.session.commit()
def setUp(self): db.create_all() self.user1 = user1 = User( first_name="Miranda", last_name="Howitt", email="*****@*****.**", username="******", bio="SUPES COOL", location="SF", password="******", ) self.user2 = user2 = User( first_name="Paula", last_name="Goyanes", email="*****@*****.**", username="******", bio="SUPES COOLER", location="San Frisco", password="******", ) db.session.add_all([user1, user2]) db.session.commit() message1 = Message(text="Our first message", user_id=1) message2 = Message(text="Our second message", user_id=2) user1.likes_messages.append(message1) db.session.add_all([message1, message2]) db.session.commit()
def setUp(self): db.drop_all() db.create_all() user1 = User(full_name='Test Person 1', username='******', password='******', location='Berkeley, CA', bio='1 test bio about a very interesting life', email='*****@*****.**', image_url='some_picture_1.jpg', header_image_url='some_header_1.png') user2 = User(full_name='Test Person 2', username='******', password='******', location='Berkeley, CA', bio='2 test bio about a very interesting life', email='*****@*****.**', image_url='some_picture_2.jpg', header_image_url='some_header_2.png') user3 = User(full_name='Test Person 3', username='******', password='******', location='Berkeley, CA', bio='3 test bio about a very interesting life', email='*****@*****.**', image_url='some_picture_3.jpg', header_image_url='some_header_3.png') db.session.add_all([user1, user2, user3]) message1 = Message("test message 1", 1) message2 = Message("test message 2", 1) message3 = Message("test message 3", 2) message4 = Message("test message 4", 3) db.session.add_all([message1, message2, message3, message4]) db.session.commit()
def setUp(self): user1 = User("Elie", "Schoppik", "eschoppik", "secret") user2 = User("Tim", "Garcia", "tigarcia", "secret") user3 = User("Matt", "Lane", "mmmaaatttttt", "secret") db.create_all() db.session.add_all([user1, user2, user3]) db.session.commit() self._login_user()
def setUp(self): db.create_all() user1 = User("Elie", "Schoppik") user2 = User("Tim", "Garcia") user3 = User("Matt", "Lane") db.session.add_all([user1, user2, user3]) message1 = Message("Hello Elie!!", 1) message2 = Message("Goodbye Elie!!", 1) message3 = Message("Hello Tim!!", 2) message4 = Message("Goodbye Tim!!", 2) db.session.add_all([message1, message2, message3, message4]) db.session.commit()
def setUp(self): db.drop_all() db.create_all() u1 = User(email='*****@*****.**', username='******', name='john', password='******') u2 = User(email='*****@*****.**', username='******', name='susan', password='******') db.session.add(u1) db.session.add(u2) db.session.commit()
def create_user(self, name=name, email=email, password=pw, role='user'): new_user = User(name=name, email=email, password=password, role=role) db.session.add(new_user) db.session.commit() return self.app.post('/', data=dict(name=name, password=password), follow_redirects=True)
def test_default_user_role(self): db.session.add(User(name, email, pw)) db.session.commit() users = db.session.query(User).all() for user in users: self.assertEqual(user.role, '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 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 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 post(self): #create new user content = request.get_json() user = User(content['email'], content['username'], content['name'], content['password']) db.session.add(user) db.session.commit() return user
def setUp(self): db.create_all() user = User("admin", "admin") db.session.add(user) db.session.commit() db.session.add( Post("Test post", "This is a test. Only a test.", user.id)) db.session.commit()
def register(): form = Registerform() if form.validate_on_submit(): user = User(form.email.data, form.username.data, form.password.data) db.session.add(user) db.session.commit() flash('Successfully registered') return redirect(url_for('login')) return render_template('register.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 setUp(self): db.create_all() user1 = User("Elie", "Schoppik") user2 = User("Tim", "Garcia") user3 = User("Matt", "Lane") db.session.add_all([user1, user2, user3]) message1 = Message("Hello Elie!!", 1) message2 = Message("Goodbye Elie!!", 1) message3 = Message("Hello Tim!!", 2) message4 = Message("Goodbye Tim!!", 2) db.session.add_all([message1, message2, message3, message4]) tag1 = Tag("Greeting") tag2 = Tag("Valediction") db.session.add_all([tag1, tag2]) message1.tags.extend([tag1]) message2.tags.extend([tag2]) message3.tags.extend([tag1]) message4.tags.extend([tag2]) db.session.commit()
def index(): if request.method == "POST": form = UserForm() if form.validate_on_submit(): new_user = User(request.form["user_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 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 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 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 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 index(): form = NewUser(request.form) if request.method == "POST" and form.validate(): new_user = User(request.form["email"], request.form["password"], request.form["first_name"], request.form["last_name"]) db.session.add(new_user) db.session.commit() elif request.method == "POST": error_found = next(iter(form.errors.values()))[0] return render_template("users/signup.html", form=form, error=error_found) return redirect("/")
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 signup(): form = UserForm(request.form) if form.validate_on_submit( ): # vs. .validate(), .validate_on_submit() checks post/patch/delete + validate try: new_user = User(form.data['username'], form.data['email'], form.data['role'], form.data['password']) db.session.add(new_user) db.session.commit() except IntegrityError as e: # without this block, the server would crash when the db complained flash('Username already taken') return render_template('signup.html', form=form) flash('User created, please login to continue') return redirect(url_for('users.login')) return render_template('users/signup.html', form=form)
def signup(): form = SignupForm() 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('users.show', id=new_user.id)) return render_template('users/signup.html', form=form)
def test_cannot_delete_another_users_message(self): """Ensure user can't delete another user's messages""" with self.client: self._login_user('eschoppik', 'secret') self.client.post('/users/1/messages', data=dict(content='Hello World', user_id=session.get('user_id'), follow_redirects=True)) user2 = User("Another", "User", "secret", "secret") db.session.add(user2) db.session.commit() self.client.get('/users/logout', follow_redirects=True) self._login_user('secret', 'secret') response = self.client.post('/users/1/messages/1?_method=DELETE', follow_redirects=True) self.assertIn(b'Not Authorized', response.data)
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 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) 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 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)