def test_get_by_id(self): """Get user by ID.""" user = User("foo", "*****@*****.**") user.save() retrieved = User.get_by_id(user.id) assert retrieved == user
def restore_password(tk): if current_user.is_authenticated: return redirect(url_for("public.home")) try: decoded_token = jwtToken.decode(tk, oct_data, do_verify=True, do_time_check=True) except JWTDecodeError: flash("Password reset link has expired.", "warning") return redirect(url_for("public.home")) user = User.query.filter_by(email=decoded_token["email"]).first() if not user: flash("Can't find any matching user.", "warning") return render_template("public/home") form = RestorePasswordForm(request.form) if not form.validate_on_submit(): # flash("Unable to update your password, please type in your password again.", "warning") return render_template("public/restore_password.html", form=form, email=decoded_token["email"]) else: User.update(self=user, password=bcrypt.generate_password_hash(form.password.data)) flash("Password updated.", "success") return redirect(url_for("public.home"))
def register(): """Register new user.""" if current_user.is_authenticated: return redirect(url_for("public.home")) form = RegisterForm(request.form) if form.validate_on_submit(): User.create( username=form.username.data, email=form.email.data, password=form.password.data, active=True, ) if form.code.data: group = StudentGroups.query.filter_by(code=form.code.data).first() user = User.query.filter_by(username=form.username.data).first() gid = group.get_id() uid = user.get_id() GroupUsers.create(user_id=uid, group_id=gid) else: group = StudentGroups.query.filter_by(name="ALL").first() gid = group.get_id() user = User.query.filter_by(username=form.username.data).first() uid = user.get_id() GroupUsers.create(user_id=uid, group_id=gid) flash("Thank you for registering. You can now log in.", "success") return redirect(url_for("public.home")) else: flash_errors(form) return render_template("public/register.html", form=form)
def create_admin(): username=os.environ['USERNAME'] email=os.environ['EMAIL'] password=os.environ['PASSWORD'] User.create(username=username, email=email, password=password, active=True, is_admin=True, is_instructor=True)
def create_admin(): username = os.environ["FLASK_USERNAME"] email = os.environ["EMAIL"] password = os.environ["PASSWORD"] User.create( username=username, email=email, password=password, active=True, is_admin=True, is_instructor=True, )
def register(): """Register new user.""" form = RegisterForm(request.form) if form.validate_on_submit(): User.create( username=form.username.data, email=form.email.data, password=form.password.data, active=True, ) flash("Thank you for registering. You can now log in.", "success") return redirect(url_for("public.home")) else: flash_errors(form) return render_template("public/register.html", form=form)
def test_check_password(self): """Check password.""" user = User.create(username="******", email="*****@*****.**", password="******") assert user.check_password("foobarbaz123") is True assert user.check_password("barfoobaz") is False
def load_user(user_id): """Load user by ID.""" return User.get_by_id(int(user_id))
def test_password_is_nullable(self): """Test null password.""" user = User(username="******", email="*****@*****.**") user.save() assert user.password is None
def test_created_at_defaults_to_datetime(self): """Test creation date.""" user = User(username="******", email="*****@*****.**") user.save() assert bool(user.created_at) assert isinstance(user.created_at, dt.datetime)