[ISSUE-205|247] Support SSL + Login

This commit is contained in:
walking98
2019-04-16 11:09:07 +08:00
parent c11f815e1e
commit 8edf026461
22 changed files with 1103 additions and 11 deletions

View File

@@ -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>

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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"
}

View File

@@ -77,5 +77,10 @@ var zh = {
"CLUSTER_NAME":"集群名",
"OPS":"运维",
"AUTO_REFRESH":"自动刷新",
"REFRESH":"刷新"
"REFRESH":"刷新",
"LOGOUT":"退出",
"LOGIN":"登录",
"USER_NAME":"用户名",
"PASSWORD":"密码",
"WELCOME":"您好欢迎使用RocketMQ控制台"
}

View 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});
}
});
};
}]);

View File

@@ -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>

View 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>