GitLab oppdateres til siste versjon den 21.08.2019 ifra 08:00/08:30. Oppdatering estimert til å ta omtrent 20/30+ minutter.

fixes #4505

parent e55d20cb
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
Sign in</button> Sign in</button>
</form> </form>
</div> </div>
<div class="col-sm-6 col-md-4 col-md-offset-4">
<div class="alert alert-warning" role="alert"><span class="glyphicon glyphicon-info-sign"></span>
Username and password are filled in by default.
</div>
</div>
</div> </div>
</div> </div>
...@@ -19,6 +24,4 @@ ...@@ -19,6 +24,4 @@
Contact: {{user.email}} Contact: {{user.email}}
</div> </div>
</div> </div>
{{rejection}}
...@@ -20,6 +20,10 @@ var archivingPortalClient = angular.module('archivingPortalClient', ...@@ -20,6 +20,10 @@ var archivingPortalClient = angular.module('archivingPortalClient',
'archivingPortalClient.projectService' 'archivingPortalClient.projectService'
]); ]);
archivingPortalClient.run(function ($rootScope) {
$rootScope.portalApiUrl = "http://localhost:8080/";
});
/** /**
* Define all routes, partials and controllers in the application. * Define all routes, partials and controllers in the application.
* Every new "place" has to be added here for Angular to pick up on it. * Every new "place" has to be added here for Angular to pick up on it.
...@@ -28,12 +32,12 @@ archivingPortalClient.config(['$routeProvider', function($routeProvider) { ...@@ -28,12 +32,12 @@ archivingPortalClient.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', { $routeProvider.when('/', {
templateUrl: 'partials/main.html', templateUrl: 'partials/main.html',
controller: MainController, controller: MainController
}); });
$routeProvider.when('/project', { $routeProvider.when('/project', {
templateUrl: 'partials/project.html', templateUrl: 'partials/project.html',
controller: ProjectController, controller: ProjectController
}); });
$routeProvider.otherwise({ $routeProvider.otherwise({
...@@ -46,7 +50,7 @@ archivingPortalClient.config(['$routeProvider', function($routeProvider) { ...@@ -46,7 +50,7 @@ archivingPortalClient.config(['$routeProvider', function($routeProvider) {
* Redirect to login if 401 is returned by the service. * Redirect to login if 401 is returned by the service.
* A 401 means no access, and it is neccessary to re-authenticate. * A 401 means no access, and it is neccessary to re-authenticate.
*/ */
archivingPortalClient.factory('authHttpResponseInterceptor',['$q','$location','$log' ,function($q, $location, $log){ archivingPortalClient.factory('authHttpResponseInterceptor',['$q','$location','$log', '$rootScope' ,function($q, $location, $log, $rootScope){
return { return {
response: function(response){ response: function(response){
if (response.status === 401) { if (response.status === 401) {
...@@ -57,8 +61,8 @@ archivingPortalClient.factory('authHttpResponseInterceptor',['$q','$location','$ ...@@ -57,8 +61,8 @@ archivingPortalClient.factory('authHttpResponseInterceptor',['$q','$location','$
}, },
responseError: function(rejection) { responseError: function(rejection) {
if (rejection.status === 401) { if (rejection.status === 401) {
$log.error("Response Error 401 @ ", rejection); $log.error(rejection);
$location.path('/').search('returnTo', $location.path()); $location.path('/');
} }
return $q.reject(rejection); return $q.reject(rejection);
...@@ -89,24 +93,16 @@ archivingPortalClient.config(['$httpProvider',function($httpProvider) { ...@@ -89,24 +93,16 @@ archivingPortalClient.config(['$httpProvider',function($httpProvider) {
}); });
}]); }]);
archivingPortalClient.run(function ($rootScope) {
$rootScope.portalApiUrl = "http://localhost:8080/";
});
/** /**
* Intercept all requests. * Intercept all requests.
* All requests will have their header modified with the Oauth2 access_token if * All requests will have their header modified with the Oauth2 access_token if
* one is available in the $rootScope. Note that this scope resets on page refresh. * one is available in the $rootScope. Note that this scope resets on page refresh.
*/ */
archivingPortalClient.run(['$rootScope', '$injector', 'LoginService', function($rootScope, $injector, LoginService) { archivingPortalClient.run(['$rootScope', '$injector', 'TokenService', '$log', function($rootScope, $injector, TokenService) {
LoginService.save({username: 'admin', password: 'password'}, function(data) {
$rootScope.oauth = data;
});
$injector.get("$http").defaults.transformRequest = function(data, headersGetter) { $injector.get("$http").defaults.transformRequest = function(data, headersGetter) {
if($rootScope.oauth) { if(TokenService.getToken()) {
headersGetter()['Authorization'] = "Bearer " + $rootScope.oauth.access_token; headersGetter()['Authorization'] = "Bearer " + TokenService.getToken();
} }
if(data) { if(data) {
return angular.toJson(data); return angular.toJson(data);
......
'use strict'; 'use strict';
var MainController = function($scope, $log, $http, LoginService, $rootScope, User) { var MainController = function($scope, User, LoginService, TokenService) {
//Login Form. //Login Form.
$scope.login = {}; $scope.login = {};
// Leave a default username and password while developing.
$scope.login.username = 'user';
$scope.login.password = 'password';
//Run only when logging in. $scope.loggedIn = TokenService.isLoggedIn();
//No pre defined scoped variables. $scope.user = User.query();
// Runs when someone clicks "Sign in".
$scope.doLogin = function() { $scope.doLogin = function() {
LoginService.save({username: $scope.login.username, password: $scope.login.password}, function(data) { LoginService.save({username: $scope.login.username, password: $scope.login.password}, function(data) {
$rootScope.oauth = data; TokenService.setToken(data);
$scope.loggedIn = $rootScope.oauth; $scope.loggedIn = TokenService.getToken();
$scope.user = User.query(); $scope.user = User.query(); //Set up for first time use. When returning, it will fire from the normal scope.
}); });
}; };
}; };
...@@ -22,3 +22,38 @@ loginService.factory('LoginService', function ($resource, $http) { ...@@ -22,3 +22,38 @@ loginService.factory('LoginService', function ($resource, $http) {
} }
}); });
}); });
/**
* Simple factory to contain token information.
* The incapsulation performed here has absolutely zero real world implications
* in regards to security, but it just feels good to pretend we are working with
* actual objects and abstracting it away from the global scope is a win.
*/
loginService.factory('TokenService', function() {
var token = {};
// Set a new JWT
token.setToken = function(atoken) {
token = atoken;
};
// Get the access_token
token.getToken = function() {
return token.access_token;
};
// Get the refresh_token. Useful for expired session.
// TODO: Consider removing refresh_token's from the backend all together...
token.getRefreshToken = function() {
return token.refresh_token;
};
// Dirty check to see if a user is logged in.
token.isLoggedIn = function() {
return !!token.hasOwnProperty("access_token");
};
return token;
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment