remove trial concept
This commit is contained in:
parent
8dca65678e
commit
6e71541985
|
@ -15,16 +15,18 @@
|
||||||
use it whenever possible, for example on untrusted websites 😎">
|
use it whenever possible, for example on untrusted websites 😎">
|
||||||
Alias
|
Alias
|
||||||
</h3>
|
</h3>
|
||||||
<form method="post" class="col text-right">
|
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<form method="post" style="margin-right: 10px">
|
||||||
<input type="hidden" name="form-name" value="create-random-email">
|
<input type="hidden" name="form-name" value="create-random-email">
|
||||||
<button class="btn btn-success">Random alias</button>
|
<button class="btn btn-success">Random alias</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if current_user.can_create_custom_email() %}
|
<form method="post">
|
||||||
<a href="{{ url_for('dashboard.custom_alias') }}" class="btn btn-primary">
|
<input type="hidden" name="form-name" value="create-custom-email">
|
||||||
Custom alias
|
<button class="btn btn-primary">Custom alias</button>
|
||||||
</a>
|
</form>
|
||||||
{% endif %}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row row-cards row-deck mt-4">
|
<div class="row row-cards row-deck mt-4">
|
||||||
|
@ -57,8 +59,12 @@
|
||||||
<div>
|
<div>
|
||||||
Created {{ gen_email.created_at | dt }}
|
Created {{ gen_email.created_at | dt }}
|
||||||
</div>
|
</div>
|
||||||
|
{% if gen_email.custom %}
|
||||||
|
<div class="text-success">Custom</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if alias_info.highlight %}
|
{% if alias_info.highlight %}
|
||||||
<span class="text-success">New</span>
|
<div class="text-success">New</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,15 @@ def index():
|
||||||
else:
|
else:
|
||||||
flash(f"You need to upgrade your plan to create new email.", "warning")
|
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":
|
elif request.form.get("form-name") == "switch-email-forwarding":
|
||||||
gen_email_id = request.form.get("gen-email-id")
|
gen_email_id = request.form.get("gen-email-id")
|
||||||
gen_email: GenEmail = GenEmail.get(gen_email_id)
|
gen_email: GenEmail = GenEmail.get(gen_email_id)
|
||||||
|
|
|
@ -111,9 +111,6 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
password = random_string(20)
|
password = random_string(20)
|
||||||
|
|
||||||
user.set_password(password)
|
user.set_password(password)
|
||||||
|
|
||||||
# by default new user will be trial period
|
|
||||||
user.trial_expiration = arrow.now().shift(days=+15)
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
|
|
||||||
# create a first alias mail to show user how to use when they login
|
# 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
|
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):
|
def can_create_custom_email(self):
|
||||||
if self.is_premium():
|
if self.is_premium():
|
||||||
return True
|
return True
|
||||||
elif self.is_trial():
|
|
||||||
return True
|
return (
|
||||||
return False
|
GenEmail.filter_by(user_id=self.id, custom=True).count()
|
||||||
|
< MAX_NB_EMAIL_FREE_PLAN
|
||||||
|
)
|
||||||
|
|
||||||
def can_create_new_email(self):
|
def can_create_new_email(self):
|
||||||
if self.is_premium():
|
if self.is_premium():
|
||||||
return True
|
return True
|
||||||
elif self.is_trial():
|
else:
|
||||||
return True
|
return (
|
||||||
else: # free or trial expired
|
GenEmail.filter_by(user_id=self.id, custom=False).count()
|
||||||
return GenEmail.filter_by(user_id=self.id).count() < MAX_NB_EMAIL_FREE_PLAN
|
< MAX_NB_EMAIL_FREE_PLAN
|
||||||
|
)
|
||||||
|
|
||||||
def set_password(self, password):
|
def set_password(self, password):
|
||||||
salt = bcrypt.gensalt()
|
salt = bcrypt.gensalt()
|
||||||
|
@ -206,9 +203,6 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
return "Monthly ($2.99/month)"
|
return "Monthly ($2.99/month)"
|
||||||
else:
|
else:
|
||||||
return "Yearly ($29.99/year)"
|
return "Yearly ($29.99/year)"
|
||||||
|
|
||||||
elif self.is_trial():
|
|
||||||
return "Trial"
|
|
||||||
else:
|
else:
|
||||||
return "Free Plan"
|
return "Free Plan"
|
||||||
|
|
||||||
|
@ -409,9 +403,9 @@ class GenEmail(db.Model, ModelMixin):
|
||||||
user = db.relationship(User)
|
user = db.relationship(User)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_new_gen_email(cls, user_id):
|
def create_new_gen_email(cls, user_id, custom=False):
|
||||||
random_email = generate_email()
|
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):
|
def __repr__(self):
|
||||||
return f"<GenEmail {self.id} {self.email}>"
|
return f"<GenEmail {self.id} {self.email}>"
|
||||||
|
|
|
@ -40,7 +40,6 @@ def test_suggested_emails_for_user_who_cannot_create_new_email(flask_client):
|
||||||
user = User.create(
|
user = User.create(
|
||||||
email="a@b.c", password="password", name="Test User", activated=True
|
email="a@b.c", password="password", name="Test User", activated=True
|
||||||
)
|
)
|
||||||
user.trial_expiration = arrow.now().shift(days=-1)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
# make sure user runs out of quota to create new email
|
# make sure user runs out of quota to create new email
|
||||||
|
|
Loading…
Reference in a new issue