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 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 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 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 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]) 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 test_create_user(self): user = User() user.name = 'hugo' user.password = '******' user.save() dk = hashlib.pbkdf2_hmac('sha256', b'123', b'salt', 100000) encrypted_passowrd = binascii.hexlify(dk) self.assertEqual(len(User.objects.all()), 1) saved_user = User.objects.all()[0] self.assertNotEqual(saved_user.created, None) self.assertEqual(saved_user.password, encrypted_passowrd)
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 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 show(id): found_user = User.query.get_or_404(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": edit_user_form = EditUserForm(request.form) if edit_user_form.validate(): if User.authenticate(found_user.username, edit_user_form.password.data): found_user.username = edit_user_form.username.data found_user.email = edit_user_form.email.data found_user.image_url = edit_user_form.image_url.data or None found_user.first_name = edit_user_form.first_name.data or None found_user.last_name = edit_user_form.last_name.data or None found_user.location = edit_user_form.location.data or None found_user.bio = edit_user_form.bio.data or None found_user.header_image_url = edit_user_form.header_image_url.data or '/static/images/warbler-hero.jpg' 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' }) # from IPython import embed; embed() return render_template('users/edit.html', form=edit_user_form, user=found_user) if request.method == b"DELETE": db.session.delete(found_user) db.session.commit() return redirect(url_for('users.signup'))
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 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 = EditForm(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.first_name = form.first_name.data or None found_user.last_name = form.last_name.data or None found_user.bio = form.bio.data or None found_user.location = form.location.data or None found_user.image_url = form.image_url.data or None found_user.header_image_url = form.header_image_url.data or None 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': token = request.form.get('csrf_token') if validate_csrf(token) == None: db.session.delete(found_user) db.session.commit() return redirect(url_for('users.signup')) return render_template('404.html')
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 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 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() 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)
def post(self): user = User.from_json(request.data) try: user.save() return(user.to_json(), 201) except NotUniqueError: return('{"error": "User Name Conflict"}', 409) except: return('{}', 500)
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 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(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 login(): form = LoginForm(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 are now logged in!") return redirect(url_for('users.users')) flash("Invalid Credentials") return render_template('users/login.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 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 tearDown(self): User.drop_collection() Cache.redis.flushall()