diff --git a/app/dashboard/templates/dashboard/index.html b/app/dashboard/templates/dashboard/index.html index 6252363e..ef178405 100644 --- a/app/dashboard/templates/dashboard/index.html +++ b/app/dashboard/templates/dashboard/index.html @@ -15,16 +15,18 @@ use it whenever possible, for example on untrusted websites 😎"> Alias -
- - -
- {% if current_user.can_create_custom_email() %} - - Custom alias - - {% endif %} +
+
+ + +
+ +
+ + +
+
@@ -57,8 +59,12 @@
Created {{ gen_email.created_at | dt }}
+ {% if gen_email.custom %} +
Custom
+ {% endif %} + {% if alias_info.highlight %} - New +
New
{% endif %} diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index 794f54f1..a826a25e 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -60,6 +60,15 @@ def index(): else: flash(f"You need to upgrade your plan to create new email.", "warning") + elif request.form.get("form-name") == "create-custom-email": + if current_user.can_create_custom_email(): + return redirect(url_for("dashboard.custom_alias")) + else: + flash( + f"You need to upgrade your plan to create new custom email.", + "warning", + ) + elif request.form.get("form-name") == "switch-email-forwarding": gen_email_id = request.form.get("gen-email-id") gen_email: GenEmail = GenEmail.get(gen_email_id) diff --git a/app/models.py b/app/models.py index f4b26af8..87e2c5b0 100644 --- a/app/models.py +++ b/app/models.py @@ -111,9 +111,6 @@ class User(db.Model, ModelMixin, UserMixin): password = random_string(20) user.set_password(password) - - # by default new user will be trial period - user.trial_expiration = arrow.now().shift(days=+15) db.session.flush() # create a first alias mail to show user how to use when they login @@ -138,23 +135,23 @@ class User(db.Model, ModelMixin, UserMixin): return False - def is_trial(self): - return self.trial_expiration is not None and self.trial_expiration > arrow.now() - def can_create_custom_email(self): if self.is_premium(): return True - elif self.is_trial(): - return True - return False + + return ( + GenEmail.filter_by(user_id=self.id, custom=True).count() + < MAX_NB_EMAIL_FREE_PLAN + ) def can_create_new_email(self): if self.is_premium(): return True - elif self.is_trial(): - return True - else: # free or trial expired - return GenEmail.filter_by(user_id=self.id).count() < MAX_NB_EMAIL_FREE_PLAN + else: + return ( + GenEmail.filter_by(user_id=self.id, custom=False).count() + < MAX_NB_EMAIL_FREE_PLAN + ) def set_password(self, password): salt = bcrypt.gensalt() @@ -206,9 +203,6 @@ class User(db.Model, ModelMixin, UserMixin): return "Monthly ($2.99/month)" else: return "Yearly ($29.99/year)" - - elif self.is_trial(): - return "Trial" else: return "Free Plan" @@ -409,9 +403,9 @@ class GenEmail(db.Model, ModelMixin): user = db.relationship(User) @classmethod - def create_new_gen_email(cls, user_id): + def create_new_gen_email(cls, user_id, custom=False): random_email = generate_email() - return GenEmail.create(user_id=user_id, email=random_email) + return GenEmail.create(user_id=user_id, email=random_email, custom=custom) def __repr__(self): return f"" diff --git a/tests/test_models.py b/tests/test_models.py index d8b7d161..7ea6faff 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -40,7 +40,6 @@ def test_suggested_emails_for_user_who_cannot_create_new_email(flask_client): user = User.create( email="a@b.c", password="password", name="Test User", activated=True ) - user.trial_expiration = arrow.now().shift(days=-1) db.session.commit() # make sure user runs out of quota to create new email