Merge pull request #1093 from wknet123/dev-temp

Updates for removing cookies about user info.
Need more test~
This commit is contained in:
yhua123 2016-11-16 17:07:34 +08:00 committed by GitHub
commit 9f0be6c53d
11 changed files with 38 additions and 61 deletions

View File

@ -9,6 +9,9 @@ type AccountSettingController struct {
func (asc *AccountSettingController) Get() { func (asc *AccountSettingController) Get() {
var isAdminForLdap bool var isAdminForLdap bool
sessionUserID, ok := asc.GetSession("userId").(int) sessionUserID, ok := asc.GetSession("userId").(int)
if !ok {
asc.Redirect("/", 302)
}
if ok && sessionUserID == 1 { if ok && sessionUserID == 1 {
isAdminForLdap = true isAdminForLdap = true
} }

View File

@ -9,6 +9,9 @@ type ChangePasswordController struct {
func (cpc *ChangePasswordController) Get() { func (cpc *ChangePasswordController) Get() {
var isAdminForLdap bool var isAdminForLdap bool
sessionUserID, ok := cpc.GetSession("userId").(int) sessionUserID, ok := cpc.GetSession("userId").(int)
if !ok {
cpc.Redirect("/", 302)
}
if ok && sessionUserID == 1 { if ok && sessionUserID == 1 {
isAdminForLdap = true isAdminForLdap = true
} }

View File

@ -112,12 +112,12 @@ func TestMain(t *testing.T) {
r, _ = http.NewRequest("GET", "/account_setting", nil) r, _ = http.NewRequest("GET", "/account_setting", nil)
w = httptest.NewRecorder() w = httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r) beego.BeeApp.Handlers.ServeHTTP(w, r)
assert.Equal(int(200), w.Code, "'/account_setting' httpStatusCode should be 200") assert.Equal(int(302), w.Code, "'/account_setting' httpStatusCode should be 302")
r, _ = http.NewRequest("GET", "/change_password", nil) r, _ = http.NewRequest("GET", "/change_password", nil)
w = httptest.NewRecorder() w = httptest.NewRecorder()
beego.BeeApp.Handlers.ServeHTTP(w, r) beego.BeeApp.Handlers.ServeHTTP(w, r)
assert.Equal(int(200), w.Code, "'/change_password' httpStatusCode should be 200") assert.Equal(int(302), w.Code, "'/change_password' httpStatusCode should be 302")
r, _ = http.NewRequest("GET", "/admin_option", nil) r, _ = http.NewRequest("GET", "/admin_option", nil)
w = httptest.NewRecorder() w = httptest.NewRecorder()

View File

@ -18,37 +18,20 @@
angular angular
.module('harbor.app') .module('harbor.app')
.factory('currentUser', currentUser) .factory('currentUser', currentUser);
.factory('currentProjectMember', currentProjectMember);
currentUser.$inject = ['$cookies', '$timeout']; currentUser.$inject = ['$rootScope'];
function currentUser($cookies, $timeout) { function currentUser($rootScope) {
return { return {
set: function(user) { set: function(user) {
$cookies.putObject('user', user, {'path': '/'}); $rootScope.user = user;
}, },
get: function() { get: function() {
return $cookies.getObject('user'); return $rootScope.user;
}, },
unset: function() { unset: function() {
$cookies.remove('user', {'path': '/'}); delete $rootScope.user;
}
};
}
currentProjectMember.$inject = ['$cookies'];
function currentProjectMember($cookies) {
return {
set: function(member) {
$cookies.putObject('member', member, {'path': '/'});
},
get: function() {
return $cookies.getObject('member');
},
unset: function() {
$cookies.remove('member', {'path': '/'});
} }
}; };
} }

View File

@ -17,7 +17,6 @@
angular angular
.module('harbor.app', [ .module('harbor.app', [
'ngMessages', 'ngMessages',
'ngCookies',
'harbor.session', 'harbor.session',
'harbor.layout.element.height', 'harbor.layout.element.height',
'harbor.layout.header', 'harbor.layout.header',

View File

@ -35,12 +35,11 @@
vm.updateUser = updateUser; vm.updateUser = updateUser;
vm.cancel = cancel; vm.cancel = cancel;
$scope.user = currentUser.get(); $scope.$watch('user', function(current) {
if(!$scope.user) { if(current) {
$window.location.href = '/'; $scope.user = current;
return; }
} });
var userId = $scope.user.user_id;
//Error message dialog handler for account setting. //Error message dialog handler for account setting.
$scope.$on('modalTitle', function(e, val) { $scope.$on('modalTitle', function(e, val) {
@ -77,10 +76,10 @@
vm.confirmOnly = true; vm.confirmOnly = true;
vm.action = vm.confirm; vm.action = vm.confirm;
if(user && angular.isDefined(user.username) && angular.isDefined(user.realname)) { if(user && angular.isDefined(user.username) && angular.isDefined(user.realname)) {
UpdateUserService(userId, user) UpdateUserService($scope.user.user_id, user)
.success(updateUserSuccess) .success(updateUserSuccess)
.error(updateUserFailed); .error(updateUserFailed);
currentUser.set(user); currentUser.set($scope.user);
} }
} }

View File

@ -20,9 +20,9 @@
.module('harbor.layout.change.password') .module('harbor.layout.change.password')
.controller('ChangePasswordController', ChangePasswordController); .controller('ChangePasswordController', ChangePasswordController);
ChangePasswordController.$inject = ['ChangePasswordService', 'UpdateUserService', '$filter', 'trFilter', '$scope', '$window', 'currentUser']; ChangePasswordController.$inject = ['ChangePasswordService', 'UpdateUserService', '$filter', 'trFilter', '$scope', '$window'];
function ChangePasswordController(ChangePasswordService, UpdateUserService, $filter, trFilter, $scope, $window, currentUser) { function ChangePasswordController(ChangePasswordService, UpdateUserService, $filter, trFilter, $scope, $window) {
var vm = this; var vm = this;
vm.isOpen = false; vm.isOpen = false;
@ -36,14 +36,13 @@
vm.updatePassword = updatePassword; vm.updatePassword = updatePassword;
vm.cancel = cancel; vm.cancel = cancel;
$scope.user = currentUser.get(); $scope.$watch('user', function(current) {
if(!$scope.user) { if(current) {
$window.location.href = '/'; $scope.user = current;
return; }
} });
var userId = $scope.user.user_id;
//Error message dialog handler for account setting. //Error message dialog handler for changing password.
$scope.$on('modalTitle', function(e, val) { $scope.$on('modalTitle', function(e, val) {
vm.modalTitle = val; vm.modalTitle = val;
}); });
@ -77,16 +76,16 @@
function updatePassword(user) { function updatePassword(user) {
if(user && angular.isDefined(user.oldPassword) && angular.isDefined(user.password)) { if(user && angular.isDefined(user.oldPassword) && angular.isDefined(user.password)) {
vm.action = vm.confirm; vm.action = vm.confirm;
ChangePasswordService(userId, user.oldPassword, user.password) ChangePasswordService($scope.user.user_id, user.oldPassword, user.password)
.success(changePasswordSuccess) .success(changePasswordSuccess)
.error(changePasswordFailed); .error(changePasswordFailed);
} }
} }
function changePasswordSuccess(data, status) { function changePasswordSuccess(data, status) {
vm.modalTitle = $filter('tr')('change_password', []); vm.modalTitle = $filter('tr')('change_password', []);
vm.modalMessage = $filter('tr')('successful_changed_password', []); vm.modalMessage = $filter('tr')('successful_changed_password', []);
vm.confirmOnly = true;
$scope.$broadcast('showDialog', true); $scope.$broadcast('showDialog', true);
} }

View File

@ -25,7 +25,7 @@
function SignUpController($scope, SignUpService, $window, $filter, trFilter) { function SignUpController($scope, SignUpService, $window, $filter, trFilter) {
var vm = this; var vm = this;
vm.user = {}; $scope.user = {};
vm.signUp = signUp; vm.signUp = signUp;
vm.confirm = confirm; vm.confirm = confirm;
@ -77,6 +77,7 @@
} }
vm.modalTitle = title; vm.modalTitle = title;
vm.modalMessage = message; vm.modalMessage = message;
vm.confirmOnly = true;
$scope.$broadcast('showDialog', true); $scope.$broadcast('showDialog', true);
} }

View File

@ -40,7 +40,7 @@
} }
function getCurrentUserFailed(e){ function getCurrentUserFailed(e){
console.log('Failed to get current user:' + e); console.log('Failed to get current user:' + e.statusText);
LogOutService() LogOutService()
.success(logOutSuccess) .success(logOutSuccess)
.error(logOutFailed); .error(logOutFailed);

View File

@ -1,9 +0,0 @@
/*
AngularJS v1.5.3
(c) 2010-2016 Google, Inc. http://angularjs.org
License: MIT
*/
(function(p,c,n){'use strict';function l(b,a,g){var d=g.baseHref(),k=b[0];return function(b,e,f){var g,h;f=f||{};h=f.expires;g=c.isDefined(f.path)?f.path:d;c.isUndefined(e)&&(h="Thu, 01 Jan 1970 00:00:00 GMT",e="");c.isString(h)&&(h=new Date(h));e=encodeURIComponent(b)+"="+encodeURIComponent(e);e=e+(g?";path="+g:"")+(f.domain?";domain="+f.domain:"");e+=h?";expires="+h.toUTCString():"";e+=f.secure?";secure":"";f=e.length+1;4096<f&&a.warn("Cookie '"+b+"' possibly not set or overflowed because it was too large ("+
f+" > 4096 bytes)!");k.cookie=e}}c.module("ngCookies",["ng"]).provider("$cookies",[function(){var b=this.defaults={};this.$get=["$$cookieReader","$$cookieWriter",function(a,g){return{get:function(d){return a()[d]},getObject:function(d){return(d=this.get(d))?c.fromJson(d):d},getAll:function(){return a()},put:function(d,a,m){g(d,a,m?c.extend({},b,m):b)},putObject:function(d,b,a){this.put(d,c.toJson(b),a)},remove:function(a,k){g(a,n,k?c.extend({},b,k):b)}}}]}]);c.module("ngCookies").factory("$cookieStore",
["$cookies",function(b){return{get:function(a){return b.getObject(a)},put:function(a,c){b.putObject(a,c)},remove:function(a){b.remove(a)}}}]);l.$inject=["$document","$log","$browser"];c.module("ngCookies").provider("$$cookieWriter",function(){this.$get=l})})(window,window.angular);
//# sourceMappingURL=angular-cookies.min.js.map

View File

@ -39,7 +39,6 @@
<script src="/static/vendors/angularjs/angular.min.js"></script> <script src="/static/vendors/angularjs/angular.min.js"></script>
<script src="/static/vendors/angularjs/angular-messages.min.js"></script> <script src="/static/vendors/angularjs/angular-messages.min.js"></script>
<script src="/static/vendors/angularjs/angular-cookies.min.js"></script>
<script src="/static/resources/js/harbor.module.js"></script> <script src="/static/resources/js/harbor.module.js"></script>
<script src="/static/resources/js/harbor.config.js"></script> <script src="/static/resources/js/harbor.config.js"></script>