From 5e8f65738adeb3c7d98445f08753a35e44b4ccc3 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 25 Apr 2016 15:16:49 -0400 Subject: [PATCH] (js) Integrate ngCookies --- UI/WebServerResources/Gruntfile.js | 1 + UI/WebServerResources/bower.json | 1 + .../js/Common/Authentication.service.js | 50 ++++++------------- 3 files changed, 17 insertions(+), 35 deletions(-) diff --git a/UI/WebServerResources/Gruntfile.js b/UI/WebServerResources/Gruntfile.js index 5232d719e..1da04ac98 100644 --- a/UI/WebServerResources/Gruntfile.js +++ b/UI/WebServerResources/Gruntfile.js @@ -132,6 +132,7 @@ module.exports = function(grunt) { '<%= src %>/angular-animate/angular-animate{,.min}.js{,.map}', '<%= src %>/angular-sanitize/angular-sanitize{,.min}.js{,.map}', '<%= src %>/angular-aria/angular-aria{,.min}.js{,.map}', + '<%= src %>/angular-cookies/angular-cookies{,.min}.js{,.map}', '<%= src %>/angular-messages/angular-messages{,.min}.js{,.map}', '<%= src %>/angular-material/angular-material{,.min}.js{,.map}', '<%= src %>/angular-ui-router/release/angular-ui-router{,.min}.js', diff --git a/UI/WebServerResources/bower.json b/UI/WebServerResources/bower.json index 93566fac5..fb9a327e5 100644 --- a/UI/WebServerResources/bower.json +++ b/UI/WebServerResources/bower.json @@ -5,6 +5,7 @@ "angular": "1.4.x", "angular-animate": "1.4.x", "angular-aria": "1.4.x", + "angular-cookies": "1.4.x", "angular-messages": "1.4.x", "angular-sanitize": "1.4.x", "angular-ui-router": "latest", diff --git a/UI/WebServerResources/js/Common/Authentication.service.js b/UI/WebServerResources/js/Common/Authentication.service.js index 556239129..5401fd99e 100644 --- a/UI/WebServerResources/js/Common/Authentication.service.js +++ b/UI/WebServerResources/js/Common/Authentication.service.js @@ -5,7 +5,7 @@ /* jshint validthis: true */ 'use strict'; - angular.module('SOGo.Authentication', []) + angular.module('SOGo.Authentication', ['ngCookies']) .constant('passwordPolicyConfig', { PolicyPasswordChangeUnsupported: -3, @@ -23,41 +23,9 @@ PolicyNoError: 65535 }) - // TODO: convert to a Factory recipe? .provider('Authentication', Authentication); function Authentication() { - function readCookie(name) { - var foundCookie, prefix, pairs, i, currentPair, start; - foundCookie = null; - prefix = name + '='; - pairs = document.cookie.split(';'); - for (i = 0; !foundCookie && i < pairs.length; i++) { - currentPair = pairs[i]; - start = 0; - while (currentPair.charAt(start) == ' ') - start++; - if (start > 0) - currentPair = currentPair.substr(start); - if (currentPair.indexOf(prefix) === 0) - foundCookie = currentPair.substr(prefix.length); - } - - return foundCookie; - } - - function readLoginCookie() { - var loginValues = null, - cookie = readCookie('0xHIGHFLYxSOGo'), - value; - if (cookie && cookie.length > 8) { - value = decodeURIComponent(cookie.substr(8)); - loginValues = value.base64decode().split(':'); - } - - return loginValues; - } - function redirectUrl(username, domain) { var userName, address, baseAddress, altBaseAddress, parts, hostpart, protocol, newAddress; @@ -91,10 +59,22 @@ /** * @ngInject */ - getService.$inject = ['$q', '$http', 'passwordPolicyConfig']; - function getService($q, $http, passwordPolicyConfig) { + getService.$inject = ['$q', '$http', '$cookies', 'passwordPolicyConfig']; + function getService($q, $http, $cookies, passwordPolicyConfig) { var service; + function readLoginCookie() { + var loginValues = null, + cookie = $cookies.get('0xHIGHFLYxSOGo'), + value; + if (cookie && cookie.length > 8) { + value = decodeURIComponent(cookie.substr(8)); + loginValues = value.base64decode().split(':'); + } + + return loginValues; + } + service = { login: function(data) { var d = $q.defer(),