Commit 8f8d33e6 authored by Romain Loth's avatar Romain Loth

prevent login when user is registered but didnt validate his registration yet...

prevent login when user is registered but didnt validate his registration yet (+add a message in login modal +better fetch promise unwrapping)
parent 3c918442
...@@ -295,7 +295,19 @@ def login(): ...@@ -295,7 +295,19 @@ def login():
mlog("ERROR", "error in doors_login request") mlog("ERROR", "error in doors_login request")
raise (err) raise (err)
mlog("DEBUG", "doors_login returned id '%s'" % doors_uid) mlog("DEBUG", "doors_login returned doors_uid '%s'" % doors_uid)
if doors_uid is None:
# break: can't doors_login
nologin_message = """<b>The login exists but it was invalid!</b><br/>Perhaps the password was wrong ?<br/>Or perhaps you never checked your mailbox and clicked on the validation link ?"""
if called_as_api:
# menubar login will prevent redirect
return(nologin_message, 404)
else:
return render_template(
"message.html",
message = nologin_message
)
luid = db.doors_uid_to_luid(doors_uid) luid = db.doors_uid_to_luid(doors_uid)
...@@ -325,11 +337,19 @@ def login(): ...@@ -325,11 +337,19 @@ def login():
if not login_ok: if not login_ok:
# break: failed to login_user() # break: failed to login_user()
render_template( notok_message = "There was an unknown problem with the login."
"message.html", if called_as_api:
message = "There was an unknown problem with the login." # menubar login will prevent redirect
) return(nologin_message, 404)
else:
return render_template(
"message.html",
message = notok_message
)
# ========
# OK cases
# ========
if called_as_api: if called_as_api:
# menubar login will do the redirect # menubar login will do the redirect
return('', 204) return('', 204)
...@@ -389,7 +409,7 @@ def profile(): ...@@ -389,7 +409,7 @@ def profile():
mlog("DEBUG", "PROFILE: current_user details: \n - %s" % ( mlog("DEBUG", "PROFILE: current_user details: \n - %s" % (
'\n - '.join([current_user.info['email'], '\n - '.join([current_user.info['email'],
current_user.info['initials'], current_user.info['initials'],
current_user.info['doors_uid'], current_user.info['doors_uid'] if current_user.info['doors_uid'] else "(no doors_uid)" ,
str(current_user.info['keywords']), str(current_user.info['keywords']),
current_user.info['country']] current_user.info['country']]
) )
......
...@@ -72,20 +72,31 @@ var cmxClt = (function(cC) { ...@@ -72,20 +72,31 @@ var cmxClt = (function(cC) {
}) })
// 1st then() over promise // 1st then() over promise
.then(function(response) { .then(function(response) {
// NB unwrapping the promise by consuming the body AND finishing this 1st then() will allow Fetch to complete which allows the cookie to be set // NB 2 promises to unwrap for Fetch to complete which allows the cookie to be set in the OK case
if(response.ok) { if(response.ok) {
// unwraps the promise // unwraps the promise => 2nd then()
return response.text() response.text().then( function(bodyText) {
// cookie should be set now !
console.log("Login was OK, redirecting to profile...")
window.location = '/services/user/profile'
})
} }
else { else {
throw new Error('Network response was not ok.'); // also unwraps the promise => 2nd then()
// (we want to use the bodyText as message)
// cf. github.com/github/fetch/issues/203
response.text().then( function(bodyText) {
console.log("Login failed, aborting and showing message")
formObj.elMainMessage.innerHTML = bodyText
// TODO factorize CSS with old #main_message as a class
formObj.elMainMessage.style.color = cmxClt.colorRed
formObj.elMainMessage.style.fontSize = "150%"
formObj.elMainMessage.style.lineHeight = "130%"
formObj.elMainMessage.style.textAlign = "center"
})
} }
}) })
// 2nd then(): at this point Fetch has completed and cookie is set
.then(function(bodyText) {
// console.log('the login cookie should be set, changing page now')
window.location = '/services/user/profile'
})
.catch(function(error) { .catch(function(error) {
console.warn('fetch error:'+error.message); console.warn('fetch error:'+error.message);
}); });
...@@ -246,6 +257,8 @@ var cmxClt = (function(cC) { ...@@ -246,6 +257,8 @@ var cmxClt = (function(cC) {
${confirmPass} ${confirmPass}
<br/> <br/>
${captchaBlock} ${captchaBlock}
<br/>
<div id="menu_message" class="legend"></div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="cmxClt.elts.box.toggleBox('auth_modal')"> <button type="button" class="btn btn-secondary" onclick="cmxClt.elts.box.toggleBox('auth_modal')">
......
...@@ -23,7 +23,8 @@ var menuUForm = cmxClt.uauth.AuthForm( ...@@ -23,7 +23,8 @@ var menuUForm = cmxClt.uauth.AuthForm(
'duuidId': "doors_uid", 'duuidId': "doors_uid",
'passId': "menu_password", 'passId': "menu_password",
'captchaId': "menu_captcha", 'captchaId': "menu_captcha",
'capcheckId': "menu_captcha_hash"} 'capcheckId': "menu_captcha_hash",
'mainMessageId': "menu_message"}
// NB the dials aka htmlEffectTgtIds are now // NB the dials aka htmlEffectTgtIds are now
// auto-retrieved by their classname // auto-retrieved by their classname
) )
......
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