mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 15:05:59 +08:00
rename can_create_custom_email -> can_create_new_custom_alias, can_create_new_email -> can_create_new_random_alias
This commit is contained in:
parent
6764a4b582
commit
c58d9052e7
|
@ -14,7 +14,7 @@ from app.utils import convert_to_id, random_string
|
||||||
@login_required
|
@login_required
|
||||||
def custom_alias():
|
def custom_alias():
|
||||||
# check if user has the right to create custom alias
|
# check if user has the right to create custom alias
|
||||||
if not current_user.can_create_custom_email():
|
if not current_user.can_create_new_custom_alias():
|
||||||
# notify admin
|
# notify admin
|
||||||
LOG.error("user %s tries to create custom alias", current_user)
|
LOG.error("user %s tries to create custom alias", current_user)
|
||||||
flash("ony premium user can choose custom alias", "warning")
|
flash("ony premium user can choose custom alias", "warning")
|
||||||
|
|
|
@ -50,9 +50,9 @@ def index():
|
||||||
)
|
)
|
||||||
|
|
||||||
elif request.form.get("form-name") == "create-random-email":
|
elif request.form.get("form-name") == "create-random-email":
|
||||||
can_create_new_email = current_user.can_create_new_email()
|
can_create_new_random_alias = current_user.can_create_new_random_alias()
|
||||||
|
|
||||||
if can_create_new_email:
|
if can_create_new_random_alias:
|
||||||
gen_email = GenEmail.create_new_gen_email(user_id=current_user.id)
|
gen_email = GenEmail.create_new_gen_email(user_id=current_user.id)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ def index():
|
||||||
)
|
)
|
||||||
|
|
||||||
elif request.form.get("form-name") == "create-custom-email":
|
elif request.form.get("form-name") == "create-custom-email":
|
||||||
if current_user.can_create_custom_email():
|
if current_user.can_create_new_custom_alias():
|
||||||
return redirect(url_for("dashboard.custom_alias"))
|
return redirect(url_for("dashboard.custom_alias"))
|
||||||
else:
|
else:
|
||||||
flash(
|
flash(
|
||||||
|
|
|
@ -134,7 +134,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def can_create_custom_email(self):
|
def can_create_new_custom_alias(self):
|
||||||
if self.is_premium():
|
if self.is_premium():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
< MAX_NB_EMAIL_FREE_PLAN
|
< MAX_NB_EMAIL_FREE_PLAN
|
||||||
)
|
)
|
||||||
|
|
||||||
def can_create_new_email(self):
|
def can_create_new_random_alias(self):
|
||||||
if self.is_premium():
|
if self.is_premium():
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -171,7 +171,7 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
def suggested_emails(self) -> (str, [str]):
|
def suggested_emails(self) -> (str, [str]):
|
||||||
"""return suggested email and other email choices """
|
"""return suggested email and other email choices """
|
||||||
all_gen_emails = [ge.email for ge in GenEmail.filter_by(user_id=self.id)]
|
all_gen_emails = [ge.email for ge in GenEmail.filter_by(user_id=self.id)]
|
||||||
if self.can_create_new_email():
|
if self.can_create_new_random_alias():
|
||||||
# create a new email
|
# create a new email
|
||||||
suggested_gen_email = generate_email()
|
suggested_gen_email = generate_email()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
{% if current_user.can_create_custom_email() %}
|
{% if current_user.can_create_new_custom_alias() %}
|
||||||
<div class="mt-2">OR</div>
|
<div class="mt-2">OR</div>
|
||||||
<div style="display: flex; align-items: center" class="mt-2">
|
<div style="display: flex; align-items: center" class="mt-2">
|
||||||
<input class="form-control"
|
<input class="form-control"
|
||||||
|
|
|
@ -151,7 +151,7 @@ def authorize():
|
||||||
gen_email = None
|
gen_email = None
|
||||||
if custom_email_prefix:
|
if custom_email_prefix:
|
||||||
# check if user can generate custom email
|
# check if user can generate custom email
|
||||||
if not current_user.can_create_custom_email():
|
if not current_user.can_create_new_custom_alias():
|
||||||
raise Exception(f"User {current_user} cannot create custom email")
|
raise Exception(f"User {current_user} cannot create custom email")
|
||||||
|
|
||||||
email = f"{convert_to_id(custom_email_prefix)}.{email_suffix}@{EMAIL_DOMAIN}"
|
email = f"{convert_to_id(custom_email_prefix)}.{email_suffix}@{EMAIL_DOMAIN}"
|
||||||
|
@ -273,9 +273,9 @@ def authorize():
|
||||||
|
|
||||||
|
|
||||||
def create_or_choose_gen_email(user) -> GenEmail:
|
def create_or_choose_gen_email(user) -> GenEmail:
|
||||||
can_create_new_email = user.can_create_new_email()
|
can_create_new_random_alias = user.can_create_new_random_alias()
|
||||||
|
|
||||||
if can_create_new_email:
|
if can_create_new_random_alias:
|
||||||
gen_email = GenEmail.create_new_gen_email(user_id=user.id)
|
gen_email = GenEmail.create_new_gen_email(user_id=user.id)
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
LOG.debug("generate email %s for user %s", gen_email.email, user)
|
LOG.debug("generate email %s for user %s", gen_email.email, user)
|
||||||
|
|
|
@ -19,7 +19,7 @@ def test_profile_picture_url(flask_client):
|
||||||
assert user.profile_picture_url() == "http://sl.test/static/default-avatar.png"
|
assert user.profile_picture_url() == "http://sl.test/static/default-avatar.png"
|
||||||
|
|
||||||
|
|
||||||
def test_suggested_emails_for_user_who_can_create_new_email(flask_client):
|
def test_suggested_emails_for_user_who_can_create_new_random_alias(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
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue