Commit 31c21101 by Yvon Kerdoncuff

change password : show errors in browser with explanations

parent f8d6b785
...@@ -35,7 +35,7 @@ class CagetteMember(models.Model): ...@@ -35,7 +35,7 @@ class CagetteMember(models.Model):
@staticmethod @staticmethod
def get_new_password_link(data): def get_new_password_link(data):
link_elts = {} result = {}
if 'email' in data: if 'email' in data:
email = data['email'].strip() email = data['email'].strip()
validator = validators.EmailValidator() validator = validators.EmailValidator()
...@@ -46,9 +46,19 @@ class CagetteMember(models.Model): ...@@ -46,9 +46,19 @@ class CagetteMember(models.Model):
m_res = api.search_read('res.partner', cond, ['id']) m_res = api.search_read('res.partner', cond, ['id'])
if m_res and 'id' in m_res[0]: if m_res and 'id' in m_res[0]:
res = api.execute('res.partner', 'send_new_password_email', [m_res[0]['id']]) res = api.execute('res.partner', 'send_new_password_email', [m_res[0]['id']])
if 'error' in res:
result['error'] = res['error']
else:
result['error'] = 'get_new_password_link django error : res_partner not found'
except Exception as e: except Exception as e:
link_elts['error'] = ' '.join(e.messages) result['error'] = 'get_new_password_link error while calling odoo api : ' + str(e)
return link_elts if "Only users with the following access level are currently allowed to do that" in str(e):
result['error'] += (" Il s'agit peut-être d'un problème de permissions de l'utilisateur api : "
"donnez lui le droit Administration/Settings (Configuration en français)")
else:
result['error'] = 'get_new_password_link django error : no email in data'
return result
@staticmethod @staticmethod
def set_new_password(received_pwd, token): def set_new_password(received_pwd, token):
......
...@@ -419,14 +419,18 @@ def create_from_csv(request): ...@@ -419,14 +419,18 @@ def create_from_csv(request):
def ask_for_new_password(request): def ask_for_new_password(request):
succeeded = False succeeded = False
res = {'succeeded': None} res = {}
try: try:
data = json.loads(request.body.decode()) data = json.loads(request.body.decode())
CagetteMember.get_new_password_link(data) result = CagetteMember.get_new_password_link(data)
if 'error' in result:
res['error'] = result['error']
else:
succeeded = True succeeded = True
except Exception as e: except Exception as e:
coop_logger.error("ask_for_new_password : %s", str(e)) coop_logger.error("ask_for_new_password : %s", str(e))
res['error'] = str(e) res['error'] = 'ask_for_new_password django error : ' + str(e)
res['succeeded'] = succeeded res['succeeded'] = succeeded
if succeeded is True: if succeeded is True:
......
...@@ -65,15 +65,11 @@ ...@@ -65,15 +65,11 @@
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
//readyState => (0,UNSENT), (1,OPENED), (2, HEADER_RECEIVED), (3, LOADING), (4, DONE) //readyState => (0,UNSENT), (1,OPENED), (2, HEADER_RECEIVED), (3, LOADING), (4, DONE)
if (this.readyState == 4) { if (this.readyState == 4) {
if (this.status == 200) {
const response = JSON.parse(xhr.response); const response = JSON.parse(xhr.response);
if (response.succeeded === true) { if (this.status == 200 && response.succeeded === true) {
alert("Un email vient de vous être envoyé à l'adresse indiquée pour réinitialiser le mot de passe."); alert("Un email vient de vous être envoyé à l'adresse indiquée pour réinitialiser le mot de passe.");
} else { } else {
alert("Il n'a pas été possible de générer un mail pour réinitialiser le mot de passe correspondant à cette adresse."); alert("Une erreur est survenue pendant le traitement de la demande : " + response.error);
}
} else {
alert("Une erreur est survenue pendant le traitement de la demande.");
} }
ask_pwd_span.textContent = "Changer de mot de passe"; ask_pwd_span.textContent = "Changer de mot de passe";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment