Commit ffcc487f authored by Romain Loth's avatar Romain Loth

email validation now also checks if user exists in doors

parent 497c84d8
...@@ -8,7 +8,7 @@ FROM java:8 ...@@ -8,7 +8,7 @@ FROM java:8
# cf. doors/application/build.sbt for correct version # cf. doors/application/build.sbt for correct version
ENV SCALA_VERSION 2.11.8 ENV SCALA_VERSION 2.11.8
ENV SBT_VERSION 0.13.12 ENV SBT_VERSION 0.13.12
ENV DOORS_COMMIT ef7c5e0 ENV DOORS_COMMIT fca0f79
# Install Scala # Install Scala
## Piping curl directly in tar ## Piping curl directly in tar
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# ========================== # ==========================
export HOST=localhost export HOST=localhost
export SQL_HOST=localhost export SQL_HOST=172.18.0.2
export DOORS_HOST=localhost export DOORS_HOST=localhost
export DOORS_PORT=32789 export DOORS_PORT=8989
export DEBUG_FLAG=false export DEBUG_FLAG=false
...@@ -62,17 +62,6 @@ ...@@ -62,17 +62,6 @@
/*color: #554 ;*/ /*color: #554 ;*/
} }
/* the doors status message (a special legend) */
#doors_ret_message {
font-size: 150%;
text-align:center;
color: #554 ;
display:none;
/*padding: .5em 0 .5em .5em ;*/
padding: 0;
}
/* the question's additional legend or caption */ /* the question's additional legend or caption */
.legend { .legend {
font-family: Cambria, serif; font-family: Cambria, serif;
......
...@@ -84,6 +84,8 @@ theForm.onblur = beTestedAsYouGo ...@@ -84,6 +84,8 @@ theForm.onblur = beTestedAsYouGo
// done when anything in the form changes // done when anything in the form changes
function beTestedAsYouGo() { function beTestedAsYouGo() {
console.log("beTestedAsYouGo Go")
basicEmailValidate() basicEmailValidate()
captchaStatus = (captcha.value.length == realCaptchaLength) captchaStatus = (captcha.value.length == realCaptchaLength)
...@@ -101,63 +103,87 @@ function beTestedAsYouGo() { ...@@ -101,63 +103,87 @@ function beTestedAsYouGo() {
} }
// NB if login ok then user exists then not available // NB using new route in doors api/userExists
// => TODO a route for doors/api/exists // case true => Ok("""{"status":"login exists"}""")
// => resulting bool instead of (resp[0] != null) // case false => Ok("""{"status":"login available"}""")
function testDoorsUserExists() { function testDoorsUserExists(emailValue) {
// /!\ async // /!\ async
callDoors( callDoors(
[email.value, pass1.value, initialsInput.value], "userExists",
[emailValue],
function(doorsResp) { function(doorsResp) {
var doorsUid = doorsResp[0] var doorsUid = doorsResp[0]
var doorsMsg = doorsResp[1] var doorsMsg = doorsResp[1]
var available = (doorsUid == null) var available = (doorsMsg == "login available")
displayDoorsStatusInLoginBox(available) displayDoorsStatusInLoginBox(available, emailValue)
}, }
"user"
) )
} }
// doors register then submit function registerDoorsAndSubmit(e){
function registerDoors() { e.preventDefault() // ? not necessary if button type is set and != "submit"
submitButton.disabled = true
mainMessage.style.display = 'block'
mainMessage.innerHTML = "Registering with ISCPIF Doors..."
// objectify the form
wholeFormData = new FormData(theForm);
// KNOCKING ON THE DOORS -------------------------------------
// /!\ async // /!\ async
callDoors( callDoors(
[email.value, pass1.value, initialsInput.value], "register",
[
// these values from the form have been checked by beTestedAsYouGo
wholeFormData.get("email"),
wholeFormData.get("password"),
wholeFormData.get("initials")
],
// VALIDATING + send to DB -------------------
function(doorsResp) { function(doorsResp) {
var doorsUid = doorsResp[0] validateSubmit(wholeFormData, doorsResp)
var doorsMsg = doorsResp[1] }
var available = (doorsUid == null)
displayDoorsStatusInLoginBox(available)
},
"register"
) )
} }
function displayDoorsStatusInLoginBox (available) { var lastEmailValueCheckedDisplayed = null
var doorsIcon = document.getElementById('doors_ret_icon')
function displayDoorsStatusInLoginBox (available, emailValue) {
if (available) { if (available) {
doorsMessage.innerHTML = "This ID + password is available !" doorsMessage.title = "This email ID is available !"
doorsMessage.style.color = colorGreen doorsIcon.classList.remove('glyphicon-remove')
doorsIcon.classList.remove('glyphicon-question-sign')
doorsIcon.classList.add('glyphicon-ok')
doorsIcon.style.color = colorGreen
} }
else { else {
doorsMessage.innerHTML = "Sorry this ID + password is already taken" doorsMessage.title = "Sorry this email ID is already taken"
doorsMessage.style.color = colorRed doorsIcon.classList.remove('glyphicon-ok')
doorsIcon.classList.remove('glyphicon-question-sign')
doorsIcon.classList.add('glyphicon-remove')
doorsIcon.style.color = colorRed
} }
doorsMessage.style.display = 'block'
// to debounce further actions in basicEmailValidate
// return to neutral is also in basicEmailValidate
lastEmailValueCheckedDisplayed = emailValue
} }
/* --------------- doors ajax cors function ---------------- /* --------------- doors ajax cors function ----------------
* @args: * @args:
* data: 3-uple with mail, pass, name * apiAction: 'register' or 'user' or 'userExists' => route to doors api
* if unknown type, default action is login via doors/api/user
* *
* data: 3-uple with mail, pass, name
* *
* callback: function that will be called after success AND after error * callback: function that will be called after success AND after error
* with the return couple * with the return couple
* *
* apiAction: 'register' or 'user' => route to doors api
* [optional] default action is login via doors/api/user route
*
* returns couple (id, message) * returns couple (id, message)
* ---------------------------- * ----------------------------
* ajax success <=> doorsId should be != null except if unknown error * ajax success <=> doorsId should be != null except if unknown error
...@@ -178,7 +204,7 @@ function displayDoorsStatusInLoginBox (available) { ...@@ -178,7 +204,7 @@ function displayDoorsStatusInLoginBox (available) {
* } * }
* } * }
*/ */
function callDoors(data, callback, apiAction) { function callDoors(apiAction, data, callback) {
// console.warn("=====> CORS <=====") // console.warn("=====> CORS <=====")
// console.log("data",data) // console.log("data",data)
...@@ -193,22 +219,27 @@ function callDoors(data, callback, apiAction) { ...@@ -193,22 +219,27 @@ function callDoors(data, callback, apiAction) {
var nameStr = data[2] var nameStr = data[2]
// test params and set defaults // test params and set defaults
if (typeof apiAction == 'undefined' || apiAction != 'register') { if (typeof apiAction == 'undefined'
// currently forces login action unless we got 'register' || (apiAction != 'register' && apiAction != 'userExists')) {
// currently forces login action unless we got 'register' or userExists
apiAction = 'user' apiAction = 'user'
console.warn('DBG: forcing user route')
} }
if (typeof callback != 'function') { if (typeof callback != 'function') {
callback = function(retval) { return retval } callback = function(retval) { return retval }
} }
var ok = (typeof mailStr != 'undefined' console.log("mailStr",mailStr)
&& typeof mailStr != 'undefined' var ok = ((apiAction == 'userExists' && typeof mailStr != 'undefined' && mailStr)
&& typeof nameStr != 'undefined' || (typeof mailStr != 'undefined'
&& mailStr && passStr) // assumes mail and pass will nvr be == 0 && typeof mailStr != 'undefined'
&& typeof nameStr != 'undefined'
&& mailStr && passStr)) // assumes mail and pass will nvr be == 0
if (!ok) { if (!ok) {
doorsMsg = "Invalid parameters in input data (arg #2)" doorsMsg = "Invalid parameters in input data (arg #1)"
console.warn('DEBUG callDoors() internal validation failed before ajax')
} }
else { else {
$.ajax({ $.ajax({
...@@ -223,15 +254,20 @@ function callDoors(data, callback, apiAction) { ...@@ -223,15 +254,20 @@ function callDoors(data, callback, apiAction) {
type: 'POST', type: 'POST',
success: function(data) { success: function(data) {
if (typeof data != 'undefined' if (typeof data != 'undefined'
&& apiAction == 'userExists') {
// userExists success case: it's all in the message :)
doorsUid = null
doorsMsg = data.status
}
else if (typeof data != 'undefined'
&& typeof data.userInfo != undefined && typeof data.userInfo != undefined
&& typeof data.userInfo.id != undefined && typeof data.userInfo.id != undefined
&& typeof data.userInfo.id.id != undefined && typeof data.userInfo.id.id != undefined
&& typeof data.status == 'string') { && typeof data.status == 'string') {
// main success case // main success case: get the id
doorsUid = data.userInfo.id.id doorsUid = data.userInfo.id.id
doorsMsg = data.status doorsMsg = data.status
} }
else { else {
doorsMsg = "Unknown response for doors apiAction (" + apiAction +"):" doorsMsg = "Unknown response for doors apiAction (" + apiAction +"):"
doorsMsg += '"' + JSON.stringify(data).substring(0,10) + '..."' doorsMsg += '"' + JSON.stringify(data).substring(0,10) + '..."'
...@@ -286,35 +322,6 @@ function makeRandomString(nChars) { ...@@ -286,35 +322,6 @@ function makeRandomString(nChars) {
return rando return rando
} }
function registerDoorsAndSubmit(e){
e.preventDefault() // ? not necessary if button type is set and != "submit"
submitButton.disabled = true
mainMessage.style.display = 'block'
mainMessage.innerHTML = "Registering with ISCPIF Doors..."
// objectify the form
wholeFormData = new FormData(theForm);
// KNOCKING ON THE DOORS -------------------------------------
// /!\ async
callDoors(
[
// these values from the form have been checked by beTestedAsYouGo
wholeFormData.get("email"),
wholeFormData.get("password"),
wholeFormData.get("initials")
],
// VALIDATING + send to DB -------------------
function(doorsResp) {
validateSubmit(wholeFormData, doorsResp)
},
"register"
)
}
// doValidate() : actions to do after doors registration and before send // doValidate() : actions to do after doors registration and before send
// //
// => validate the columns // => validate the columns
...@@ -573,7 +580,27 @@ nameInputs.forEach ( function(nameInput) { ...@@ -573,7 +580,27 @@ nameInputs.forEach ( function(nameInput) {
// very basic email validation TODO: better extension and allowed chars set :) // very basic email validation TODO: better extension and allowed chars set :)
// (used in tests "as we go") // (used in tests "as we go")
function basicEmailValidate () { function basicEmailValidate () {
emailStatus = /^[-A-z0-9_=.+]+@[-A-z0-9_=.+]+\.[-A-z0-9_=.+]{1,4}$/.test(email.value)
var newValue = email.value
// tests if email is well-formed
emailStatus = /^[-A-z0-9_=.+]+@[-A-z0-9_=.+]+\.[-A-z0-9_=.+]{1,4}$/.test(newValue)
console.log("basicEmailValidate: emailStatus", emailStatus)
if (! emailStatus) {
// restore original lack of message
doorsMessage.title = 'The email will be checked in our DB after you type and leave the box.'
doorsIcon.classList.remove('glyphicon-remove')
doorsIcon.classList.remove('glyphicon-ok')
doorsIcon.classList.add('glyphicon-question-sign')
doorsIcon.style.color = colorGrey
}
else if (emailStatus && (newValue != lastEmailValueCheckedDisplayed)) {
// additional ajax to check login availability
// doesn't change the boolean but displays a message
testDoorsUserExists(newValue)
}
} }
// pass 1 and pass 2 ~~~> do they match? // pass 1 and pass 2 ~~~> do they match?
......
...@@ -150,10 +150,21 @@ ...@@ -150,10 +150,21 @@
<div class="question"> <div class="question">
<p class="legend">Your email will also be your login for the ISC services.</p> <p class="legend">Your email will also be your login for the ISC services.</p>
<div class="input-group"> <div class="input-group">
<!-- TODO email validation onblur/onchange if value --> <!-- email validation onblur/onchange
is done by basicEmailValidate
and testDoorsUserExists
in comex_reg_form_controllers.js -->
<label for="email" class="smlabel input-group-addon">* Email</label> <label for="email" class="smlabel input-group-addon">* Email</label>
<input id="email" name="email" maxlength="255" <input id="email" name="email" maxlength="255"
type="text" class="form-control" placeholder="email"> type="text" class="form-control" placeholder="email">
<!-- doors return value icon -->
<div id="doors_ret_message" class="input-group-addon"
title="The email will be checked in our DB after you type and leave the box.">
<span id="doors_ret_icon"
class="glyphicon glyphicon-question-sign grey"
></span>
</div>
</div> </div>
</div> </div>
...@@ -175,17 +186,6 @@ ...@@ -175,17 +186,6 @@
<p id="password_message" class="legend red" style="font-weight:bold"></p> <p id="password_message" class="legend red" style="font-weight:bold"></p>
</div> </div>
<button type=button class="btn btn-sm btn-default" style="float:right"
id="knock_on_doors"
onclick="testDoorsUserExists()">
Check login availability at ISCPIF Doors
</button>
<!-- doors return value message -->
<p id="doors_ret_message" class="legend"></p>
<!-- JOB & INTERESTS --> <!-- JOB & INTERESTS -->
<h3 class="formcat"> About your job and research </h3> <h3 class="formcat"> About your job and research </h3>
...@@ -399,12 +399,15 @@ ...@@ -399,12 +399,15 @@
<!-- FOR DEBUG: test go-between with Doors --> <!-- FOR DEBUG: test go-between with Doors -->
<!-- <p> <!-- <p>
<button type=button onclick='callDoors([email.value, pass1.value, initialsInput.value], console.warn, "user")'> <button type=button onclick='callDoors("user", [email.value, pass1.value, initialsInput.value], console.warn)'>
test doors login test doors login
</button> </button>
<button type=button onclick='callDoors([email.value, pass1.value, initialsInput.value], "register", console.warn)'> <button type=button onclick='callDoors("register", [email.value, pass1.value, initialsInput.value], console.warn)'>
test doors register test doors register
</button> </button>
<button type=button onclick='callDoors("userExists", [email.value, null, null], console.warn)'>
test doors userExists
</button>
</p> --> </p> -->
</div> </div>
......
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