custom email must have .suffix
This commit is contained in:
parent
a1c65d3921
commit
2a6021c230
|
@ -19,18 +19,19 @@
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-label">Custom Alias</label>
|
<label class="form-label">Custom Alias</label>
|
||||||
<small class="text-muted">
|
<small class="text-muted">
|
||||||
Email must use alphanumeric characters and must be at least 6 characters
|
Email must use alphanumeric characters and must be at least 3 characters
|
||||||
</small>
|
</small>
|
||||||
<div class="row mt-4">
|
<div class="row mt-4">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{ form.email(class="form-control",
|
{{ form.email(class="form-control",
|
||||||
pattern="[0-9|A-Z|a-z]{6,}",
|
pattern="[0-9|A-Z|a-z]{3,}",
|
||||||
title="Email must use alphanumeric characters and must be at least 6 characters.") }}
|
title="Email must use alphanumeric characters and must be at least 3 characters.") }}
|
||||||
{{ render_field_errors(form.email) }}
|
{{ render_field_errors(form.email) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="col align-self-center">
|
<div class="col align-self-center">
|
||||||
|
<input type="hidden" name="email-suffix" value="{{ email_suffix }}">
|
||||||
<h4>
|
<h4>
|
||||||
@simplelogin.co
|
.{{ email_suffix }}@{{ EMAIL_DOMAIN }}
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import render_template, redirect, url_for, flash
|
from flask import render_template, redirect, url_for, flash, request
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import StringField, validators
|
from wtforms import StringField, validators
|
||||||
|
@ -8,7 +8,7 @@ from app.dashboard.base import dashboard_bp
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import GenEmail
|
from app.models import GenEmail
|
||||||
from app.utils import convert_to_id
|
from app.utils import convert_to_id, random_string
|
||||||
|
|
||||||
|
|
||||||
class CustomAliasForm(FlaskForm):
|
class CustomAliasForm(FlaskForm):
|
||||||
|
@ -31,10 +31,12 @@ def custom_alias():
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
email = form.email.data
|
email = form.email.data
|
||||||
email = convert_to_id(email)
|
email = convert_to_id(email)
|
||||||
if len(email) < 6:
|
email_suffix = request.form.get("email-suffix")
|
||||||
error = "email must be at least 6 letters"
|
|
||||||
|
if len(email) < 3:
|
||||||
|
error = "email must be at least 3 letters"
|
||||||
else:
|
else:
|
||||||
full_email = f"{email}@{EMAIL_DOMAIN}"
|
full_email = f"{email}.{email_suffix}@{EMAIL_DOMAIN}"
|
||||||
# check if email already exists
|
# check if email already exists
|
||||||
if GenEmail.get_by(email=full_email):
|
if GenEmail.get_by(email=full_email):
|
||||||
error = "email already chosen, please choose another one"
|
error = "email already chosen, please choose another one"
|
||||||
|
@ -48,4 +50,11 @@ def custom_alias():
|
||||||
|
|
||||||
return redirect(url_for("dashboard.index"))
|
return redirect(url_for("dashboard.index"))
|
||||||
|
|
||||||
return render_template("dashboard/custom_alias.html", form=form, error=error)
|
email_suffix = random_string(6)
|
||||||
|
return render_template(
|
||||||
|
"dashboard/custom_alias.html",
|
||||||
|
form=form,
|
||||||
|
error=error,
|
||||||
|
email_suffix=email_suffix,
|
||||||
|
EMAIL_DOMAIN=EMAIL_DOMAIN,
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue