Esempio n. 1
0
    def test_create(self):
        user = dict(username="******",
                    email="*****@*****.**")
        password = "******"

        new_user = users.create(user, password)

        assert new_user is not None
        assert new_user.username == user["username"]
        assert isinstance(new_user, User)
Esempio n. 2
0
    def test_get_by_email_sanitized(self):
        user = dict(username="******",
                    email="*****@*****.**")
        password = "******"
        new_user = users.create(user, password)

        retrieved_user = users.get_user_by_email(
            "*****@*****.**")

        assert retrieved_user is not None
        assert new_user.user_id == retrieved_user.user_id
Esempio n. 3
0
    def logged_in_client(self):
        user = dict(username="******", email="*****@*****.**")
        password = "******"
        test_user = users.create(user, password)

        client = self.app.test_client()
        client.post(
            "/auth/login",
            data=dict(username=test_user.username, password="******"),
            follow_redirects=True,
        )

        return client
Esempio n. 4
0
    def several_users(self):
        def user(n):
            return dict(
                username=f"test-user-{n}",
                email=f"test{n}@notanemailprovider.really",
                eaten_offset=2 * n * n,
                baked_offset=n,
            )

        password = "******"

        new_users = [users.create(user(i), password) for i in range(10)]
        return new_users
Esempio n. 5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for("lobby.lobby"))
    form = RegistrationForm()
    if form.validate_on_submit():
        if form.registration_token.data != current_app.config["REGISTRATION_KEY"]:
            flash(f"Your registration token was invalid")
            return redirect(url_for("auth.register"))
        user_dict = dict(username=form.username.data, email=form.email.data)
        user = users.create(user_dict, form.password.data)
        clubsessions.join_all_future_sessions(user)
        flash("Thank you for signing up!")
        login_user(user)
        return redirect(url_for("lobby.lobby"))
    return render_template("register.html", title="Sign Up", form=form)
Esempio n. 6
0
    def test_join_all_future_sessions(self):
        today = datetime.date.today()
        past = today - datetime.timedelta(days=7)
        future = today + datetime.timedelta(days=7)

        today_session = clubsessions.create(date=today, auto_assign=False)
        past_session = clubsessions.create(date=past, auto_assign=False)
        future_session = clubsessions.create(date=future, auto_assign=False)

        user_dict = dict(username="******",
                         email="*****@*****.**")
        new_user = user_module.create(user_dict, "password")

        clubsessions.join_all_future_sessions(new_user)

        assert new_user not in past_session.participants.all()
        assert new_user in today_session.participants.all()
        assert new_user in future_session.participants.all()
Esempio n. 7
0
def create_or_update_user(data):
    temp_password = username_generator.get_uname(10, 64, False)
    temp_password += str(random.randint(1111, 9999))
    existing_user = users_module.get_user_by_email(data["email"])

    if not existing_user:
        user_data = {
            "username": data["username"],
            "email": data["email"],
            "eaten_offset": int(data.get("eaten_offset", 0)),
            "baked_offset": int(data.get("baked_offset", 0)),
        }
        try:
            new_user = users_module.create(user_data, temp_password)
        except SQLAlchemyError:
            raise DatabaseError
    else:
        new_user = existing_user
        if "eaten_offset" in data:
            new_user.eaten_offset = int(data["eaten_offset"])
        if "baked_offset" in data:
            new_user.baked_offset = int(data["baked_offset"])

    if data.get("future"):
        clubsessions.join_all_future_sessions(new_user)

    if data.get("send_welcome_email") is not False:
        new_user.set_password(temp_password)
        send_email(
            "Your Cakeclub Account",
            current_app.config["ADMIN_EMAIL"],
            recipients=[new_user.email],
            body=render_template("email/welcome.html",
                                 user=new_user,
                                 password=temp_password),
            plain=render_template("email/welcome.txt",
                                  user=new_user,
                                  password=temp_password),
        )

    db.session.commit()
    broadcast_session_update()
Esempio n. 8
0
 def test_user(self):
     user = dict(username="******", email="*****@*****.**")
     password = "******"
     return users.create(user, password)