mirror of
https://github.com/apache/rocketmq-dashboard.git
synced 2026-02-22 05:35:43 +08:00
[ISSUE-205|247] Support SSL + Login: Polish with testcase, doc, session over cookie
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
var initFlag = false;
|
||||
var loginFlag = false;
|
||||
var app = angular.module('app', [
|
||||
'ngAnimate',
|
||||
'ngCookies',
|
||||
@@ -29,43 +31,60 @@ var app = angular.module('app', [
|
||||
'localytics.directives',
|
||||
'pascalprecht.translate'
|
||||
]).run(
|
||||
['$rootScope','$location','$cookies','$http',
|
||||
function ($rootScope,$location,$cookies,$http) {
|
||||
// var filter = function(url){
|
||||
// var outFilterArrs = []
|
||||
// outFilterArrs.push("/login");
|
||||
// outFilterArrs.push("/reg");
|
||||
// outFilterArrs.push("/logout");
|
||||
// outFilterArrs.push("/404");
|
||||
// var flag = false;
|
||||
// $.each(outFilterArrs,function(i,value){
|
||||
// if(url.indexOf(value) > -1){
|
||||
// flag = true;
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
// return flag;
|
||||
// }
|
||||
['$rootScope','$location','$cookies','$http', '$window','Notification',
|
||||
function ($rootScope,$location,$cookies,$http, $window, Notification) {
|
||||
var init = function(callback){
|
||||
if (initFlag) return;
|
||||
initFlag = true;
|
||||
|
||||
// if(angular.isDefined($cookies.get("isLogin")) && $cookies.get("isLogin") == 'true'){
|
||||
// chatApi.login();
|
||||
// }
|
||||
//TODO: make the session timeout consistent with backend
|
||||
// var sessionId = $cookies.get("JSESSIONID");
|
||||
// console.log("sessionId "+ sessionId);
|
||||
//
|
||||
// if (sessionId === undefined || sessionId == null) {
|
||||
// $window.sessionStorage.clear();
|
||||
// }
|
||||
|
||||
$rootScope.username = $cookies.get("username");
|
||||
if (!angular.isDefined($rootScope.username)) {
|
||||
$rootScope.username = '';
|
||||
var url = '/login/check.query';
|
||||
var setting = {
|
||||
type: "GET",
|
||||
timeout:15000,
|
||||
success:callback,
|
||||
async:false
|
||||
}
|
||||
//sync invoke
|
||||
$.ajax(url,setting)
|
||||
}
|
||||
console.log("username " + $rootScope.username);
|
||||
$rootScope.globals = $cookies.get('TOKEN');
|
||||
console.log('TOKEN ' + $rootScope.globals);
|
||||
console.log('initFlag0='+ initFlag + ' loginFlag0==='+loginFlag);
|
||||
|
||||
$rootScope.$on('$locationChangeStart', function (event, next, current) {
|
||||
// redirect to login page if not logged in and trying to access a restricted page
|
||||
var restrictedPage = $.inArray($location.path(), ['/login']) === -1;
|
||||
var loggedIn = $rootScope.globals;
|
||||
if (restrictedPage && (!angular.isDefined(loggedIn) || !loggedIn)) {
|
||||
var callback = $location.path();
|
||||
$location.path('/login');
|
||||
init(function(resp){
|
||||
if (resp.status == 0) {
|
||||
// console.log('resp.data==='+resp.data);
|
||||
loginFlag = resp.data;
|
||||
}else {
|
||||
Notification.error({message: "" + resp.errMsg, delay: 2000});
|
||||
}
|
||||
});
|
||||
|
||||
console.log('initFlag='+ initFlag + ' loginFlag==='+loginFlag);
|
||||
$rootScope.username = '';
|
||||
if (loginFlag || loginFlag == "true") {
|
||||
var username = $window.sessionStorage.getItem("username");
|
||||
|
||||
if (username != null) {
|
||||
$rootScope.username = username;
|
||||
}
|
||||
|
||||
// console.log("username " + $rootScope.username);
|
||||
var restrictedPage = $.inArray($location.path(), ['/login']) === -1;
|
||||
if (restrictedPage && !username) {
|
||||
var callback = $location.path();
|
||||
$location.path('/login');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -94,6 +113,19 @@ var app = angular.module('app', [
|
||||
}
|
||||
});
|
||||
|
||||
app.factory('abc', function ($http, $window) {
|
||||
console.log('xxxxxxx');
|
||||
$http({
|
||||
method: "GET",
|
||||
url: "/login/check.query"
|
||||
}).success(function (resp) {
|
||||
if (resp.status == 0) {
|
||||
alert(resp.data)
|
||||
}
|
||||
});
|
||||
return 1;
|
||||
});
|
||||
|
||||
app.provider('getDictName', function () {
|
||||
|
||||
var dictList = [];
|
||||
@@ -142,6 +174,9 @@ app.config(['$routeProvider', '$httpProvider','$cookiesProvider','getDictNamePro
|
||||
}
|
||||
});
|
||||
|
||||
// check login status
|
||||
|
||||
|
||||
$httpProvider.defaults.cache = false;
|
||||
|
||||
$routeProvider.when('/', {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
app.controller('AppCtrl', ['$scope','$rootScope','$cookies','$location','$translate','$http','Notification', function ($scope,$rootScope,$cookies,$location,$translate, $http, Notification) {
|
||||
app.controller('AppCtrl', ['$scope','$window','$translate','$http','Notification', function ($scope,$window,$translate, $http, Notification) {
|
||||
$scope.changeTranslate = function(langKey){
|
||||
$translate.use(langKey);
|
||||
}
|
||||
@@ -22,10 +22,10 @@ app.controller('AppCtrl', ['$scope','$rootScope','$cookies','$location','$transl
|
||||
$scope.logout = function(){
|
||||
$http({
|
||||
method: "POST",
|
||||
url: "login/logout"
|
||||
url: "login/logout.do"
|
||||
}).success(function (resp) {
|
||||
window.location = "/";
|
||||
$cookies.remove("username");
|
||||
$window.sessionStorage.clear();
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
app.controller('loginController', ['$scope','$location','$http','Notification','$cookies', function ($scope,$location,$http,Notification,$cookies) {
|
||||
app.controller('loginController', ['$scope','$location','$http','Notification','$cookies','$window', function ($scope,$location,$http,Notification,$cookies, $window) {
|
||||
$scope.login = function () {
|
||||
if(!$("#username").val()) {
|
||||
alert("用户名不能为空");
|
||||
@@ -28,12 +28,14 @@ app.controller('loginController', ['$scope','$location','$http','Notification','
|
||||
|
||||
$http({
|
||||
method: "POST",
|
||||
url: "login/check",
|
||||
url: "login/login.do",
|
||||
params:{username:$("#username").val(), password:$("#password").val()}
|
||||
}).success(function (resp) {
|
||||
if (resp.status == 0) {
|
||||
Notification.info({message: 'Login successful, redirect now', delay: 2000});
|
||||
$window.sessionStorage.setItem("username", $("#username").val());
|
||||
window.location = "/";
|
||||
initFlag = false;
|
||||
} else{
|
||||
Notification.error({message: resp.errMsg, delay: 2000});
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
</div>
|
||||
<script>
|
||||
$(function(){
|
||||
console.log('aaaaa111');
|
||||
//$("#loginModal").modal("hide");
|
||||
console.log('aaaaa');
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user