Allow deletion of kindle email address and force e-mail address to be valid

This commit is contained in:
Ozzie Isaacs 2022-08-28 15:54:43 +02:00
parent ec8844c7d4
commit 89d226e36b
3 changed files with 17 additions and 9 deletions

View File

@ -1960,8 +1960,11 @@ def _handle_edit_user(to_save, content, languages, translations, kobo_support):
if to_save.get("locale"): if to_save.get("locale"):
content.locale = to_save["locale"] content.locale = to_save["locale"]
try: try:
if to_save.get("email", content.email) != content.email: new_email = check_email(to_save.get("email", content.email))
content.email = check_email(to_save["email"]) if not new_email:
raise Exception(_(u"E-Mail Address can't be empty and has to be a valid E-Mail"))
if new_email != content.email:
content.email = new_email
# Query username, if not existing, change # Query username, if not existing, change
if to_save.get("name", content.name) != content.name: if to_save.get("name", content.name) != content.name:
if to_save.get("name") == "Guest": if to_save.get("name") == "Guest":

View File

@ -654,11 +654,13 @@ def check_username(username):
def valid_email(email): def valid_email(email):
email = email.strip() email = email.strip()
# Regex according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#validation # if email is not deleted
if not re.search(r"^[\w.!#$%&'*+\\/=?^_`{|}~-]+@[\w](?:[\w-]{0,61}[\w])?(?:\.[\w](?:[\w-]{0,61}[\w])?)*$", if email:
email): # Regex according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#validation
log.error(u"Invalid e-mail address format") if not re.search(r"^[\w.!#$%&'*+\\/=?^_`{|}~-]+@[\w](?:[\w-]{0,61}[\w])?(?:\.[\w](?:[\w-]{0,61}[\w])?)*$",
raise Exception(_(u"Invalid e-mail address format")) email):
log.error(u"Invalid e-mail address format")
raise Exception(_(u"Invalid e-mail address format"))
return email return email
# ################################# External interface ################################# # ################################# External interface #################################

View File

@ -1364,8 +1364,11 @@ def change_profile(kobo_support, local_oauth_check, oauth_status, translations,
try: try:
if to_save.get("kindle_mail", current_user.kindle_mail) != current_user.kindle_mail: if to_save.get("kindle_mail", current_user.kindle_mail) != current_user.kindle_mail:
current_user.kindle_mail = valid_email(to_save.get("kindle_mail")) current_user.kindle_mail = valid_email(to_save.get("kindle_mail"))
if to_save.get("email", current_user.email) != current_user.email: new_email = check_email(to_save.get("email", current_user.email))
current_user.email = check_email(to_save.get("email")) if not new_email:
raise Exception(_(u"E-Mail Address can't be empty and has to be a valid E-Mail"))
if new_email != current_user.email:
current_user.email = new_email
if current_user.role_admin(): if current_user.role_admin():
if to_save.get("name", current_user.name) != current_user.name: if to_save.get("name", current_user.name) != current_user.name:
# Query username, if not existing, change # Query username, if not existing, change