2 * Copyright 2016-2017, CMCC Technologies Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 String.prototype.trim = function() {
\r
17 return this.replace(/(^\s*)|(\s*$)/g, "");
\r
20 function loginSubmitHandler() {
\r
22 "userName": $("#openo_input_userName").val(),
\r
23 "password": $("#openo_input_password").val()
\r
27 url : "/openoapi/auth/v1/tokens",
\r
29 contentType : 'application/json; charset=utf-8',
\r
30 data : JSON.stringify(loginData)
\r
31 }).done(function(data) {
\r
32 var topURL = top.window.document.location.href;
\r
33 if (topURL.indexOf("?service") != -1) {
\r
34 top.window.document.location.href = decodeURIComponent(topURL.substring(topURL.indexOf("?service") + 9));
\r
36 top.window.document.location.href = "/openoui/common/default.html";
\r
38 store("loginUserName", $("#openo_input_userName").val());
\r
39 }).fail(function(data) {
\r
40 var tipDivId = $("#loginConnError");
\r
41 if (data.status == 401) {
\r
42 tipDivId = $("#nameOrpwdError");
\r
45 tipDivId.addClass('alert-danger');
\r
46 if (tipDivId.attr("tipstatus") == "normal") {
\r
48 } else if (tipDivId.attr("tipstatus") == "close") {
\r
49 tipDivId.attr("tipstatus", "normal");
\r
56 var Login = function () {
\r
57 var handleLogin = function() {
\r
58 $('.login-form').validate({
\r
59 errorElement: 'span', //default input error message container
\r
60 errorClass: 'help-block', // default input error message class
\r
61 focusInvalid: false, // do not focus the last invalid input
\r
75 required: $.i18n.prop('openo_input_userName').replace(/\"/g,'')
\r
78 required: $.i18n.prop('openo_input_password').replace(/\"/g,'')
\r
81 invalidHandler: function (event, validator) {
\r
82 $('.alert-danger', $('.login-form')).show();
\r
84 highlight: function (element) {
\r
85 $(element).closest('.form-group').addClass('has-error'); // set error class to the control group
\r
87 success: function (label) {
\r
88 label.closest('.form-group').removeClass('has-error');
\r
91 errorPlacement: function (error, element) {
\r
92 error.insertAfter(element.closest('.input-icon'));
\r
94 submitHandler: loginSubmitHandler
\r
97 $('.login-form input').keypress(function (e) {
\r
98 $("#nameOrpwdError").hide();
\r
99 $("#loginConnError").hide();
\r
100 if (e.which == 13) {
\r
101 if ($('.login-form').validate().form()) {
\r
102 $('.login-form').submit();
\r
110 //main function to initiate the module
\r
111 init: function () {
\r
114 "image/integration/openo_bg_1.jpg",
\r
115 "image/integration//openo_bg_2.jpg",
\r
116 "image/integration//openo_bg_3.jpg"
\r
125 $(document).ready(function() {
\r
126 if (store("remember") == "true") {
\r
127 $("input[name='remember']").attr("checked", "checked");
\r
128 $("#openo_input_userName").val(store("openo_input_userName"));
\r
129 $("#openo_input_password").val(store("openo_input_password"));
\r
133 function saveUserInfo() {
\r
134 var rmbcheck = $("input[name='remember']");
\r
135 if (rmbcheck.attr("checked") == true || rmbcheck.is(':checked')) {
\r
136 store("remember", "true");
\r
137 store("openo_input_userName", $("#openo_input_userName").val());
\r
138 store("openo_input_password", $("#openo_input_password").val());
\r
140 store.remove("remember");
\r
141 store.remove("openo_input_userName");
\r
142 store.remove("openo_input_password");
\r
146 function logoutSubmit() {
\r
148 url: "/openoapi/auth/v1/tokens" + "?=" + new Date().getTime(),
\r
150 contentType: "application/json",
\r
152 success: function() {
\r
153 top.window.location = "/openoui/common/login.html";
\r
155 error: function() {
\r