mirror of
https://github.com/apache/rocketmq-dashboard.git
synced 2026-02-23 22:55:46 +08:00
[ISSUE-205|247] Support SSL + Login
This commit is contained in:
@@ -113,6 +113,6 @@
|
||||
<script type="text/javascript" src="src/ops.js?timestamp=7"></script>
|
||||
<script type="text/javascript" src="src/remoteApi/remoteApi.js"></script>
|
||||
<script type="text/javascript" src="vendor/preLoading/main.js"></script>
|
||||
|
||||
<script type="text/javascript" src="src/login.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -29,8 +29,8 @@ var app = angular.module('app', [
|
||||
'localytics.directives',
|
||||
'pascalprecht.translate'
|
||||
]).run(
|
||||
['$rootScope','$location','$cookies',
|
||||
function ($rootScope,$location,$cookies) {
|
||||
['$rootScope','$location','$cookies','$http',
|
||||
function ($rootScope,$location,$cookies,$http) {
|
||||
// var filter = function(url){
|
||||
// var outFilterArrs = []
|
||||
// outFilterArrs.push("/login");
|
||||
@@ -51,6 +51,23 @@ var app = angular.module('app', [
|
||||
// chatApi.login();
|
||||
// }
|
||||
|
||||
$rootScope.username = $cookies.get("username");
|
||||
if (!angular.isDefined($rootScope.username)) {
|
||||
$rootScope.username = '';
|
||||
}
|
||||
console.log("username " + $rootScope.username);
|
||||
$rootScope.globals = $cookies.get('TOKEN');
|
||||
console.log('TOKEN ' + $rootScope.globals);
|
||||
$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');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$rootScope.$on('$routeChangeSuccess', function() {
|
||||
var pathArray = $location.url().split("/");
|
||||
@@ -130,6 +147,9 @@ app.config(['$routeProvider', '$httpProvider','$cookiesProvider','getDictNamePro
|
||||
$routeProvider.when('/', {
|
||||
templateUrl: 'view/pages/index.html',
|
||||
controller:'dashboardCtrl'
|
||||
}).when('/login', {
|
||||
templateUrl: 'view/pages/login.html',
|
||||
controller:'loginController'
|
||||
}).when('/cluster', {
|
||||
templateUrl: 'view/pages/cluster.html',
|
||||
controller:'clusterController'
|
||||
@@ -153,7 +173,7 @@ app.config(['$routeProvider', '$httpProvider','$cookiesProvider','getDictNamePro
|
||||
controller:'opsController'
|
||||
}).when('/404', {
|
||||
templateUrl: '404'
|
||||
}).otherwise('404');
|
||||
}).otherwise('/login');
|
||||
|
||||
$translateProvider.translations('en',en);
|
||||
$translateProvider.translations('zh',zh);
|
||||
|
||||
@@ -14,10 +14,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
app.controller('AppCtrl', ['$scope','$rootScope','$cookies','$location','$translate', function ($scope,$rootScope,$cookies,$location,$translate) {
|
||||
app.controller('AppCtrl', ['$scope','$rootScope','$cookies','$location','$translate','$http','Notification', function ($scope,$rootScope,$cookies,$location,$translate, $http, Notification) {
|
||||
$scope.changeTranslate = function(langKey){
|
||||
$translate.use(langKey);
|
||||
}
|
||||
|
||||
$scope.logout = function(){
|
||||
$http({
|
||||
method: "POST",
|
||||
url: "login/logout"
|
||||
}).success(function (resp) {
|
||||
window.location = "/";
|
||||
$cookies.remove("username");
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
app.controller('dashboardCtrl', ['$scope','$rootScope','$translate','$filter','Notification','remoteApi','tools', function ($scope,$rootScope,$translate,$filter,Notification,remoteApi,tools) {
|
||||
|
||||
@@ -77,5 +77,10 @@ var en = {
|
||||
"CLUSTER_NAME":"clusterName",
|
||||
"OPS":"OPS",
|
||||
"AUTO_REFRESH":"AUTO_REFRESH",
|
||||
"REFRESH":"REFRESH"
|
||||
"REFRESH":"REFRESH",
|
||||
"LOGOUT":"Logout",
|
||||
"LOGIN":"Login",
|
||||
"USER_NAME":"Username",
|
||||
"PASSWORD":"Password",
|
||||
"WELCOME":"Hi, welcome using RocketMQ Console"
|
||||
}
|
||||
@@ -77,5 +77,10 @@ var zh = {
|
||||
"CLUSTER_NAME":"集群名",
|
||||
"OPS":"运维",
|
||||
"AUTO_REFRESH":"自动刷新",
|
||||
"REFRESH":"刷新"
|
||||
"REFRESH":"刷新",
|
||||
"LOGOUT":"退出",
|
||||
"LOGIN":"登录",
|
||||
"USER_NAME":"用户名",
|
||||
"PASSWORD":"密码",
|
||||
"WELCOME":"您好,欢迎使用RocketMQ控制台"
|
||||
}
|
||||
42
src/main/resources/static/src/login.js
Normal file
42
src/main/resources/static/src/login.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.
|
||||
*/
|
||||
|
||||
app.controller('loginController', ['$scope','$location','$http','Notification','$cookies', function ($scope,$location,$http,Notification,$cookies) {
|
||||
$scope.login = function () {
|
||||
if(!$("#username").val()) {
|
||||
alert("用户名不能为空");
|
||||
return;
|
||||
}
|
||||
if(!$("#password").val()) {
|
||||
alert("密码不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
$http({
|
||||
method: "POST",
|
||||
url: "login/check",
|
||||
params:{username:$("#username").val(), password:$("#password").val()}
|
||||
}).success(function (resp) {
|
||||
if (resp.status == 0) {
|
||||
Notification.info({message: 'Login successful, redirect now', delay: 2000});
|
||||
window.location = "/";
|
||||
} else{
|
||||
Notification.error({message: resp.errMsg, delay: 2000});
|
||||
}
|
||||
});
|
||||
};
|
||||
}]);
|
||||
@@ -28,7 +28,27 @@
|
||||
<li><a href="javascript:void(0)" ng-click="changeTranslate('zh')">Simplified Chinese</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="dropdown" ng-show="username != ''">
|
||||
<a href="bootstrap-elements.html" data-target="#" class="dropdown-toggle" data-toggle="dropdown">{{username}}
|
||||
<b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="javascript:void(0)" ng-click="logout()">{{'LOGOUT' | translate}}</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var app = angular.module('DemoApp',[]);
|
||||
|
||||
app.controller('DemoController',function($scope){
|
||||
$scope.IsVisible = false;
|
||||
|
||||
$scope.ShowHide = function(){
|
||||
$scope.IsVisible = $scope.IsVisible = true;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
44
src/main/resources/static/view/pages/login.html
Normal file
44
src/main/resources/static/view/pages/login.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<div id="loginModal" class="page-content" id="deployHistoryList" data-width="400" data-backdrop="static" role="main" >
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">{{'WELCOME' | translate}}</h4>
|
||||
</div>
|
||||
<form class="form-horizontal form-bordered form-row-stripped" id="loginForm">
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="form-body">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-4">{{'USER_NAME' | translate}}: </label>
|
||||
<div class="col-md-5">
|
||||
<input type="text" id="username" name="username" placeholder="{{'USER_NAME' | translate}}" class="form-control" ng-model="filterStr"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-md-4"> {{'PASSWORD' | translate}}: </label>
|
||||
<div class="col-md-5">
|
||||
<input type="password" name="password" id="password"
|
||||
value="" placeholder="{{'USER_NAME' | translate}}"
|
||||
class="form-control" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-raised btn-sm btn-primary" type="button" ng-click="login()">{{'LOGIN' | translate}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function(){
|
||||
console.log('aaaaa111');
|
||||
//$("#loginModal").modal("hide");
|
||||
console.log('aaaaa');
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user