Commit 31c21101 by Yvon Kerdoncuff

change password : show errors in browser with explanations

parent f8d6b785
......@@ -35,7 +35,7 @@ class CagetteMember(models.Model):
@staticmethod
def get_new_password_link(data):
link_elts = {}
result = {}
if 'email' in data:
email = data['email'].strip()
validator = validators.EmailValidator()
......@@ -46,9 +46,19 @@ class CagetteMember(models.Model):
m_res = api.search_read('res.partner', cond, ['id'])
if m_res and 'id' in m_res[0]:
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:
link_elts['error'] = ' '.join(e.messages)
return link_elts
result['error'] = 'get_new_password_link error while calling odoo api : ' + str(e)
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
def set_new_password(received_pwd, token):
......
......@@ -419,14 +419,18 @@ def create_from_csv(request):
def ask_for_new_password(request):
succeeded = False
res = {'succeeded': None}
res = {}
try:
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
except Exception as 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
if succeeded is True:
......
......@@ -65,15 +65,11 @@
xhr.onreadystatechange = function() {
//readyState => (0,UNSENT), (1,OPENED), (2, HEADER_RECEIVED), (3, LOADING), (4, DONE)
if (this.readyState == 4) {
if (this.status == 200) {
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.");
} else {
alert("Il n'a pas été possible de générer un mail pour réinitialiser le mot de passe correspondant à cette adresse.");
}
} else {
alert("Une erreur est survenue pendant le traitement de la demande.");
alert("Une erreur est survenue pendant le traitement de la demande : " + response.error);
}
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