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
# cf. doors/application/build.sbt for correct version
ENV SCALA_VERSION 2.11.8
ENV SBT_VERSION 0.13.12
ENV DOORS_COMMIT ef7c5e0
ENV DOORS_COMMIT fca0f79
# Install Scala
## Piping curl directly in tar
......
......@@ -2,7 +2,7 @@
# ==========================
export HOST=localhost
export SQL_HOST=localhost
export SQL_HOST=172.18.0.2
export DOORS_HOST=localhost
export DOORS_PORT=32789
export DOORS_PORT=8989
export DEBUG_FLAG=false
......@@ -62,17 +62,6 @@
/*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 */
.legend {
font-family: Cambria, serif;
......
......@@ -84,6 +84,8 @@ theForm.onblur = beTestedAsYouGo
// done when anything in the form changes
function beTestedAsYouGo() {
console.log("beTestedAsYouGo Go")
basicEmailValidate()
captchaStatus = (captcha.value.length == realCaptchaLength)
......@@ -101,63 +103,87 @@ function beTestedAsYouGo() {
}
// NB if login ok then user exists then not available
// => TODO a route for doors/api/exists
// => resulting bool instead of (resp[0] != null)
function testDoorsUserExists() {
// NB using new route in doors api/userExists
// case true => Ok("""{"status":"login exists"}""")
// case false => Ok("""{"status":"login available"}""")
function testDoorsUserExists(emailValue) {
// /!\ async
callDoors(
[email.value, pass1.value, initialsInput.value],
"userExists",
[emailValue],
function(doorsResp) {
var doorsUid = doorsResp[0]
var doorsMsg = doorsResp[1]
var available = (doorsUid == null)
displayDoorsStatusInLoginBox(available)
},
"user"
var available = (doorsMsg == "login available")
displayDoorsStatusInLoginBox(available, emailValue)
}
)
}
// doors register then submit
function registerDoors() {
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(
[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) {
var doorsUid = doorsResp[0]
var doorsMsg = doorsResp[1]
var available = (doorsUid == null)
displayDoorsStatusInLoginBox(available)
},
"register"
validateSubmit(wholeFormData, doorsResp)
}
)
}
function displayDoorsStatusInLoginBox (available) {
var lastEmailValueCheckedDisplayed = null
var doorsIcon = document.getElementById('doors_ret_icon')
function displayDoorsStatusInLoginBox (available, emailValue) {
if (available) {
doorsMessage.innerHTML = "This ID + password is available !"
doorsMessage.style.color = colorGreen
doorsMessage.title = "This email ID is available !"
doorsIcon.classList.remove('glyphicon-remove')
doorsIcon.classList.remove('glyphicon-question-sign')
doorsIcon.classList.add('glyphicon-ok')
doorsIcon.style.color = colorGreen
}
else {
doorsMessage.innerHTML = "Sorry this ID + password is already taken"
doorsMessage.style.color = colorRed
doorsMessage.title = "Sorry this email ID is already taken"
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 ----------------
* @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
* 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)
* ----------------------------
* ajax success <=> doorsId should be != null except if unknown error
......@@ -178,7 +204,7 @@ function displayDoorsStatusInLoginBox (available) {
* }
* }
*/
function callDoors(data, callback, apiAction) {
function callDoors(apiAction, data, callback) {
// console.warn("=====> CORS <=====")
// console.log("data",data)
......@@ -193,22 +219,27 @@ function callDoors(data, callback, apiAction) {
var nameStr = data[2]
// test params and set defaults
if (typeof apiAction == 'undefined' || apiAction != 'register') {
// currently forces login action unless we got 'register'
if (typeof apiAction == 'undefined'
|| (apiAction != 'register' && apiAction != 'userExists')) {
// currently forces login action unless we got 'register' or userExists
apiAction = 'user'
console.warn('DBG: forcing user route')
}
if (typeof callback != 'function') {
callback = function(retval) { return retval }
}
var ok = (typeof mailStr != 'undefined'
&& typeof mailStr != 'undefined'
&& typeof nameStr != 'undefined'
&& mailStr && passStr) // assumes mail and pass will nvr be == 0
console.log("mailStr",mailStr)
var ok = ((apiAction == 'userExists' && typeof mailStr != 'undefined' && mailStr)
|| (typeof mailStr != 'undefined'
&& typeof mailStr != 'undefined'
&& typeof nameStr != 'undefined'
&& mailStr && passStr)) // assumes mail and pass will nvr be == 0
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 {
$.ajax({
......@@ -223,15 +254,20 @@ function callDoors(data, callback, apiAction) {
type: 'POST',
success: function(data) {
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.id != undefined
&& typeof data.userInfo.id.id != undefined
&& typeof data.status == 'string') {
// main success case
// main success case: get the id
doorsUid = data.userInfo.id.id
doorsMsg = data.status
}
else {
doorsMsg = "Unknown response for doors apiAction (" + apiAction +"):"
doorsMsg += '"' + JSON.stringify(data).substring(0,10) + '..."'
......@@ -286,35 +322,6 @@ function makeRandomString(nChars) {
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
//
// => validate the columns
......@@ -573,7 +580,27 @@ nameInputs.forEach ( function(nameInput) {
// very basic email validation TODO: better extension and allowed chars set :)
// (used in tests "as we go")
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?
......
......@@ -150,10 +150,21 @@
<div class="question">
<p class="legend">Your email will also be your login for the ISC services.</p>
<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>
<input id="email" name="email" maxlength="255"
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>
......@@ -175,17 +186,6 @@
<p id="password_message" class="legend red" style="font-weight:bold"></p>
</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 -->
<h3 class="formcat"> About your job and research </h3>
......@@ -399,12 +399,15 @@
<!-- FOR DEBUG: test go-between with Doors -->
<!-- <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
</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
</button>
<button type=button onclick='callDoors("userExists", [email.value, null, null], console.warn)'>
test doors userExists
</button>
</p> -->
</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