def setup(self): super(TestUser, self).setup() self.cli = self.app.test_client() self.user = User('test', '*****@*****.**', 'password') db.session.add(self.user) db.session.commit()
def reset_password(code): try: username = _check_reset_password_code(code) except itsdangerous.SignatureExpired: flash('Reset code expired, please get another one!', 'error') return redirect(url_for('.reset_password_request')) except itsdangerous.BadSignature: flash('Could not verify reset code. Please try again!', 'error') return redirect(url_for('.reset_password_request')) form = ResetPasswordForm() if form.validate_on_submit(): user = User.fetch(username) if user: user.password = form.password.data db.session.commit() flash('Password successfully reset: please log in.', 'success') else: flash('Username not found in our database!', 'error') return redirect(url_for('.login')) return render_template('user/reset_password.html', form=form)
def test_home_post(self): """Update user data if logged in""" self.login() self.cli.post(url_for('user.home_for_user', username='******'), data={'email': '*****@*****.**'}) u = User.fetch('test') h.assert_equal(u.email, '*****@*****.**')
def setup(self): super(TestMain, self).setup() self.cli = self.app.test_client() self.user = User('test', '*****@*****.**', 'password') self.consumer = Consumer('annotateit') self.consumer.secret = 'secret' db.session.add(self.user) db.session.add(self.consumer) db.session.commit()
def before_request(): g.debug = current_app.debug # User from session username = session.get('user') g.user = User.fetch(username) g.auth = auth.Authenticator(Consumer.fetch) g.authorize = authz.authorize g.after_annotation_create = _add_annotation_link g.before_annotation_update = _add_annotation_link
def view_annotation(id, format=None): ann = Annotation.fetch(id) if ann is None: return abort(404) if g.authorize(ann, 'read', g.user): if ann['consumer'] == 'annotateit': user = User.fetch(ann['user']) else: user = None return {'annotation': ann, 'user': user} abort(401)
def _add_user(form): user = User(username=form.username.data, email=form.email.data, password=form.password.data) db.session.add(user) try: db.session.commit() except sqlalchemy.exc.IntegrityError as e: if 'email is not unique' in e.message: form.email.errors.append("This email address is already registered: please use another.") if 'username is not unique' in e.message: form.username.errors.append("This username is taken: please use another.") return False # Fallthrough: all's gone well. return True
def test_null_password(self): u = User('joe', '*****@*****.**') h.assert_false(u.check_password('foo'))
def test_password(self): u = User('joe', '*****@*****.**') u.password = '******' h.assert_is_not_none(u.password_hash) h.assert_true(u.check_password('foo'))
def _get_session_user(): username = session.get('user') if username is None: return None else: return User.fetch(username)
email = '' while not email: email = raw_input("Admin email: ").strip() password = '' while not password: password = getpass("Admin password: "******"Primary consumer key [annotateit]: ").strip() if not ckey: ckey = 'annotateit' with app.test_request_context(): print("\nCreating admin user... ", end="") u = User(username, email, password) u.is_admin = True db.session.add(u) db.session.commit() print("done.") print("Creating primary consumer... ", end="") c = Consumer(ckey) c.user_id = u.id db.session.add(c) db.session.commit()
def test_gravatar_url(self): u = User('joe', '*****@*****.**') h.assert_equal(u.gravatar_url, 'http://www.gravatar.com/avatar/011b2f33289a5f9941e457bdd1e549ff?d=mm')
def test_constructor(self): u = User('joe', '*****@*****.**') h.assert_equal(u.username, 'joe') h.assert_equal(u.email, '*****@*****.**')
print("Migrating database... ") migrate.upgrade(**migrate_args) print("done.") ckey = os.environ.get('CONSUMER_KEY', 'annotateit') csecret = os.environ.get('CONSUMER_SECRET', 'annotate.it.secret') with app.test_request_context(): users_count = User.query.count() print("Users in DB: " + str(users_count)) if users_count == 0: print("Creating admin user... ") u = User(username, email, password) u.is_admin = True db.session.add(u) db.session.commit() print("done.\n") print("Creating primary consumer... ") c = Consumer(ckey) c.user_id = u.id c.secret = csecret db.session.add(c) db.session.commit()