refstack/refstack-ui/app/app.js
Vladislav Kuzmin 7b48c99fcb Add authentication through openstackid.org
In Refstack's database store only fullname, email and openid.
After sign in refstack backend create session and write it id in cookie.
When UI is opened in browser, Angular try to get info from
/v1/profile. If data about user received then user is authenticated.

Change-Id: Ib2cabc0c6b4de4b2ca1f02cc9e062a6e3550daa0
2015-07-02 16:20:55 +03:00

87 lines
2.6 KiB
JavaScript

/** Main app module where application dependencies are listed. */
var refstackApp = angular.module('refstackApp', [
'ui.router', 'ui.bootstrap', 'cgBusy']);
/**
* Handle application routing. Specific templates and controllers will be
* used based on the URL route.
*/
refstackApp.config([
'$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider) {
'use strict';
$urlRouterProvider.otherwise('/');
$stateProvider.
state('home', {
url: '/',
templateUrl: '/components/home/home.html'
}).
state('about', {
url: '/about',
templateUrl: '/components/about/about.html'
}).
state('capabilities', {
url: '/capabilities',
templateUrl: '/components/capabilities/capabilities.html',
controller: 'capabilitiesController'
}).
state('results', {
url: '/results',
templateUrl: '/components/results/results.html',
controller: 'resultsController'
}).
state('resultsDetail', {
url: '/results/:testID',
templateUrl: '/components/results-report/resultsReport.html',
controller: 'resultsReportController'
}).
state('profile', {
url: '/profile',
templateUrl: '/components/profile/profile.html',
controller: 'profileController'
});
}
]);
/**
* Try to authenticate user
*/
refstackApp.run(['$http', '$rootScope', 'refstackApiUrl',
function($http, $rootScope, refstackApiUrl) {
'use strict';
var profile_url = refstackApiUrl + '/profile';
$http.get(profile_url, {withCredentials: true}).
success(function(data) {
$rootScope.currentUser = data;
}).
error(function() {
$rootScope.currentUser = null;
});
}
]);
/**
* Load config and start up the angular application.
*/
angular.element(document).ready(function () {
'use strict';
var $http = angular.injector(['ng']).get('$http');
function startApp(config) {
// Add config options as constants.
for (var key in config) {
angular.module('refstackApp').constant(key, config[key]);
}
angular.bootstrap(document, ['refstackApp']);
}
$http.get('config.json').success(function (data) {
startApp(data);
}).error(function () {
startApp({});
});
});