user can set/remove pgp key
This commit is contained in:
parent
18fbed7d1b
commit
24fd19d6d9
|
@ -52,6 +52,31 @@
|
||||||
</div>
|
</div>
|
||||||
<!-- END Change email -->
|
<!-- END Change email -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Change PGP Public key -->
|
||||||
|
<div class="card">
|
||||||
|
<form method="post">
|
||||||
|
<input type="hidden" name="form-name" value="pgp">
|
||||||
|
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">
|
||||||
|
PGP
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label">PGP Public Key</label>
|
||||||
|
|
||||||
|
<textarea name="pgp" class="form-control" rows=10>{{mailbox.pgp_public_key or ""}}</textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="btn btn-primary" name="action" value="save">Save</button>
|
||||||
|
<button class="btn btn-danger float-right" name="action" value="remove">Remove</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<!-- END PGP Public key -->
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -37,53 +37,77 @@ def mailbox_detail_route(mailbox_id):
|
||||||
else:
|
else:
|
||||||
pending_email = None
|
pending_email = None
|
||||||
|
|
||||||
if change_email_form.validate_on_submit():
|
if request.method == "POST":
|
||||||
new_email = change_email_form.email.data
|
if (
|
||||||
if new_email != mailbox.email and not pending_email:
|
request.form.get("form-name") == "update-email"
|
||||||
# check if this email is not already used
|
and change_email_form.validate_on_submit()
|
||||||
if (
|
):
|
||||||
email_already_used(new_email)
|
new_email = change_email_form.email.data
|
||||||
or GenEmail.get_by(email=new_email)
|
if new_email != mailbox.email and not pending_email:
|
||||||
or DeletedAlias.get_by(email=new_email)
|
# check if this email is not already used
|
||||||
):
|
if (
|
||||||
flash(f"Email {new_email} already used", "error")
|
email_already_used(new_email)
|
||||||
elif not can_be_used_as_personal_email(new_email):
|
or GenEmail.get_by(email=new_email)
|
||||||
flash("You cannot use this email address as your mailbox", "error")
|
or DeletedAlias.get_by(email=new_email)
|
||||||
else:
|
):
|
||||||
mailbox.new_email = new_email
|
flash(f"Email {new_email} already used", "error")
|
||||||
|
elif not can_be_used_as_personal_email(new_email):
|
||||||
|
flash(
|
||||||
|
"You cannot use this email address as your mailbox", "error",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
mailbox.new_email = new_email
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
s = Signer(MAILBOX_SECRET)
|
||||||
|
mailbox_id_signed = s.sign(str(mailbox.id)).decode()
|
||||||
|
verification_url = (
|
||||||
|
URL
|
||||||
|
+ "/dashboard/mailbox/confirm_change"
|
||||||
|
+ f"?mailbox_id={mailbox_id_signed}"
|
||||||
|
)
|
||||||
|
|
||||||
|
send_email(
|
||||||
|
new_email,
|
||||||
|
f"Confirm mailbox change on SimpleLogin",
|
||||||
|
render(
|
||||||
|
"transactional/verify-mailbox-change.txt",
|
||||||
|
user=current_user,
|
||||||
|
link=verification_url,
|
||||||
|
mailbox_email=mailbox.email,
|
||||||
|
mailbox_new_email=new_email,
|
||||||
|
),
|
||||||
|
render(
|
||||||
|
"transactional/verify-mailbox-change.html",
|
||||||
|
user=current_user,
|
||||||
|
link=verification_url,
|
||||||
|
mailbox_email=mailbox.email,
|
||||||
|
mailbox_new_email=new_email,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
flash(
|
||||||
|
f"You are going to receive an email to confirm {new_email}.",
|
||||||
|
"success",
|
||||||
|
)
|
||||||
|
return redirect(
|
||||||
|
url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
|
||||||
|
)
|
||||||
|
elif request.form.get("form-name") == "pgp":
|
||||||
|
if request.form.get("action") == "save":
|
||||||
|
mailbox.pgp_public_key = request.form.get("pgp")
|
||||||
|
# TODO
|
||||||
|
# mailbox.pgp_finger_print = load_public_key(mailbox.pgp_public_key)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
flash("Your PGP public key is saved successfully", "success")
|
||||||
s = Signer(MAILBOX_SECRET)
|
return redirect(
|
||||||
mailbox_id_signed = s.sign(str(mailbox.id)).decode()
|
url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
|
||||||
verification_url = (
|
|
||||||
URL
|
|
||||||
+ "/dashboard/mailbox/confirm_change"
|
|
||||||
+ f"?mailbox_id={mailbox_id_signed}"
|
|
||||||
)
|
|
||||||
|
|
||||||
send_email(
|
|
||||||
new_email,
|
|
||||||
f"Confirm mailbox change on SimpleLogin",
|
|
||||||
render(
|
|
||||||
"transactional/verify-mailbox-change.txt",
|
|
||||||
user=current_user,
|
|
||||||
link=verification_url,
|
|
||||||
mailbox_email=mailbox.email,
|
|
||||||
mailbox_new_email=new_email,
|
|
||||||
),
|
|
||||||
render(
|
|
||||||
"transactional/verify-mailbox-change.html",
|
|
||||||
user=current_user,
|
|
||||||
link=verification_url,
|
|
||||||
mailbox_email=mailbox.email,
|
|
||||||
mailbox_new_email=new_email,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
flash(
|
|
||||||
f"You are going to receive an email to confirm {new_email}.",
|
|
||||||
"success",
|
|
||||||
)
|
)
|
||||||
|
elif request.form.get("action") == "remove":
|
||||||
|
mailbox.pgp_public_key = None
|
||||||
|
mailbox.pgp_finger_print = None
|
||||||
|
db.session.commit()
|
||||||
|
flash("Your PGP public key is removed successfully", "success")
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
|
url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue