Started working on a more natural user experience when logged in

parent feefdc9e
......@@ -62,6 +62,7 @@
<script src="scripts/archivingPortalClient.js"></script>
<script src="scripts/services.js"></script>
<script src="scripts/service/LoginService.js"></script>
<script src="scripts/service/UserService.js"></script>
<script src="scripts/service/NationService.js"></script>
<script src="scripts/directives.js"></script>
<script src="scripts/controller/MainController.js"></script>
......
<div class="alert alert-info">
Username: user<br/>
Password: password
<div class="container" ng-hide="loggedIn">
<div class="row">
<div class="col-sm-6 col-md-4 col-md-offset-4">
<img class="img-responsive" src="/images/logo.png">
<h3>Log in<small> to use this service</small></h3>
<form class="form-group">
<input ng-model="login.username" class="form-control" type="text" placeholder="Username" required autofocus>
<input ng-model="login.password" class="form-control" type="password" placeholder="Password"required>
<button class="btn btn-lg btn-info btn-block" type="submit" ng-click="doLogin()">
Sign in</button>
</form>
</div>
</div>
</div>
<div>
<form class="well form-inline">
<h3>Login</h3>
<input ng-model="login.username" type="text" placeholder="Username">
<input ng-model="login.password" type="password" placeholder="Password">
<button type="submit" class="btn" ng-click="doLogin()">Log in</button>
</form>
<div class="container" ng-show="loggedIn">
<div class="row">
<h3>Welcome back <small>{{user.username}}</small></h3>
Contact: {{user.email}}
</div>
</div>
......@@ -9,12 +9,12 @@ var archivingPortalClient = angular.module('archivingPortalClient',
'ngResource',
'ngRoute',
'archivingPortalClient.directives',
'archivingPortalClient.nationService',
'archivingPortalClient.loginService'
'archivingPortalClient.loginService',
'archivingPortalClient.userService',
'archivingPortalClient.nationService'
]);
archivingPortalClient.config(['$routeProvider', function ($routeProvider) {
archivingPortalClient.config(['$routeProvider','$httpProvider', function($routeProvider,$httpProvider) {
$routeProvider.when('/', {
templateUrl: 'partials/main.html',
......@@ -37,29 +37,48 @@ archivingPortalClient.config(['$routeProvider', function ($routeProvider) {
}]);
archivingPortalClient.factory('authHttpResponseInterceptor',['$q','$location','$log' ,function($q, $location, $log){
return {
response: function(response){
if (response.status === 401) {
$log.error("Response 401");
//$rootScope.oauth.access_token = "";
}
return response || $q.when(response);
},
responseError: function(rejection) {
if (rejection.status === 401) {
$log.error("Response Error 401 @ ", rejection);
$location.path('/').search('returnTo', $location.path());
}
return $q.reject(rejection);
}
}
}]);
archivingPortalClient.config(['$httpProvider',function($httpProvider) {
$httpProvider.interceptors.push('authHttpResponseInterceptor');
}]);
archivingPortalClient.run(function ($rootScope) {
$rootScope.portalApiUrl = "http://localhost:8080/";
});
/**
* Oauth Section***
*
* This section deals with the Oauth2 stuff we are using to
* authenticate users to the service.
*/
/**
* Intercept all requests.
* All requests will have their header modified with the Oauth2 access_token if
* one is available in the $rootScope. Note that this scope resets if you refresh.
*/
archivingPortalClient.run(['$rootScope', '$injector', function($rootScope, $injector) {
$injector.get("$http").defaults.transformRequest = function(data, headersGetter) {
if ($rootScope.access_token) headersGetter()['Authorization'] = "Bearer "+$rootScope.access_token;
if (data) {
if($rootScope.oauth) {
headersGetter()['Authorization'] = "Bearer " + $rootScope.oauth.access_token;
}
if(data) {
return angular.toJson(data);
}
};
}]);
......@@ -72,5 +91,3 @@ archivingPortalClient.run(['$rootScope', '$injector', function($rootScope, $inje
* archivingPortalClient.config(['$routeProvider', function ($routeProvider, $locationProvider) {...
* $locationProvider.html5Mode(true);
*/
'use strict';
var MainController = function($scope, $log, $http, LoginService, $rootScope) {
var MainController = function($scope, $log, $http, LoginService, $rootScope, User) {
//Login Form.
$scope.login = {};
//Run only when logging in.
//No pre defined scoped variables.
$scope.doLogin = function() {
if($rootScope.access_token != null) {
$log.info("IM A NOOB!");
}
LoginService.save({username: $scope.login.username, password: $scope.login.password}, function(data) {
$rootScope.access_token = data.access_token;
$log.info(data.access_token);
$rootScope.oauth = data;
$scope.loggedIn = $rootScope.oauth != null;
$scope.user = User.query();
});
}
};
};
......@@ -3,19 +3,6 @@
var ProjectController = function($scope, $log, $http) {
$scope.project = {};
//$scope.dataSet = {};
//$scope.dataSetFile = {};
//$scope.create = function() {
// $http.post($scope.portalApiUrl+'project/create', angular.toJson($scope.project))
// .success(function(result) {
// $log.info(result)
// })
// .error(function (error) {
// $log.error("Unable to post -> " + angular.toJson($scope.project));
// $log.error(error);
// });
//}
$scope.create = function() {
$log.info(angular.toJson($scope.project));
......
'use strict';
var userService = angular.module('archivingPortalClient.userService', ['ngResource']);
userService.factory('User', ['$resource',
function($resource) {
return $resource(apiUrl+'user/get', {}, {
query:{
//params can go here if we got any.
}
});
}
]);
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