mirror of
https://github.com/fergalmoran/dss.web.git
synced 2026-02-15 04:25:41 +00:00
Feature finished
This commit is contained in:
@@ -17,20 +17,19 @@ angular.module('dssWebApp', [
|
||||
'angulartics',
|
||||
'ngClipboard',
|
||||
'angular-jwt',
|
||||
'http-auth-interceptor',
|
||||
'angular-smilies',
|
||||
'satellizer',
|
||||
'angulartics.google.analytics'
|
||||
])
|
||||
.config(function ($stateProvider, $sceDelegateProvider, $httpProvider, $urlRouterProvider, $locationProvider, $provide, $authProvider,
|
||||
ngClipProvider, jwtInterceptorProvider, $analyticsProvider, dialogsProvider, DSProvider, DSHttpAdapterProvider,
|
||||
ngClipProvider, $analyticsProvider, dialogsProvider, DSProvider, DSHttpAdapterProvider,
|
||||
SERVER_CONFIG, STORAGE) {
|
||||
$urlRouterProvider
|
||||
.otherwise('/');
|
||||
|
||||
//$httpProvider.defaults.headers.common.Accept = 'application/json';
|
||||
$httpProvider.defaults.useXDomain = true;
|
||||
$httpProvider.interceptors.push('AuthInterceptor');
|
||||
//$httpProvider.interceptors.push('AuthInterceptor');
|
||||
|
||||
$authProvider.baseUrl = SERVER_CONFIG.apiUrl + '/';
|
||||
$authProvider.loginUrl = '_a/';
|
||||
@@ -54,7 +53,9 @@ angular.module('dssWebApp', [
|
||||
url: '_a/?backend=twitter'
|
||||
});
|
||||
$authProvider.google({
|
||||
clientId: '248170132962-5km115budk9h84raa26hdmnnqdj8ivkl.apps.googleusercontent.com'
|
||||
clientId: '248170132962-5km115budk9h84raa26hdmnnqdj8ivkl.apps.googleusercontent.com',
|
||||
redirectUri: 'http://ext-test.deepsouthsounds.com:9000/',
|
||||
url: '/_a/?backend=google',
|
||||
});
|
||||
ngClipProvider.setPath("bower_components/zeroclipboard/dist/ZeroClipboard.swf");
|
||||
|
||||
@@ -105,6 +106,8 @@ angular.module('dssWebApp', [
|
||||
|
||||
//ensure login before state change
|
||||
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
||||
|
||||
/*
|
||||
if (!$rootScope.currentUser && Session.getLocalToken() != null && Session.getBackend()) {
|
||||
LoginService.loginUser().then(function (user) {
|
||||
LoginService.getUserProfile()
|
||||
@@ -130,6 +133,6 @@ angular.module('dssWebApp', [
|
||||
}
|
||||
});
|
||||
event.preventDefault();
|
||||
}
|
||||
}*/
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('dssWebApp')
|
||||
.controller('MainCtrl', function ($scope, $rootScope, $http, $state, dialogs, logger, authService, SocketService, AudioService,
|
||||
.controller('MainCtrl', function ($scope, $rootScope, $http, $state, $auth,
|
||||
dialogs, logger, SocketService, AudioService,
|
||||
MixModel, UserModel, LoginService, Session, SERVER_CONFIG, CHAT_EVENTS, AUTH_EVENTS) {
|
||||
$scope.isAuthorized = LoginService.isAuthorized;
|
||||
$scope.isAuthenticated = LoginService.isAuthenticated;
|
||||
$scope.currentPath = '';
|
||||
$scope.chatVisible = false;
|
||||
$rootScope.isMessaging = false;
|
||||
|
||||
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
|
||||
if ($auth.isAuthenticated()) {
|
||||
LoginService.getUserProfile()
|
||||
.then(function (user) {
|
||||
$rootScope.setCurrentUser(user);
|
||||
$rootScope.connectSockets();
|
||||
return $state.go(toState.name, toParams);
|
||||
});
|
||||
}
|
||||
});
|
||||
$rootScope.safeApply = function (fn) {
|
||||
var phase = this.$root.$$phase;
|
||||
if (phase == '$apply' || phase == '$digest') {
|
||||
@@ -59,20 +69,6 @@ angular.module('dssWebApp')
|
||||
$rootScope.connectSockets();
|
||||
});
|
||||
|
||||
$scope.$on('event:auth-loginRequired', function (rejection) {
|
||||
console.log("Refreshing token");
|
||||
LoginService.getJwtToken(Session.getLocalToken(), Session.getBackend())
|
||||
.then(function (result) {
|
||||
authService.loginConfirmed(result, function (config) {
|
||||
config.headers = config.headers || {};
|
||||
config.headers.Authorization = 'JWT ' + Session.getToken();
|
||||
return config;
|
||||
});
|
||||
}, function (reason, code) {
|
||||
console.error(reason, code);
|
||||
});
|
||||
});
|
||||
|
||||
$scope.setCurrentPath = function (path) {
|
||||
$scope.currentPath = path;
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
'use strict';
|
||||
angular.module('dssWebApp')
|
||||
.factory('AuthInterceptor', function ($q, jwtHelper, Session) {
|
||||
return {
|
||||
request: addToken
|
||||
};
|
||||
function addToken(config) {
|
||||
var token = Session.getToken();
|
||||
if (token) {
|
||||
config.headers = config.headers || {};
|
||||
config.headers.Authorization = 'JWT ' + token;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
});
|
||||
@@ -1,138 +0,0 @@
|
||||
/*global angular:true, browser:true */
|
||||
|
||||
/**
|
||||
* @license HTTP Auth Interceptor Module for AngularJS
|
||||
* (c) 2012 Witold Szczerba
|
||||
* License: MIT
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('http-auth-interceptor', ['http-auth-interceptor-buffer'])
|
||||
|
||||
.factory('authService', ['$rootScope', 'httpBuffer', function ($rootScope, httpBuffer) {
|
||||
return {
|
||||
/**
|
||||
* Call this function to indicate that authentication was successfull and trigger a
|
||||
* retry of all deferred requests.
|
||||
* @param data an optional argument to pass on to $broadcast which may be useful for
|
||||
* example if you need to pass through details of the user that was logged in
|
||||
*/
|
||||
loginConfirmed: function (data, configUpdater) {
|
||||
var updater = configUpdater || function (config) {
|
||||
return config;
|
||||
};
|
||||
$rootScope.$broadcast('event:auth-loginConfirmed', data);
|
||||
httpBuffer.retryAll(updater);
|
||||
},
|
||||
|
||||
/**
|
||||
* Call this function to indicate that authentication should not proceed.
|
||||
* All deferred requests will be abandoned or rejected (if reason is provided).
|
||||
* @param data an optional argument to pass on to $broadcast.
|
||||
* @param reason if provided, the requests are rejected; abandoned otherwise.
|
||||
*/
|
||||
loginCancelled: function (data, reason) {
|
||||
httpBuffer.rejectAll(reason);
|
||||
$rootScope.$broadcast('event:auth-loginCancelled', data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Call this function to make a function onto every object in the httpBuffer
|
||||
* This allows us to modify the requests
|
||||
*/
|
||||
transformRequests: function (func) {
|
||||
httpBuffer.transform(func);
|
||||
}
|
||||
};
|
||||
}])
|
||||
|
||||
/**
|
||||
* $http interceptor.
|
||||
* On 401 response (without 'ignoreAuthModule' option) stores the request
|
||||
* and broadcasts 'event:angular-auth-loginRequired'.
|
||||
*/
|
||||
.config(['$httpProvider', function ($httpProvider) {
|
||||
$httpProvider.interceptors.push(['$rootScope', '$q', 'httpBuffer', function ($rootScope, $q, httpBuffer) {
|
||||
return {
|
||||
responseError: function (rejection) {
|
||||
if ((rejection.status === 401 || rejection.status === 403) && !rejection.config.ignoreAuthModule) {
|
||||
var deferred = $q.defer();
|
||||
httpBuffer.append(rejection.config, deferred);
|
||||
$rootScope.$broadcast('event:auth-loginRequired', rejection);
|
||||
return deferred.promise;
|
||||
}
|
||||
// otherwise, default behaviour
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
|
||||
/**
|
||||
* Private module, a utility, required internally by 'http-auth-interceptor'.
|
||||
*/
|
||||
angular.module('http-auth-interceptor-buffer', [])
|
||||
|
||||
.factory('httpBuffer', ['$injector', function ($injector) {
|
||||
/** Holds all the requests, so they can be re-requested in future. */
|
||||
var buffer = [];
|
||||
|
||||
/** Service initialized later because of circular dependency problem. */
|
||||
var $http;
|
||||
|
||||
function retryHttpRequest(config, deferred) {
|
||||
function successCallback(response) {
|
||||
deferred.resolve(response);
|
||||
}
|
||||
|
||||
function errorCallback(response) {
|
||||
deferred.reject(response);
|
||||
}
|
||||
|
||||
$http = $http || $injector.get('$http');
|
||||
$http(config).then(successCallback, errorCallback);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Appends HTTP request configuration object with deferred response attached to buffer.
|
||||
*/
|
||||
append: function (config, deferred) {
|
||||
buffer.push({
|
||||
config: config,
|
||||
deferred: deferred
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply a function to every call in the buffer array
|
||||
*/
|
||||
transform: function (func) {
|
||||
buffer = buffer.map(func);
|
||||
},
|
||||
|
||||
/**
|
||||
* Abandon or reject (if reason provided) all the buffered requests.
|
||||
*/
|
||||
rejectAll: function (reason) {
|
||||
if (reason) {
|
||||
for (var i = 0; i < buffer.length; ++i) {
|
||||
buffer[i].deferred.reject(reason);
|
||||
}
|
||||
}
|
||||
buffer = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* Retries all the buffered requests clears the buffer.
|
||||
*/
|
||||
retryAll: function (updater) {
|
||||
for (var i = 0; i < buffer.length; ++i) {
|
||||
retryHttpRequest(updater(buffer[i].config), buffer[i].deferred);
|
||||
}
|
||||
buffer = [];
|
||||
}
|
||||
};
|
||||
}]);
|
||||
})();
|
||||
@@ -77,14 +77,11 @@ angular.module('dssWebApp')
|
||||
|
||||
function logoutUser() {
|
||||
var defer = $q.defer();
|
||||
hello.logout(Session.getBackend())
|
||||
.then(function () {
|
||||
Session.destroy();
|
||||
defer.resolve();
|
||||
}, function () {
|
||||
Session.destroy();
|
||||
$auth.logout()
|
||||
.then(function(){
|
||||
defer.resolve();
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -193,8 +193,6 @@
|
||||
<script src="app/routes.js"></script>
|
||||
<script src="app/services/audio/audio.events.js"></script>
|
||||
<script src="app/services/audio/audio.service.js"></script>
|
||||
<script src="app/services/auth/auth.interceptor.js"></script>
|
||||
<script src="app/services/auth/httpInterceptor.js"></script>
|
||||
<script src="app/services/auth/login.events.js"></script>
|
||||
<script src="app/services/auth/login.service.js"></script>
|
||||
<script src="app/services/image/imageupload.service.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user