From aaa5c732eb7094e1bd832ffc27f3d7ffd86e1f90 Mon Sep 17 00:00:00 2001 From: s71221 Date: Mon, 19 Sep 2016 09:30:50 +0800 Subject: added auth UI code Change-Id: If62a7efbce05451384e34155a25bfdf879da3387 Signed-off-by: s71221 --- openo-portal/portal-auth/pom.xml | 32 +++ .../src/main/webapp/user/changePassword.html | 125 +++++++++++ .../src/main/webapp/user/createUser.html | 141 ++++++++++++ .../src/main/webapp/user/css/component.css | 247 +++++++++++++++++++++ .../portal-auth/src/main/webapp/user/css/user.css | 95 ++++++++ .../src/main/webapp/user/images/add.png | Bin 0 -> 1104 bytes .../src/main/webapp/user/images/delete.png | Bin 0 -> 1100 bytes .../src/main/webapp/user/images/edit.bak.png | Bin 0 -> 3045 bytes .../src/main/webapp/user/images/edit.png | Bin 0 -> 3045 bytes .../src/main/webapp/user/images/reset.bak.png | Bin 0 -> 2898 bytes .../src/main/webapp/user/images/reset.png | Bin 0 -> 2863 bytes .../src/main/webapp/user/js/changePassword.js | 193 ++++++++++++++++ .../src/main/webapp/user/js/createUser.js | 189 ++++++++++++++++ .../src/main/webapp/user/js/modifyUser.js | 78 +++++++ .../portal-auth/src/main/webapp/user/js/user.js | 109 +++++++++ .../src/main/webapp/user/js/userTools.js | 88 ++++++++ .../src/main/webapp/user/modifyUser.html | 77 +++++++ .../portal-auth/src/main/webapp/user/user.html | 41 ++++ 18 files changed, 1415 insertions(+) create mode 100644 openo-portal/portal-auth/pom.xml create mode 100644 openo-portal/portal-auth/src/main/webapp/user/changePassword.html create mode 100644 openo-portal/portal-auth/src/main/webapp/user/createUser.html create mode 100644 openo-portal/portal-auth/src/main/webapp/user/css/component.css create mode 100644 openo-portal/portal-auth/src/main/webapp/user/css/user.css create mode 100644 openo-portal/portal-auth/src/main/webapp/user/images/add.png create mode 100644 openo-portal/portal-auth/src/main/webapp/user/images/delete.png create mode 100644 openo-portal/portal-auth/src/main/webapp/user/images/edit.bak.png create mode 100644 openo-portal/portal-auth/src/main/webapp/user/images/edit.png create mode 100644 openo-portal/portal-auth/src/main/webapp/user/images/reset.bak.png create mode 100644 openo-portal/portal-auth/src/main/webapp/user/images/reset.png create mode 100644 openo-portal/portal-auth/src/main/webapp/user/js/changePassword.js create mode 100644 openo-portal/portal-auth/src/main/webapp/user/js/createUser.js create mode 100644 openo-portal/portal-auth/src/main/webapp/user/js/modifyUser.js create mode 100644 openo-portal/portal-auth/src/main/webapp/user/js/user.js create mode 100644 openo-portal/portal-auth/src/main/webapp/user/js/userTools.js create mode 100644 openo-portal/portal-auth/src/main/webapp/user/modifyUser.html create mode 100644 openo-portal/portal-auth/src/main/webapp/user/user.html (limited to 'openo-portal') diff --git a/openo-portal/portal-auth/pom.xml b/openo-portal/portal-auth/pom.xml new file mode 100644 index 00000000..5f7c8b2b --- /dev/null +++ b/openo-portal/portal-auth/pom.xml @@ -0,0 +1,32 @@ + + + + 4.0.0 + + openo-portal + openo-portal + 1.0.0-SNAPSHOT + + + + openo-portal.module.auth + module-auth + 1.0.0-SNAPSHOT + pom + diff --git a/openo-portal/portal-auth/src/main/webapp/user/changePassword.html b/openo-portal/portal-auth/src/main/webapp/user/changePassword.html new file mode 100644 index 00000000..3b987033 --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/changePassword.html @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + +
+
Enter the Password Information
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ * + + User Name: + +
+ +
+
+
+ * + + Old Password: + +
+ +
+
+ +
+ * + + New Password: + +
+ +
+
+ +
+ * + + Confirm Password: + +
+ +
+
+ +
+
+
+
Password Rule:
+ + + + + + + + + + + + + +
1. Contains a minimum of 8 characters and a maximum of 32;
2. At least contains: one uppercase letter(A-Z), one lowercase letter(a-z), and one digit(0-9), one special character: ~`@#$%^&*-_=+|?/()<>[]{}",.;'!
3. Can not contain any the user name or user name in reverse order;
4. Can not contain space.
+
+
+
+ + +
+ + + diff --git a/openo-portal/portal-auth/src/main/webapp/user/createUser.html b/openo-portal/portal-auth/src/main/webapp/user/createUser.html new file mode 100644 index 00000000..ff12593c --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/createUser.html @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + +
+
Enter Basic Information
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ * + + User Name: + +
+ +
+
+ +
+ * + + Password: + +
+ +
+
+ +
+ * + + Confirm Password: + +
+ +
+
+ +
+ + + Description: + +
+ +
+
+
+
+
+
User Name Rule:
+ + + + + + + + + + + + + +
1. Contains a minimum of 5 characters and a maximum of 30;
2. Contains only alphanumeric characters(a-z\,A-Z\,0-9);
3. Can not contain any special characters except "_", which only in the middle of the user name;
4. Can not contain space.
+
Password Rule:
+ + + + + + + + + + + + + +
1. Contains a minimum of 8 characters and a maximum of 32;
2. At least contains: one uppercase letter(A-Z), one lowercase letter(a-z), and one digit(0-9), one special character: ~`@#$%^&*-_=+|?/()<>[]{}",.;'!
3. Can not contain any the user name or user name in reverse order;
4. Can not contain space.
+
+
+
+ + +
+ + + diff --git a/openo-portal/portal-auth/src/main/webapp/user/css/component.css b/openo-portal/portal-auth/src/main/webapp/user/css/component.css new file mode 100644 index 00000000..9c81d666 --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/css/component.css @@ -0,0 +1,247 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +.button_Group { + margin: 15px 0; + overflow: hidden; +} + +.fk_button { + padding: 0 14px; + height: 24px; + float: left; + cursor: pointer; + text-decoration: none; + outline: 0; + border: 1px solid #d3d3d3; + text-align: center; + box-shadow: 0 1px 1px rgba(0,0,0,.05); + background: #fafafa; + background: -moz-linear-gradient(top,#fff,#fafafa); + background: -webkit-gradient(linear,left top,left bottom,color-stop(0,#fff),color-stop(100%,#fafafa)); + background: -webkit-linear-gradient(top,#fff,#fafafa); + background: linear-gradient(to bottom,#fff,#fafafa); + border-radius: 6px; +} +.fk_button:hover { + color: #009ae7; + border: 1px solid #4AC9FF +} +.fk_button:active { + color: #0000; + border: 1px solid #4AC9FF +} + +.button_Group > button { + margin-right: 10px; +} +.add_imag { + background-image: url(/openoui/auth/v1/user/images/add.png); +} +.delete_imag { + background-image: url(/openoui/auth/v1/user/images/delete.png); +} +.button_imag { + padding-left: 25px; + background-repeat: no-repeat; + background-position: 5px center; +} + + +/*table style*/ +table.dataTable thead th { + padding: 0!important; + height: 22px!important; + padding: 1px 10px 0 5px; + overflow: visible; + white-space: nowrap; + background: #f0f0f0!important; + border: 1px solid #ddd; + border-top: 1px solid #e3e3e3!important; + border-left: 1px dotted transparent!important; + border-bottom: 1px solid #e3e3e3!important; + box-sizing: content-box; + text-align: left; + font-weight: +} +table.dataTable tr td { + padding: 0 10px 0 5px!important; + height: 30px!important; + color: #000!important; + border: none!important; + border-left: 1px solid transparent!important; + border-bottom: 1px solid #e3e3e3!important; + overflow: hidden!important; + white-space: nowrap!important; + text-align: left; +} + +table.dataTable th, table.dataTable td { + font-size: 12px!important; + color: #000!important; + max-width: 95%!important; + font-weight: 400!important; +} + +.paginate_button { + color: #666!important; + font-size: 12px!important; + font-family: Lucida Grande,Verdana,Arial,Helvetica,sans-serif!important; + line-height: 24px!important; + text-align: center!important; + border: 1px solid #e0e0e0!important; + text-decoration: none!important; + padding: 0 7px!important; + border-radius: 3px!important; + background: #fff!important; +} +.paginate_button:hover { + color: #666!important; + border: 1px solid #4ac9ff!important; + cursor: pointer!important; +} +.current { + text-decoration: none!important; + color: #fff!important; + border: 1px solid #00adf5!important; + background: #4ad2ff!important; +} + +/*over write the jquery dataTable*/ +.dataTables_wrapper .dataTables_paginate .paginate_button:hover { + color: #666!important; +} +.dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover { + color: #fff!important; +} +table.dataTable tr.odd, table.dataTable tr.odd>.sorting_1 { + background-color: #f9f9f9!important; +} +table.dataTable tr.even, table.dataTable tr.even>.sorting_1 { + background-color: #f7f7f7!important; +} +table.dataTable tbody tr:hover, tbody tr.odd>.sorting_1:hover, tbody tr.even>.sorting_1:hover { + background-color: #E6FBE0!important; +} +table.dataTable.no-footer { + border-bottom: none!important; +} + +/*the length information step style*/ +.dataTables_length, .dataTables_info { + display: inline-block!important; + float: left!important; +} +.left { + display: inline-block; + float: left; + overflow: hidden; + margin: 10px 20px 10px 5px; +} + .right { + display: inline-block; + float: right; + overflow: hidden; + margin-top: 10px; +} +.dataTables_length, .dataTables_info { + display: inline-block;!important; + float: left!important; + clear: none!important; + padding-top: 0!important; +} +.dataTables_length label { + font-size: 0; +} + +/*page select style*/ +.dataTables_length select { + height: 22px; + line-height: 22px; + text-align: center; + margin-right: 5px; + border: 1px solid #e0e0e0; + color: #000; + padding: 1px; +} +.dataTables_length select:active { + text-align: center; + margin-right: 5px; + border: 1px solid #e0e0e0; + color: #000; + padding: 1px; + border-radius: 5px; +} + +/* input style overwrite*/ +.fwk_input { + border: 1px solid #c3c3c3; + background-color: #fff; + padding: 0 0 0 6px; + border-radius: 4px; + color: #000; + display: inline-block; + outline: 0; + box-shadow: 1px 1px #f6f6f6 inset; + font-size: 12px; + background: #fff; + height: 24px; + width: 300px; +} + +.fwk_input:hover, .fwk_input:focus { + border-color: #4ac9ff; + box-shadow: 1px 1px rgba(74,201,255,.2) inset; +} +.fwk_input[type=password] { + -moz-user-select: none; + -khtml-user-select: none; + user-select: none; +} + +.fwk_input:disabled { + background-color: #ededed!important; + color: #666; + box-shadow: 1px 1px #ededed inset!important; + border: 1px solid #e0e0e0!important; + resize: none; +} + +/* input style textarea*/ +.fwk_textarea { + border: 1px solid #c3c3c3; + background-color: #fff; + padding: 0 0 0 6px; + border-radius: 4px; + color: #000; + display: inline-block; + outline: 0; + box-shadow: 1px 1px #f6f6f6 inset; + font-size: 12px; + background: #fff; + height: 72px; + width: 300px; +} + +.fwk_textarea:hover, .fwk_textarea:focus { + border-color: #4ac9ff; + box-shadow: 1px 1px rgba(74,201,255,.2) inset; +} + + + + + + diff --git a/openo-portal/portal-auth/src/main/webapp/user/css/user.css b/openo-portal/portal-auth/src/main/webapp/user/css/user.css new file mode 100644 index 00000000..b5060e9a --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/css/user.css @@ -0,0 +1,95 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +* { + font-family: Microsoft Yahei!important; + font-size: 12px; + color: #333; +} + +.hw_body { + background-color: #fafafa!important; + padding-left: 15px; +} + +.delete, .changePsd, .edit { + padding: 0 10px; + cursor: pointer; +} + +.mt20 { + margin: 20px; +} + +#progress { + position: relative;; + display: inline-block; +} + +#serverError { + margin-left: 18px; +} + +.mandatory { + color: #F00; + width: 7px; + padding-right: 10px 5px 10px 0; +} + +.row_interval { + padding: 10px 10px 10px 0; +} + +.progress_bar { + height: 4px; + border-radius: 2px; + width: 420px; + background: -webkit-linear-gradient(left, #6fd330, #29b6eb); + background: -o-linear-gradient(right, #6fd330, #29b6eb); + background: -moz-linear-gradient(right, #6fd330, #29b6eb); + background: linear-gradient(to right, #6fd330, #29b6eb); +} + +.progress_charater { + display: block; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + color: #1fbe5c; + text-align: center; + margin-bottom: 20px; +} + +.errorTip { + color: red; +} + +.suggestion_tip { + height: auto; + background-color: #FFF5EA; + border: 1px solid #F9DFC5; + padding: 8px 10px; + margin: 3px 0; + color: #333; + line-height: 20px; + overflow: auto; +} + +.rule_label { + font-weight: 600; +} +#role_content table { + margin-left: 20px; +} \ No newline at end of file diff --git a/openo-portal/portal-auth/src/main/webapp/user/images/add.png b/openo-portal/portal-auth/src/main/webapp/user/images/add.png new file mode 100644 index 00000000..d1f82993 Binary files /dev/null and b/openo-portal/portal-auth/src/main/webapp/user/images/add.png differ diff --git a/openo-portal/portal-auth/src/main/webapp/user/images/delete.png b/openo-portal/portal-auth/src/main/webapp/user/images/delete.png new file mode 100644 index 00000000..737f8797 Binary files /dev/null and b/openo-portal/portal-auth/src/main/webapp/user/images/delete.png differ diff --git a/openo-portal/portal-auth/src/main/webapp/user/images/edit.bak.png b/openo-portal/portal-auth/src/main/webapp/user/images/edit.bak.png new file mode 100644 index 00000000..68d76257 Binary files /dev/null and b/openo-portal/portal-auth/src/main/webapp/user/images/edit.bak.png differ diff --git a/openo-portal/portal-auth/src/main/webapp/user/images/edit.png b/openo-portal/portal-auth/src/main/webapp/user/images/edit.png new file mode 100644 index 00000000..68d76257 Binary files /dev/null and b/openo-portal/portal-auth/src/main/webapp/user/images/edit.png differ diff --git a/openo-portal/portal-auth/src/main/webapp/user/images/reset.bak.png b/openo-portal/portal-auth/src/main/webapp/user/images/reset.bak.png new file mode 100644 index 00000000..778b9c0c Binary files /dev/null and b/openo-portal/portal-auth/src/main/webapp/user/images/reset.bak.png differ diff --git a/openo-portal/portal-auth/src/main/webapp/user/images/reset.png b/openo-portal/portal-auth/src/main/webapp/user/images/reset.png new file mode 100644 index 00000000..d57e9b39 Binary files /dev/null and b/openo-portal/portal-auth/src/main/webapp/user/images/reset.png differ diff --git a/openo-portal/portal-auth/src/main/webapp/user/js/changePassword.js b/openo-portal/portal-auth/src/main/webapp/user/js/changePassword.js new file mode 100644 index 00000000..afe96b3d --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/js/changePassword.js @@ -0,0 +1,193 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +$(document).ready(function() { + var USER_SERVICE = "/openoapi/auth/v1/users"; + var userId; + var $userName = $("#userName"); + var $oldPassword = $("#oldPassword"); + var $oldPasswordError = $("#oldPasswordError"); + var $password = $("#password"); + var $passwordError = $("#passwordError") + + var $cfPsdError = $("#cfPsdError"); + + function initialPage() { + userId = getId(); + getUserDetails(userId).done(function(data) { + listUserDetails(data); + }); + + /*initial the event*/ + $("#confirm").click(function(e) { + if (!checkPassword()) { + return; + } + var data = getModifyUser(); + changePsd(data).done(function() { + top.bootbox.alert("Password change successfully.", function(e) { + Rest.turn2URI("/openoui/auth/v1/user/html/user.html"); + }) + }).fail(function(e) { + if (e.statusText == "Unauthorized") { + showError($oldPasswordError, "The old password is wrong."); + } else { + showError($oldPasswordError, e.statusText); + } + }) + }) + $("#cancel").click(function(e) { + window.document.location = "/openoui/auth/v1/user/html/user.html"; + }) + } + + function checkPassword() { + if (!checkMandatory()) { + return false; + } + + if (!checkCfPassword()) { + showError($cfPsdError, "The password is not the same."); + return false; + } + + if (!checkPasswordRule()) { + return false; + } + return true; + } + + function checkMandatory() { + if ($password.val() == "") { + showError($passwordError, "Mandatory."); + return false; + } + + if ($oldPassword.val() == "") { + showError($oldPasswordError, "Mandatory."); + return false; + } + return true; + } + + function checkCfPassword() { + return $("#password").val() == $("#cfPassword").val(); + } + + function checkPasswordRule() { + var password = $password.val(); + + if (!checkLength(8, 32, password)) { + showError($passwordError, "The password length should between 8 and 32."); + return false + } + + if (!checkCotainSpecial(password)) { + showError($passwordError, "At least contain: one uppercase letter, one lowercase letter, and one digit, one special character;"); + return false + } + + if (!checkNoContainAndReverse(password, $userName.val())) { + showError($passwordError, "The password should not contain the user name or reverse."); + return false + } + + if (!checkNoSpace(password)) { + showError($passwordError, "The password should not contain space."); + return false + } + return true + } + + function checkLength(min, max, str) { + return str.length >= min && str.length <= max; + } + + function checkOnlySpecials(str, reg) { + return str.match(reg) && str.match(reg).length == str.length + } + + function checkCotainSpecial(password) { + return password.match(/\~|\`|\@|\#|\$|\%|\^|\&|\*|\-|\_|\=|\+|\||\?|\/|\(|\)|\<|\>|\[|\]|\{|\}|\"|\,|\.|\;|\'|\!/g) != null + && password.match(/[0-9]/g) != null && password.match(/[a-z]/g) != null && password.match(/[A-Z]/g) != null; + } + + function checkUderScore(str) { + return str.indexOf("_") != 0 && str.lastIndexOf("_") != str.length - 1; + } + + function checkNoSpace(str) { + return str.indexOf(" ") == -1; + } + + function checkNoContainAndReverse(str, str2) { + return str.indexOf(str2) == -1 && str.indexOf(str2.split("").reverse().join("")) == -1; + } + + function getModifyUser() { + var data = {}; + data["original_password"] = $("#oldPassword").val(); + data.password = $("#password").val(); + return data; + } + + function getUserDetails(id) { + return Rest.http({ + url: USER_SERVICE + "/" + id + "?=" + new Date().getTime(), + type: "GET", + async: false, + contentType: 'application/json', + dataType: "json" + }) + } + + function listUserDetails(data) { + $("#userName").val(data.name); + } + + + function changePsd(data) { + return Rest.http({ + url: USER_SERVICE + "/" + userId + "/password" + "?=" + new Date().getTime(), + type: "POST", + async: false, + contentType: 'application/json', + dataType: "json", + data: JSON.stringify(data) + }) + } + + function getId() { + var qs = location.search; + qs = qs.indexOf("?") === 0 ? qs : ("?" + qs); + var start = qs.indexOf("id=") + 3; + var end = qs.indexOf("&") === -1 ? qs.length : qs.indexOf("&") - start; + return qs.substr(start, end); + } + + function showError($Obj, message) { + $Obj.text(message); + $Obj.css("visibility", "visible"); + setTimeout(function() { + hideError($Obj); + }, 5000) + } + + function hideError($Obj) { + $Obj.css("visibility", "hidden"); + } + + initialPage(); +}) diff --git a/openo-portal/portal-auth/src/main/webapp/user/js/createUser.js b/openo-portal/portal-auth/src/main/webapp/user/js/createUser.js new file mode 100644 index 00000000..7a95a8ee --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/js/createUser.js @@ -0,0 +1,189 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +$(document).ready(function() { + + var USER_SERVICE = "/openoapi/auth/v1/users"; + var $userName = $("#userName"); + var $password = $("#password"); + var $cfPsdError = $("#cfPsdError"); + var $userNameError = $("#userNameError"); + var $passwordError = $("#passwordError"); + + function initialPage() { + /*initial the event*/ + $("#confirm").click(function(e) { + if (!checkUserRules()) { + return; + } + var data = getCreateUser(); + createUser(data).done(function() { + window.document.location = "/openoui/auth/v1/user/html/user.html"; + }) + }) + $("#cancel").click(function(e) { + window.document.location = "/openoui/auth/v1/user/html/user.html"; + }) + } + + function getCreateUser() { + var data = {}; + data.userName = $userName.val(); + data.password = $password.val(); + data.description = $("#description").val(); + data.email = "xxxx@xxxx.com"; + return data; + } + + function createUser(data) { + return Rest.http({ + url: USER_SERVICE + "?=" + new Date().getTime(), + type: "POST", + async: false, + contentType: 'application/json', + dataType: "json", + data: JSON.stringify(data) + }) + } + + function checkUserRules() { + if (!checkMandatory()) { + return false; + } + + if (!checkCfPassword()) { + return false; + } + + if (!checkUserNameRule()) { + return false; + } + + if (!checkPasswordRule()) { + return false; + } + return true; + } + + function checkMandatory() { + if ($userName.val() == "") { + showError($userNameError, "Mandatory."); + return false; + } + + if ($password.val() == "") { + showError($passwordError, "Mandatory."); + return false; + } + return true; + } + + function checkUserNameRule() { + var username = $userName.val(); + if (!checkLength(5, 30, username)) { + showError($userNameError, "The user name length should between 5 and 30."); + return false + } + + if (!checkOnlySpecials(username, /[0-9]|[a-z]|[A-Z]|_/g)) { + showError($userNameError, "Only Character(a-z\,A-Z\,0-9,_) is allowed."); + return false + } + + if(!checkUderScore(username)) { + showError($userNameError, 'The character "_" is only allowed in the middle of the user name.'); + return false + } + + if (!checkNoSpace(username)) { + showError($userNameError, "The user name should not contain space."); + return false + } + + return true + } + + function checkPasswordRule() { + var password = $password.val(); + + if (!checkLength(8, 32, password)) { + showError($passwordError, "The password length should between 8 and 32."); + return false + } + + if (!checkCotainSpecial(password)) { + showError($passwordError, "At least contain: one uppercase letter, one lowercase letter, and one digit, one special character;"); + return false + } + + if (!checkNoContainAndReverse(password, $userName.val())) { + showError($passwordError, "The password should not contain the user name or reverse."); + return false + } + + if (!checkNoSpace(password)) { + showError($passwordError, "The password should not contain space."); + return false + } + return true + } + + function checkLength(min, max, str) { + return str.length >= min && str.length <= max; + } + + function checkOnlySpecials(str, reg) { + return str.match(reg) && str.match(reg).length == str.length + } + + function checkCotainSpecial(password) { + return password.match(/\~|\`|\@|\#|\$|\%|\^|\&|\*|\-|\_|\=|\+|\||\?|\/|\(|\)|\<|\>|\[|\]|\{|\}|\"|\,|\.|\;|\'|\!/g) != null + && password.match(/[0-9]/g) != null && password.match(/[a-z]/g) != null && password.match(/[A-Z]/g) != null; + } + + function checkUderScore(str) { + return str.indexOf("_") != 0 && str.lastIndexOf("_") != str.length - 1; + } + + function checkNoContainAndReverse(str, str2) { + return str.indexOf(str2) == -1 && str.indexOf(str2.split("").reverse().join("")) == -1; + } + + function checkNoSpace(str) { + return str.indexOf(" ") == -1; + } + + function checkCfPassword() { + if ($password.val() == $("#cfPassword").val()) { + return true; + } + showError($cfPsdError, "The password is not the same."); + return false; + } + + function showError($Obj, message) { + $Obj.text(message); + $Obj.css("visibility", "visible"); + setTimeout(function() { + hideError($Obj); + }, 5000) + } + + function hideError($Obj) { + $Obj.css("visibility", "hidden"); + } + + initialPage(); +}) diff --git a/openo-portal/portal-auth/src/main/webapp/user/js/modifyUser.js b/openo-portal/portal-auth/src/main/webapp/user/js/modifyUser.js new file mode 100644 index 00000000..b01cebe4 --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/js/modifyUser.js @@ -0,0 +1,78 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +$(document).ready(function() { + var USER_SERVICE = "/openoapi/auth/v1/users"; + var userId; + function initialPage() { + userId = getId(); + getUserDetails(userId).done(function(data) { + listUserDetails(data); + }); + + /*initial the event*/ + $("#confirm").click(function(e) { + var data = getModifyUser(); + modifyUser(data).done(function() { + window.document.location = "/openoui/auth/v1/user/html/user.html"; + }) + }) + $("#cancel").click(function(e) { + window.document.location = "/openoui/auth/v1/user/html/user.html"; + }) + } + + function getModifyUser() { + var data = {}; + data.description = $("#description").val(); + data.email = "xxxx@xxxx.com"; + return data; + } + function getUserDetails(id) { + return Rest.http({ + url: USER_SERVICE + "/" + id + "?=" + new Date().getTime(), + type: "GET", + async: false, + contentType: 'application/json', + dataType: "json" + }) + } + + function listUserDetails(data) { + $("#userName").val(data.name); + $("#description").val(data.description); + } + + function modifyUser(data) { + return Rest.http({ + url: USER_SERVICE + "/" + userId + "?=" + new Date().getTime(), + type: "PATCH", + async: false, + contentType: 'application/json', + dataType: "json", + data: JSON.stringify(data) + }) + } + + function getId() { + var qs = location.search; + qs = qs.indexOf("?") === 0 ? qs : ("?" + qs); + var start = qs.indexOf("id=") + 3; + var end = qs.indexOf("&") === -1 ? qs.length : qs.indexOf("&") - start; + return qs.substr(start, end); + } + + initialPage(); +}) \ No newline at end of file diff --git a/openo-portal/portal-auth/src/main/webapp/user/js/user.js b/openo-portal/portal-auth/src/main/webapp/user/js/user.js new file mode 100644 index 00000000..bc442616 --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/js/user.js @@ -0,0 +1,109 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +$(document).ready(function() { + var USER_SERVICE = "/openoapi/auth/v1/users"; + var deleteEditOpt = ""; + var editOpt = ""; + + var userListHeader = [ + { title: "User", data: "User",width: "20%"}, + { title: "Description", data: "Description",width: "60%"}, + { title: "Operations", data: "Operations",width: "20%"} + ]; + function initialPage() { + /*get the user list data;*/ + getUserList().done(function(data) { + var data = formatUsers(data); + Table.create(data, "table_id", userListHeader); + $(".hw_body").css("visibility", "visible"); + }).error(function(data) { + if (data.status == 403) { + $(".hw_body").html("" + JSON.parse(data.responseText).error.message + ""); + } + }); + + /*add the listener*/ + $("#table_id tbody").on("click", "td", function(e) { + var classname = e.target.className; + var id = $("#table_id").DataTable().row(this).data().rowid; + if (classname == "delete") { + top.bootbox.confirm("Are you sure to delete this user?", function(result) { + if (result) { + deleteUser(id).done(function() { + getUserList().done(function(data) { + var data = formatUsers(data); + var datatable = $("#table_id").dataTable().api(); + datatable.clear(); + datatable.rows.add(data); + datatable.draw(); + }) + }) + } + }) + } else if (classname == "edit") { + window.document.location = "/openoui/auth/v1/user/html/modifyUser.html" + "?id=" + id; + } else if (classname == "changePsd") { + window.document.location = "/openoui/auth/v1/user/html/changePassword.html" + "?id=" + id; + } + }) + + $("#create").click(function(e) { + window.document.location = "/openoui/auth/v1/user/html/createUser.html"; + }) + } + + function getUserList() { + return Rest.http({ + url: USER_SERVICE + "?=" + new Date().getTime(), + type: "GET", + async: false, + contentType: 'application/json', + dataType: "json" + }) + } + + function deleteUser(id) { + return Rest.http({ + url: USER_SERVICE + "/" + id + "?=" + new Date().getTime(), + type: "DELETE", + async: false, + contentType: 'application/json', + dataType: "json" + }) + } + + function formatUsers(data) { + var tableData = []; + for (var i = 0; i < data.length; i++) { + var temp = {}; + temp.rowid = data[i].id; + temp.User = data[i].name; + temp.Description = data[i].description; + if (data[i].name == "admin") { + temp.Operations = editOpt; + } else { + temp.Operations = deleteEditOpt; + } + tableData.push(temp); + } + return tableData; + } + initialPage(); + + setTimeout(function() { + Table.enableToolTips("table_id"); + }, 0) +}); diff --git a/openo-portal/portal-auth/src/main/webapp/user/js/userTools.js b/openo-portal/portal-auth/src/main/webapp/user/js/userTools.js new file mode 100644 index 00000000..d9157a9a --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/js/userTools.js @@ -0,0 +1,88 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var Table = {}; +Table.create = function(data, id, columns) { + $('#' + id).DataTable({ + data: data, + bSort: false, + "sDom": "<'right'p>>", + columns: columns + }); + } + /** + * update the table data, the cloumns must be same with the create one. + * data: the update data. as the create structure + * id: the table id. + */ +Table.updata = function(data, id) { + var datatable = $('#' + id).dataTable().api(); + datatable.clear(); + datatable.rows.add(data); + datatable.draw(); +} + +Table.enableToolTips = function(id) { + $("#" + id + " tr th").each(function(index, sdom){ + sdom.title = sdom.textContent; + }) + $("#" + id + " tbody tr td").each(function(index, sdom){ + sdom.title = sdom.textContent; + }) +} + +var Rest = {}; + +Rest.http = function(setting) { + var ret = $.ajax(setting); + ret.fail(function(data) { + try { + if (data.responseText.indexOf("login") != -1) { + top.window.document.location.reload() + } + var result = JSON.parse(data.responseText); + if (result.error && result.error.message) { + top.bootbox.alert(result.error.message, function() {}); + } + } catch (e) { + } + + }) + return ret; +} + +Rest.turn2URI = function(url) { + var cookies = document.cookie.split(";"); + var cookie = ""; + for (var i = 0; i < cookies.length; i++) { + if (cookies[i].split("=")[0] == "X-Auth-Token") { + cookie = cookies[i].split("=")[1]; + break; + } + } + $.ajax({ + url: "/openoapi/auth/v1/tokens", + type: "HEAD", + headers: { + "X-Auth-Token": cookie + }, + success: function(data) { + window.document.location = url; + }, + error: function(data) { + top.window.document.location.reload(); + } + }) +} diff --git a/openo-portal/portal-auth/src/main/webapp/user/modifyUser.html b/openo-portal/portal-auth/src/main/webapp/user/modifyUser.html new file mode 100644 index 00000000..2c3bdcae --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/modifyUser.html @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + +
+
Enter Basic Information
+
+
+
+ + + + + + + + + + + + + +
+ * + + User Name: + +
+ +
+
+ +
+ + + Description: + +
+ +
+
+ +
+
+
+ + +
+ + + diff --git a/openo-portal/portal-auth/src/main/webapp/user/user.html b/openo-portal/portal-auth/src/main/webapp/user/user.html new file mode 100644 index 00000000..39050638 --- /dev/null +++ b/openo-portal/portal-auth/src/main/webapp/user/user.html @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+ + + -- cgit 1.2.3-korg