[Users | Trunk]: finish register service form

This commit is contained in:
Konstantinos Triantafyllou 2020-10-22 09:03:54 +00:00
parent 5d2cc9c427
commit 0fbe93619f
2 changed files with 120 additions and 72 deletions

View File

@ -75,7 +75,7 @@ public class RegisterServiceServlet extends HttpServlet {
String[] schemes = {"https"};
UrlValidator urlValidator = new UrlValidator(schemes);
if (!urlValidator.isValid(jwksUri)){
request.getSession().setAttribute("msg_key_uri_error_display", "display:block");
request.getSession().setAttribute("uri_error", true);
canProceed = false;
}
} else {
@ -86,11 +86,11 @@ public class RegisterServiceServlet extends HttpServlet {
jwks = gson.fromJson(jwksSet, Jwks.class);
if (jwks.getKeys() == null || jwks.getKeys().length == 0) {
System.out.println("Something wrong with the keys.");
request.getSession().setAttribute("msg_key_value_error_display", "display:block");
request.getSession().setAttribute("value_error", true);
canProceed = false;
}
} catch (JsonParseException jpe) {
request.getSession().setAttribute("msg_key_value_error_display", "display:block");
request.getSession().setAttribute("value_error", true);
canProceed = false;
}
}

View File

@ -56,23 +56,22 @@
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
<div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
<span id="server_error" class="uk-text-danger uk-text-small uk-float-left">${message}</span>
<c:remove var="message" scope="session"/>
<h4 class="uk-text-bold uk-text-center">General</h4>
<div class="uk-margin-medium-top">
<label class="uk-form-label uk-text-bold" for="first_name">Name*</label>
<input id="first_name" name="first_name" type="text" placeholder="Name (*)"
class="form-control" value=${first_name}>
<span class="uk-text-danger uk-text-small">
Please enter a name for your service.</span>
<c:remove var="msg_first_name_error_display" scope="session"/>
class="uk-input" onkeyup="validate()" onfocusout="nameTouched = true;validate()" value=${first_name}>
<c:remove var="first_name" scope="session"/>
<div id="first_name_error" style="display:none;" class="uk-text-danger uk-text-small">Please enter a name for your
service.
</div>
</div>
<div class="uk-margin-medium-top">
<label class="uk-form-label uk-text-bold" for="description">Description</label>
<textarea id="description" name="description" type="textarea" placeholder="Description:"
class="form-control uk-textarea" rows="3" value=${description}></textarea>
class="uk-textarea" rows="3" value=${description}></textarea>
<c:remove var="description" scope="session"/>
</div>
<hr class="uk-margin-medium uk-divider">
<h4 class="uk-text-bold uk-text-center">Access</h4>
<div class="uk-margin-medium-top">
<label class="uk-form-label uk-text-bold">Scope</label>
@ -82,7 +81,6 @@
<label class="uk-form-label uk-text-bold">Grant Types</label>
<input disabled value="client credentials" class="uk-input">
</div>
<hr class="uk-margin-medium uk-divider">
<h4 class="uk-text-bold uk-text-center">Credentials</h4>
<div class="uk-margin-medium-top">
<label class="uk-form-label uk-text-bold">Authentication Method</label>
@ -97,28 +95,59 @@
<label class="uk-form-label uk-text-bold">Public Key Set</label>
<span class="uk-float-right">
<span class="uk-margin-small-right">
<input id="by_value" class="uk-radio uk-margin-small-right" type="radio" name="key_radio" value="value" ${(key_radio == 'value' || key_radio == '' || key_radio == null) ? 'checked' : ''}>
<input id="by_value" class="uk-radio uk-margin-small-right" type="radio"
name="key_radio"
value="value" ${(key_radio == 'value' || key_radio == '' || key_radio == null) ? 'checked' : ''}>
<label class="clickable" for="by_value">By Value</label>
</span>
<span>
<input id="by_uri" class="uk-radio uk-margin-small-right" type="radio" name="key_radio" value="uri" ${key_radio == 'uri' ? 'checked' : ''}>
<input id="by_uri" class="uk-radio uk-margin-small-right" type="radio"
name="key_radio" value="uri" ${key_radio == 'uri' ? 'checked' : ''}>
<label class="clickable" for="by_uri">By URI</label>
</span>
</span>
<c:remove var="key_radio" scope="session"/>
<div id="value_input">
<textarea id="value" name="value" type="textarea" placeholder='{"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...}'
class="form-control uk-textarea" rows="10">${value}</textarea>
<span class="uk-text-danger uk-text-small">Please provide a valid JSON.</span>
<textarea id="value" name="value" type="textarea"
placeholder='{"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...}'
onfocusout="valueTouched = true;validate()"
onkeyup="validate()"
class="uk-textarea ${value_error == true?'uk-form-danger':''}" rows="10">${value}</textarea>
<c:choose>
<c:when test="${value_error == true}">
<div id="value_error" class="uk-text-danger uk-text-small">Please provide a valid JSON.</div>
<c:remove var="value_error" scope="session"/>
</c:when>
<c:otherwise>
<div id="value_error" style="display:none;" class="uk-text-danger uk-text-small">Please provide a valid JSON.</div>
</c:otherwise>
</c:choose>
<c:remove var="value" scope="session"/>
</div>
<div id="uri_input" style="display:none;">
<input id="uri" name="uri" type="text" placeholder="https://" class="form-control" value="${jwksUri}">
<span class="uk-text-danger uk-text-small">Please provide a valid URI (do not forget the protocol! https://...)</span>
<input id="uri" name="uri" type="text" placeholder="https://" onfocusout="uriTouched = true;validate()"
onkeyup="validate()"
class="uk-input ${uri_error == true?'uk-form-danger':''}" value="${jwksUri}">
<c:choose>
<c:when test="${uri_error == true}">
<div id="uri_error" class="uk-text-danger uk-text-small">
Please provide a valid URI (do not forget the protocol! https://...)
</div>
<c:remove var="uri_error" scope="session"/>
</c:when>
<c:otherwise>
<div id="uri_error" style="display:none;" class="uk-text-danger uk-text-small">
Please provide a valid URI (do not forget the protocol! https://...)
</div>
</c:otherwise>
</c:choose>
<c:remove var="jwksUri" scope="session"/>
</div>
</div>
<div class="uk-flex uk-flex-right uk-margin-medium-top">
<a type="submit" class="uk-button uk-button-default uk-margin-small-right"
href="./registeredServices">Cancel</a>
<button type="submit" class="uk-button uk-button-primary" onclick="return validate();">
<button id="create" type="submit" class="uk-button uk-button-primary">
Add new service
</button>
</div>
@ -164,81 +193,100 @@
</body>
</html>
<script>
$('input[type=radio][name=key_radio]').change(function () {
if (this.value == 'uri') {
var nameTouched = false;
var valueTouched = false;
var uriTouched = false;
$(document).ready(function () {
checkRadio();
if($('#value_error').is(':visible')) {
$("#value_input").get(0).scrollIntoView();
} else if($('#uri_error').is(':visible')) {
$("#uri_input").get(0).scrollIntoView();
}
$('input[type=radio][name=key_radio]').change(function () {
checkRadio();
});
});
function checkRadio() {
var radio = $('input[type=radio][name=key_radio]:checked').val();
if (radio === 'uri') {
$("#uri_input").show();
$("#value_input").hide();
} else if (this.value == 'value') {
} else if (radio === 'value') {
$("#uri_input").hide();
$("#value_input").show();
}
});
validate();
}
function validate() {
var isValid = false;
if ($("#first_name").val() != undefined) {
if ($.trim($("#first_name").val()).length <= 0) {
$("#first_name").addClass('uk-input aai-form-danger');
$(".msg_first_name_error").show();
return false;
var isValid = true;
var create = $('#create');
create.prop('disabled', true);
var name = $("#first_name");
if (name.val() !== undefined) {
if ($.trim(name.val()).length <= 0) {
if (nameTouched) {
name.addClass('uk-form-danger');
$("#first_name_error").show();
}
isValid = false;
} else {
$(".msg_first_name_error").hide();
$("#first_name").removeClass('aai-form-danger');
if (nameTouched) {
name.removeClass('uk-form-danger');
$("#first_name_error").hide();
}
}
}
if ($('input[type=radio][name=key_radio]:checked').val() === 'value') {
isValid = validateJSON();
if (!isValid) {
$("#value_input").addClass('uk-input aai-form-danger');
$(".msg_key_value_error_display").show();
return false;
var radio = $('input[type=radio][name=key_radio]:checked');
if (radio.val() === 'value') {
if (!validateJSON()) {
if (valueTouched) {
$("#value").addClass('uk-form-danger');
$("#value_error").show();
}
isValid = false;
} else {
if (valueTouched) {
$("#value").removeClass('uk-form-danger');
$("#value_error").hide();
}
}
}
if ($('input[type=radio][name=key_radio]:checked').val() === 'uri') {
isValid = validateURI();
if (!isValid) {
$("#uri_input").addClass('uk-input aai-form-danger');
$(".msg_key_uri_error_display").show();
return false;
if (radio.val() === 'uri') {
if (!validateURI()) {
if (uriTouched) {
$("#uri").addClass('uk-form-danger');
$("#uri_error").show();
}
isValid = false;
} else {
if (uriTouched) {
$("#uri").removeClass('uk-form-danger');
$("#uri_error").hide();
}
}
}
if (isValid) {
create.prop('disabled', false);
}
return isValid;
}
function validateJSON() {
if ($("#value").val() != undefined && $("#value").val() !== "") {
if (/^[\],:{}\s]*$/.test($("#value").val().replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
return true;
} else {
return false;
}
var value = $("#value").val();
if (value !== undefined && value !== "") {
return /^[\],:{}\s]*$/.test(value.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''));
}
return false;
}
function validateURI() {
if ($("#uri").val() != undefined && $("#uri").val() !== "") {
return /^(?:(?:(?:https):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test($("#uri").val());
var value = $("#uri").val();
if (value !== undefined && value !== "") {
return /^(?:(?:(?:https):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value);
}
return false;
}
$("#first_name").focusin(function () {
$(this).removeClass('aai-form-danger');
$(".msg_first_name_error").fadeOut();
});
$("#value_input").focusin(function () {
$(this).removeClass('aai-form-danger');
$(".msg_key_value_error").fadeOut();
});
$("#uri_input").focusin(function () {
$(this).removeClass('aai-form-danger');
$(".msg_key_uri_error").fadeOut();
});
</script>