Project

General

Profile

1
<%--
2
  Created by IntelliJ IDEA.
3
  User: sofia
4
  Date: 19/10/2017
5
  Time: 4:30 μμ
6
  To change this template use File | Settings | File Templates.
7
--%>
8
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
9
<!DOCTYPE html>
10
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
11
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
12
<head>
13
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
14
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
15
    <meta name="viewport" content="width=device-width, initial-scale=1">
16
    <base href=".">
17
    <title>OpenAIRE - Register</title>
18
    <script src="./js/jquery.js"></script>
19
    <script src="./js/uikit.min.js"></script>
20
    <script src="./js/uikit-icons-max.js"></script>
21
    <link rel="stylesheet" style="text/css" href="./css/theme.css">
22
    <link rel="stylesheet" style="text/css" href="./css/custom.css">
23
    <link rel="stylesheet" style="text/css" href="./css/aai-custom.css">
24
    <link rel="icon" type="image/png" sizes="32x32" href="images/favicon/favicon-32x32.png">
25
    <link rel="icon" type="image/png" sizes="96x96" href="images/favicon//favicon-96x96.png">
26
    <link rel="icon" type="image/png" sizes="16x16" href="images/favicon/favicon-16x16.png">
27
    <link href="images/favicon/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon"/>
28
</head>
29
<body class="" style="">
30
<div class="uk-offcanvas-content uk-height-viewport">
31
    <jsp:include page="header.jsp"/>
32
    <!-- CONTENT STARTS HERE -->
33
    <div class=" uk-section  uk-margin-small-top uk-container uk-container-large" id="tm-main">
34
        <div class="uk-grid ">
35
            <div class="uk-width-1-4@m">
36
                <div class="uk-card uk-card-default uk-card-body">
37
                    <div class="uk-h4">API Access</div>
38
                    <ul class="uk-nav uk-nav-default">
39
                        <li class=""><a href="./personalToken">Personal token</a></li>
40
                        <li class=""><a href="./registeredServices">Registered services</a></li>
41
                    </ul>
42
                </div>
43
            </div>
44
            <!-- CENTER SIDE -->
45
            <div class="uk-width-2-3@l uk-width-2-3@m">
46
                <c:choose>
47
                    <c:when test="${not empty param.id}">
48
                        <h4 class="uk-margin-remove-top uk-text-bold uk-text-primary">Edit service</h4>
49
                    </c:when>
50
                    <c:otherwise>
51
                      <h4 class="uk-margin-remove-top uk-text-bold uk-text-primary">Add a new service</h4>
52
                    </c:otherwise>
53
                </c:choose>
54

    
55
                <!-- REGISTER FORM -->
56
                <div id="registerForm">
57
                    <form action="registerService" method="POST" role="form" class="m-t uk-form-horizontal"
58
                          id="register_form">
59
                          <input type="hidden" name="id" value="${param.id}"/>
60
                        <c:choose>
61
                            <c:when test = "${not empty param.id}">
62
                                <input type="hidden" name="mode" value="edit"/>
63
                            </c:when>
64
                            <c:otherwise>
65
                              <input type="hidden" name="mode" value="create"/>
66
                            </c:otherwise>
67
                        </c:choose>
68
                        <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
69
                        <div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
70
                        <div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
71
                        <div class="uk-margin-medium-top">
72
                            <label class="uk-form-label uk-text-bold" for="first_name">Name*</label>
73
                            <div class="uk-margin-small">Give a name to your service</div>
74
                            <input id="first_name" name="first_name" type="text" placeholder="Name (*)"
75
                                   class="uk-input ${first_name_error == true?'uk-form-danger':''}"
76
                                   onkeyup="validate()" onfocusout="nameTouched = true;validate()" value="${(first_name != null)?first_name:''}">
77
                            <c:choose>
78
                                <c:when test="${first_name_error == true}">
79
                                    <div id="first_name_error" class="uk-text-danger uk-text-small">Please enter a name for your service.
80
                                    </div>
81
                                </c:when>
82
                                <c:otherwise>
83
                                <div id="first_name_error" style="display:none;" class="uk-text-danger uk-text-small">Please enter a name for your service.</div>
84
                                </c:otherwise>
85
                            </c:choose>
86
                            <c:remove var="first_name" scope="session"/>
87
                            <c:remove var="first_name_error" scope="session"/>
88
                        </div>
89
                        <div class="uk-margin-medium-top">
90
                            <label class="uk-form-label uk-text-bold">Security level</label>
91
                            <div id="security-hint" class="uk-margin"></div>
92
                            <div class="uk-margin-small-top">
93
                                <span class="uk-margin-small-right">
94
                                    <input id="basic" class="uk-radio uk-margin-small-right" type="radio"
95
                                           name="security_level"
96
                                           value="basic" ${key_type == null ? 'checked' : ''}>
97
                                    <label class="clickable" for="by_value">Basic</label>
98
                                </span>
99
                                <span>
100
                                    <input id="advanced" class="uk-radio uk-margin-small-right" type="radio"
101
                                           name="security_level" value="advanced"  ${key_type != null ? 'checked' : ''}>
102
                                    <label class="clickable" for="by_uri">Advanced</label>
103
                                </span>
104
                            </div>
105
                        </div>
106
                        <div id="public-key" class="uk-margin-medium-top">
107
                            <label class="uk-form-label uk-text-bold">Public Key</label>
108
                            <span class="uk-float-right">
109
                                <span class="uk-margin-small-right">
110
                                    <input id="by_value" class="uk-radio uk-margin-small-right" type="radio"
111
                                           name="key_type"
112
                                           value="value" ${(key_type == 'value') ? 'checked' : ''}>
113
                                    <label class="clickable" for="by_value">By Value</label>
114
                                </span>
115
                                <span>
116
                                    <input id="by_uri" class="uk-radio uk-margin-small-right" type="radio"
117
                                           name="key_type"
118
                                           value="uri" ${key_type == 'uri' ? 'checked' : ''}>
119
                                    <label class="clickable" for="by_uri">By URI</label>
120
                                </span>
121
                            </span>
122
                            <c:remove var="key_type" scope="session"/>
123
                            <div class="uk-margin">Public Key hint</div>
124
                            <div id="value_input">
125
                                <textarea id="value" name="value" type="textarea"
126
                                          placeholder='{"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...}'
127
                                          onfocusout="valueTouched = true;validate()"
128
                                          onkeyup="validate()"
129
                                          class="uk-textarea ${value_error == true?'uk-form-danger':''}" rows="10">${(value != null)?value:''}</textarea>
130
                                <c:choose>
131
                                    <c:when test="${value_error == true}">
132
                                        <div id="value_error" class="uk-text-danger uk-text-small">Please provide a valid JSON. The format should be
133
                                            {"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...} </div>
134
                                        <c:remove var="value_error" scope="session"/>
135
                                    </c:when>
136
                                    <c:otherwise>
137
                                        <div id="value_error" style="display:none;" class="uk-text-danger uk-text-small">Please provide a valid JSON. The format should be
138
                                        {"kty": ..., "e": ... , "use": ... , "kid": ..., "alg": ... , "n": ...} </div>
139
                                    </c:otherwise>
140
                                </c:choose>
141
                                <c:remove var="value" scope="session"/>
142
                            </div>
143
                            <div id="uri_input" style="display:none;">
144
                                <input id="uri" name="uri" type="text" placeholder="https://" onfocusout="uriTouched = true;validate()"
145
                                       onkeyup="validate()"
146
                                       class="uk-input ${uri_error == true?'uk-form-danger':''}" value="${(jwksUri != null)?jwksUri:''}">
147
                                <c:choose>
148
                                    <c:when test="${uri_error == true}">
149
                                        <div id="uri_error"  class="uk-text-danger uk-text-small">
150
                                            Please provide a valid URI (do not forget the protocol! https://...)
151
                                        </div>
152
                                        <c:remove var="uri_error" scope="session"/>
153
                                    </c:when>
154
                                    <c:otherwise>
155
                                        <div id="uri_error" style="display:none;" class="uk-text-danger uk-text-small">
156
                                            Please provide a valid URI (do not forget the protocol! https://...)
157
                                        </div>
158
                                    </c:otherwise>
159
                                </c:choose>
160
                                <c:remove var="jwksUri" scope="session"/>
161
                            </div>
162
                        </div>
163
                        <div class="uk-flex uk-flex-right uk-margin-medium-top">
164
                            <a type="submit" class="uk-button uk-button-default uk-margin-small-right"
165
                               href="./registeredServices">Cancel</a>
166
                            <button id="create" type="submit" class="uk-button uk-button-primary" onclick="return validate();">
167
                                <c:choose>
168
                                    <c:when test="${not empty param.id}">
169
                                        Update service
170
                                    </c:when>
171
                                    <c:otherwise>
172
                                        Add new service
173
                                    </c:otherwise>
174
                                </c:choose>
175
                            </button>
176
                        </div>
177
                    </form>
178
                </div>
179
                <!-- END OF REGISTER FORM -->
180
                </ul>
181
            </div>
182
            <!-- END OF CENTER SIDE -->
183
        </div>
184
    </div>
185
    <!-- CONTENT ENDS HERE -->
186
    <c:import url="footer.jsp"/>
187
</div>
188
</body>
189
</html>
190
<script>
191
    var nameTouched = false;
192
    var valueTouched = false;
193
    var uriTouched = false;
194
    $(document).ready(function () {
195
        checkRadio();
196
        if($('input[name=mode]').val() === 'edit') {
197
            $("#basic").prop("disabled", true);
198
            $("#advanced").prop("disabled", true);
199
        }
200
        if($('#value_error').is(':visible')) {
201
            $("#value_input").get(0).scrollIntoView();
202
        } else if($('#uri_error').is(':visible')) {
203
            $("#uri_input").get(0).scrollIntoView();
204
        }
205
        $('input[type=radio][name=security_level]').change(function () {
206
            var securityLevel = $('input[type=radio][name=security_level]:checked').val();
207
            if(securityLevel === 'advanced') {
208
                $("#by_value").prop("checked", true);
209
            } else {
210
                $("#by_value").prop("checked", false);
211
                $("#by_uri").prop("checked", false);
212
            }
213
            checkRadio();
214
        });
215
        $('input[type=radio][name=key_type]').change(function () {
216
            checkRadio();
217
        });
218
    });
219

    
220
    function checkRadio() {
221
        var securityLevel = $('input[type=radio][name=security_level]:checked').val();
222
        if(securityLevel === 'basic') {
223
            $("#security-hint").html('Basic Security level hint');
224
            $("#public-key").hide();
225
        } else {
226
            $("#security-hint").html('Advanced Security level hint');
227
            var keyType = $('input[type=radio][name=key_type]:checked').val();
228
            $("#public-key").show();
229
            if (keyType === 'uri') {
230
                $("#uri_input").show();
231
                $("#value_input").hide();
232
            } else if (keyType === 'value') {
233
                $("#uri_input").hide();
234
                $("#value_input").show();
235
            }
236
        }
237
        validate();
238
    }
239

    
240
    function validate() {
241
        var isValid = true;
242
        var create = $('#create');
243
        create.prop('disabled', true);
244
        var name = $("#first_name");
245

    
246
        if (name.val() !== undefined) {
247
            if ($.trim(name.val()).length <= 0) {
248
                if (nameTouched) {
249
                    name.addClass('uk-form-danger');
250
                    $("#first_name_error").show();
251
                }
252
                isValid = false;
253
            } else {
254
                if (nameTouched) {
255
                    name.removeClass('uk-form-danger');
256
                    $("#first_name_error").hide();
257
                }
258
            }
259
        }
260
        var securityLevel = $('input[type=radio][name=security_level]:checked').val();
261
        if(securityLevel === 'advanced') {
262
            var keyType = $('input[type=radio][name=key_type]:checked');
263
            if (keyType.val() === 'value') {
264
                if (!validateJSON()) {
265
                    if (valueTouched) {
266
                        $("#value").addClass('uk-form-danger');
267
                        $("#value_error").show();
268
                    }
269
                    isValid = false;
270
                } else {
271
                    if (valueTouched) {
272
                        $("#value").removeClass('uk-form-danger');
273
                        $("#value_error").hide();
274
                    }
275
                }
276
            }
277
            if (keyType.val() === 'uri') {
278
                if (!validateURI()) {
279
                    if (uriTouched) {
280
                        $("#uri").addClass('uk-form-danger');
281
                        $("#uri_error").show();
282
                    }
283
                    isValid = false;
284
                } else {
285
                    if (uriTouched) {
286
                        $("#uri").removeClass('uk-form-danger');
287
                        $("#uri_error").hide();
288
                    }
289
                }
290
            }
291
        }
292

    
293
        if (isValid) {
294
            create.prop('disabled', false);
295
        }
296
        return isValid;
297
    }
298

    
299
    function validateJSON() {
300
        var value = $("#value").val();
301
        if (value !== undefined && value !== "") {
302
            return /^[\],:{}\s]*$/.test(value.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''));
303
        }
304
        return false;
305
    }
306

    
307
    function validateURI() {
308
        var value = $("#uri").val();
309
        if (value !== undefined && value !== "") {
310
            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);
311
        }
312
        return false;
313
    }
314
</script>
(15-15/27)