got new auth to start working
This commit is contained in:
parent
dc3a58ff85
commit
d6b64187ab
3
config/env/all.js
vendored
3
config/env/all.js
vendored
|
@ -65,7 +65,8 @@ module.exports = {
|
|||
'public/lib/angular-ui-router/release/angular-ui-router.js',
|
||||
'public/lib/angular-ui-utils/ui-utils.js',
|
||||
'public/lib/angular-bootstrap/ui-bootstrap-tpls.js',
|
||||
'public/lib/ng-file-upload/ng-file-upload-all.js'
|
||||
'public/lib/ng-file-upload/ng-file-upload-all.js',
|
||||
'public/lib/angular-cookies/angular-cookies.js',
|
||||
]
|
||||
},
|
||||
css: [
|
||||
|
|
|
@ -9,8 +9,8 @@ angular.module(ApplicationConfiguration.applicationModuleName).config(['$locatio
|
|||
$locationProvider.hashPrefix('!');
|
||||
}
|
||||
]);
|
||||
angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', 'Principal',
|
||||
function($rootScope, Principal) {
|
||||
angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope',
|
||||
function($rootScope) {
|
||||
$rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) {
|
||||
// track the state the user wants to go to; authorization service needs this
|
||||
$rootScope.toState = toState;
|
||||
|
|
|
@ -14,7 +14,7 @@ angular.module('core').config(['$stateProvider', '$urlRouterProvider',
|
|||
});
|
||||
|
||||
$urlRouterProvider.otherwise( function($injector) {
|
||||
var $state = $injector.get("$state");
|
||||
var $state = $injector.get('$state');
|
||||
$state.go('home');
|
||||
});
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('core').controller('HeaderController', ['$rootScope','$scope', 'Principal', 'Menus', '$state',
|
||||
function($rootScope, $scope, Auth, Menus, $state) {
|
||||
$rootScope.authentication = Auth;
|
||||
$rootScope.user = {},
|
||||
angular.module('core').controller('HeaderController', ['$rootScope','$scope','Menus', '$state',
|
||||
function($rootScope, $scope, Menus, $state) {
|
||||
// $rootScope.authentication = Auth;
|
||||
// $rootScope.user = {},
|
||||
$scope.isCollapsed = false;
|
||||
$scope.hideNav = false;
|
||||
$scope.menu = Menus.getMenu('topbar');
|
||||
|
@ -16,28 +16,28 @@ angular.module('core').controller('HeaderController', ['$rootScope','$scope', 'P
|
|||
// function(error){
|
||||
// console.log(error);
|
||||
// }).then(function(){
|
||||
$scope.signout = function() {
|
||||
// $scope.signout = function() {
|
||||
// $http.get('/auth/signout').success(function(response) {
|
||||
// $state.go('home');
|
||||
// }).error(function(error) {
|
||||
// $scope.error = (error.message || error);
|
||||
// });
|
||||
|
||||
Principal.signout().then(
|
||||
function(result){
|
||||
$state.go('home');
|
||||
},
|
||||
function(error){
|
||||
$scope.error = (error.message || error);
|
||||
}
|
||||
);
|
||||
// Principal.signout().then(
|
||||
// function(result){
|
||||
// $state.go('home');
|
||||
// },
|
||||
// function(error){
|
||||
// $scope.error = (error.message || error);
|
||||
// }
|
||||
// );
|
||||
// if( angular.isDefined(response_obj.error) ){
|
||||
// $scope.error = response_obj.error;
|
||||
// } else{
|
||||
// $state.go('home');
|
||||
// }
|
||||
|
||||
};
|
||||
// };
|
||||
|
||||
$scope.toggleCollapsibleMenu = function() {
|
||||
$scope.isCollapsed = !$scope.isCollapsed;
|
||||
|
@ -54,7 +54,7 @@ angular.module('core').controller('HeaderController', ['$rootScope','$scope', 'P
|
|||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
// });
|
||||
|
||||
}
|
||||
]);
|
|
@ -1,13 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
angular.module('core').controller('HomeController', ['$rootScope', '$scope', 'Principal',
|
||||
function($rootScope, $scope, Principal) {
|
||||
angular.module('core').controller('HomeController', ['$rootScope', '$scope',
|
||||
function($rootScope, $scope) {
|
||||
// This provides Principal context.
|
||||
$scope.authentication = Principal;
|
||||
// $scope.authentication = Principal;
|
||||
// $scope.user = {};
|
||||
|
||||
$rootScope.user = $window.user;
|
||||
// $rootScope.user = $window.user;
|
||||
console.log($rootScope.user);
|
||||
|
||||
// Principal.identity().then(function(user){
|
||||
|
|
|
@ -2,50 +2,51 @@
|
|||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name AvianServer.controller:IndexCtrl
|
||||
* @name medform.controller:IndexCtrl
|
||||
* @description
|
||||
* # IndexCtrl
|
||||
* Controller of the AvianServer
|
||||
* Controller of core
|
||||
*/
|
||||
angular.module('AvianServer')
|
||||
.controller('IndexCtrl', function ($scope, $location, User, Auth, $state) {
|
||||
Auth.ensureHasCurrentUser(User);
|
||||
$scope.user = Auth.getUserState();
|
||||
$scope.authorization = Auth;
|
||||
angular.module('medform').controller('IndexCtrl', function ($scope, $rootScope, $location, User, Auth, $state) {
|
||||
$rootScope.user = Auth.ensureHasCurrentUser(User);
|
||||
// $rootScope.user = Auth.getUserState(User).user;
|
||||
$rootScope.authorization = Auth;
|
||||
|
||||
|
||||
$scope.login = function() {
|
||||
$scope.signin = function() {
|
||||
Auth.currentUser = User.login($scope.credentials,
|
||||
function() {
|
||||
function(response) {
|
||||
|
||||
// console.log(response);
|
||||
// Auth.currentUser = $rootScope.loginResult.user;
|
||||
Auth.login();
|
||||
$rootScope.user = Auth.ensureHasCurrentUser(User);
|
||||
|
||||
// console.log( $rootScope.loginResult.user);
|
||||
|
||||
$location.path('home');
|
||||
$location.path('listForms');
|
||||
},
|
||||
function(res) {
|
||||
|
||||
$scope.loginError = res.data.error;
|
||||
console.log(res);
|
||||
console.log('loginError: '+res.data.error);
|
||||
$rootScope.user = Auth.ensureHasCurrentUser(User);
|
||||
|
||||
if(!$scope.loginError){
|
||||
// if(!$scope.loginError){
|
||||
// Auth.currentUser = rootScope.loginResult.user;
|
||||
// console.log(Auth.currentUser );
|
||||
}
|
||||
// }
|
||||
|
||||
// Auth.currentUser = $rootScope.loginResult.user;
|
||||
}
|
||||
);-
|
||||
);
|
||||
|
||||
console.log(Auth.currentUser);
|
||||
// Auth.currentUser = $rootScope.loginResult;
|
||||
|
||||
};
|
||||
|
||||
$scope.register = function() {
|
||||
$scope.signup = function() {
|
||||
$scope.user = User.save($scope.registration,
|
||||
function() {
|
||||
},
|
||||
|
@ -59,11 +60,12 @@ angular.module('AvianServer')
|
|||
);
|
||||
};
|
||||
|
||||
$scope.logout = function() {
|
||||
$scope.signout = function() {
|
||||
User.logout(function() {
|
||||
Auth.logout();
|
||||
$state.go('index');
|
||||
$scope.$apply();
|
||||
$rootScope.user = null;
|
||||
$state.go('home');
|
||||
// $scope.$apply();
|
||||
});
|
||||
};
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('forms').controller('EditFormController', ['$scope', '$state', 'Upload', '$stateParams', 'Principal', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location',
|
||||
function ($scope, $state, Upload, $stateParams, Principal, FormFields, Forms, CurrentForm, $modal, $location) {
|
||||
angular.module('forms').controller('EditFormController', ['$scope', '$state', 'Upload', '$stateParams', 'FormFields', 'Forms', 'CurrentForm', '$modal', '$location',
|
||||
function ($scope, $state, Upload, $stateParams, FormFields, Forms, CurrentForm, $modal, $location) {
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.authentication.user = user;
|
||||
// }).then(function(){
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
// Forms controller
|
||||
angular.module('forms').controller('SubmitFormController', ['$scope', '$stateParams', '$state', 'Principal', 'Forms', 'CurrentForm',
|
||||
function($scope, $stateParams, $state, Principal, Forms, CurrentForm) {
|
||||
angular.module('forms').controller('SubmitFormController', ['$scope', '$stateParams', '$state', 'Forms', 'CurrentForm',
|
||||
function($scope, $stateParams, $state, Forms, CurrentForm) {
|
||||
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.authentication.user = user;
|
||||
|
|
|
@ -1,63 +1,63 @@
|
|||
'use strict';
|
||||
// 'use strict';
|
||||
|
||||
angular.module('users').controller('AuthenticationController', ['$scope', '$location', 'Principal', '$state',
|
||||
function($scope, $location, Principal, $state) {
|
||||
// angular.module('users').controller('AuthenticationController', ['$scope', '$location', '$state',
|
||||
// function($scope, $location, $state) {
|
||||
|
||||
$scope.authentication = Principal;
|
||||
// // $scope.authentication = Principal;
|
||||
|
||||
// If user is signed in then redirect back home
|
||||
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
||||
// // If user is signed in then redirect back home
|
||||
// if ($scope.authentication.isAuthenticated()) $state.go('home');
|
||||
|
||||
$scope.signup = function() {
|
||||
Principal.signup($scope.credentials).then(
|
||||
function(result){
|
||||
$state.go('home');
|
||||
},
|
||||
function(rejection_reason){
|
||||
$scope.error = rejection_reason;
|
||||
}
|
||||
);
|
||||
// $http.post('/auth/signup', $scope.credentials).success(function(response) {
|
||||
// // If successful we assign the response to the global user model
|
||||
// $scope.authentication.user = response;
|
||||
// Principal.authenticate(response);
|
||||
// $scope.signup = function() {
|
||||
// Principal.signup($scope.credentials).then(
|
||||
// function(result){
|
||||
// $state.go('home');
|
||||
// },
|
||||
// function(rejection_reason){
|
||||
// $scope.error = rejection_reason;
|
||||
// }
|
||||
// );
|
||||
// // $http.post('/auth/signup', $scope.credentials).success(function(response) {
|
||||
// // // If successful we assign the response to the global user model
|
||||
// // $scope.authentication.user = response;
|
||||
// // Principal.authenticate(response);
|
||||
|
||||
// // And redirect to the index page
|
||||
// $location.path('/');
|
||||
// }).error(function(response) {
|
||||
// $scope.error = response.message;
|
||||
// });
|
||||
};
|
||||
// // // And redirect to the index page
|
||||
// // $location.path('/');
|
||||
// // }).error(function(response) {
|
||||
// // $scope.error = response.message;
|
||||
// // });
|
||||
// };
|
||||
|
||||
$scope.signin = function() {
|
||||
console.log('signin');
|
||||
// $scope.signin = function() {
|
||||
// console.log('signin');
|
||||
|
||||
Principal.signin($scope.credentials).then(
|
||||
function(result){
|
||||
$state.go('home');
|
||||
},
|
||||
function(rejection_reason){
|
||||
$scope.error = rejection_reason;
|
||||
}
|
||||
);
|
||||
// var response_obj = Principal.signin($scope.credentials);
|
||||
// if( angular.isDefined(response_obj.error) ){
|
||||
// $scope.error = response_obj.error;
|
||||
// $location.path('/signin');
|
||||
// } else{
|
||||
// $location.path('/');
|
||||
// }
|
||||
// $http.post('/auth/signin', $scope.credentials).success(function(response) {
|
||||
// // If successful we assign the response to the global user model
|
||||
// $scope.authentication.user = response;
|
||||
// Principal.authenticate(response);
|
||||
// Principal.signin($scope.credentials).then(
|
||||
// function(result){
|
||||
// $state.go('home');
|
||||
// },
|
||||
// function(rejection_reason){
|
||||
// $scope.error = rejection_reason;
|
||||
// }
|
||||
// );
|
||||
// // var response_obj = Principal.signin($scope.credentials);
|
||||
// // if( angular.isDefined(response_obj.error) ){
|
||||
// // $scope.error = response_obj.error;
|
||||
// // $location.path('/signin');
|
||||
// // } else{
|
||||
// // $location.path('/');
|
||||
// // }
|
||||
// // $http.post('/auth/signin', $scope.credentials).success(function(response) {
|
||||
// // // If successful we assign the response to the global user model
|
||||
// // $scope.authentication.user = response;
|
||||
// // Principal.authenticate(response);
|
||||
|
||||
// // And redirect to the index page
|
||||
// $location.path('/');
|
||||
// }).error(function(response) {
|
||||
// Principal.authenticate(null);
|
||||
// $scope.error = response.message;
|
||||
// });
|
||||
};
|
||||
}
|
||||
]);
|
||||
// // // And redirect to the index page
|
||||
// // $location.path('/');
|
||||
// // }).error(function(response) {
|
||||
// // Principal.authenticate(null);
|
||||
// // $scope.error = response.message;
|
||||
// // });
|
||||
// };
|
||||
// }
|
||||
// ]);
|
|
@ -1,18 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'Principal',
|
||||
function($scope, $stateParams, $state, Principal) {
|
||||
$scope.authentication = Principal;
|
||||
angular.module('users').controller('PasswordController', ['$scope', '$stateParams', '$state', 'User',
|
||||
function($scope, $stateParams, $state, User) {
|
||||
// $scope.authentication = Principal;
|
||||
|
||||
//If user is signed in then redirect back home
|
||||
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
||||
|
||||
Principal.identity().then(function(response){
|
||||
$scope.authentication.user = response;
|
||||
// Principal.identity().then(function(response){
|
||||
// $scope.authentication.user = response;
|
||||
|
||||
// Submit forgotten password account id
|
||||
$scope.askForPasswordReset = function() {
|
||||
Principal.askForPasswordReset($scope.credentials).then(
|
||||
User.askForPasswordReset($scope.credentials).then(
|
||||
function(response){
|
||||
$scope.success = response.message;
|
||||
$scope.credentials = null;
|
||||
|
@ -27,7 +27,7 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
|
|||
// Change user password
|
||||
$scope.resetUserPassword = function() {
|
||||
$scope.success = $scope.error = null;
|
||||
Principal.resetPassword($scope.passwordDetails, $stateParams.token).then(
|
||||
User.resetPassword($scope.passwordDetails, $stateParams.token).then(
|
||||
function(response){
|
||||
// If successful show success message and clear form
|
||||
$scope.success = response.message;
|
||||
|
@ -56,6 +56,6 @@ angular.module('users').controller('PasswordController', ['$scope', '$stateParam
|
|||
// $scope.error = response.message;
|
||||
// });
|
||||
};
|
||||
});
|
||||
// });
|
||||
}
|
||||
]);
|
|
@ -1,12 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('users').controller('SettingsController', ['$scope', '$http', '$state', 'Users', 'Principal',
|
||||
function($scope, $http, $state, Users, Principal) {
|
||||
angular.module('users').controller('SettingsController', ['$scope', '$http', '$state', 'Users',
|
||||
function($scope, $http, $state, Users) {
|
||||
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.user = user;
|
||||
// }).then(function(){
|
||||
$scope.user = Principal.identity();
|
||||
// $scope.user = Principal.identity();
|
||||
|
||||
// If user is not signed in then redirect back home
|
||||
if (!$scope.user) $state.go('home');
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('AvianServer')
|
||||
.factory('Auth', function($cookies) {
|
||||
angular.module('users')
|
||||
.factory('Auth', function() {
|
||||
var userState =
|
||||
{
|
||||
// isLoggedIn: $cookies.get('isLoggedIn')
|
||||
isLoggedIn: false
|
||||
// user: null
|
||||
};
|
||||
|
||||
return {
|
||||
|
@ -18,35 +19,37 @@ angular.module('AvianServer')
|
|||
if (this.currentUser) {
|
||||
console.log('Using cached current user.');
|
||||
console.log(this.currentUser);
|
||||
return this.currentUser;
|
||||
} else{
|
||||
console.log('Fetching current user from the server.');
|
||||
this.currentUser = User.getCurrent(function() {
|
||||
// success
|
||||
userState.isLoggedIn = true;
|
||||
$cookies.put('isLoggedIn', 'true');
|
||||
// $cookies.put('isLoggedIn', 'true');
|
||||
return this.currentUser;
|
||||
},
|
||||
function(response) {
|
||||
userState.isLoggedIn = false;
|
||||
$cookies.put('isLoggedIn', 'false');
|
||||
// $cookies.put('isLoggedIn', 'false');
|
||||
console.log('User.getCurrent() err', response);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getUserState: function() {
|
||||
getUserState: function(user) {
|
||||
// userState.user = ensureHasCurrentUser(user);
|
||||
return userState;
|
||||
},
|
||||
|
||||
login: function() {
|
||||
userState.isLoggedIn = true;
|
||||
$cookies.put('isLoggedIn', 'true');
|
||||
this.ensureHasCurrentUser(null);
|
||||
login: function(user) {
|
||||
// userState.isLoggedIn = true;
|
||||
// $cookies.put('isLoggedIn', 'true');
|
||||
this.ensureHasCurrentUser(user);
|
||||
},
|
||||
|
||||
logout: function() {
|
||||
this.currentUser = null;
|
||||
userState.isLoggedIn = false;
|
||||
$cookies.put('isLoggedIn', 'false');
|
||||
this.ensureHasCurrentUser(null);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', '
|
|||
|
||||
var userService = {
|
||||
getCurrent: function() {
|
||||
deferred = $q.defer();
|
||||
var deferred = $q.defer();
|
||||
|
||||
$http.get('/users/me')
|
||||
.success(function(response) {
|
||||
|
@ -15,6 +15,8 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', '
|
|||
.error(function() {
|
||||
deferred.reject("User's session has expired");
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
login: function(credentials) {
|
||||
|
||||
|
@ -57,9 +59,6 @@ angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', '
|
|||
var deferred = $q.defer();
|
||||
$http.get('/auth/password/'+token, passwordDetails).success(function(response) {
|
||||
|
||||
// Attach user profile
|
||||
service.authenticate(response);
|
||||
|
||||
deferred.resolve();
|
||||
}).error(function(error) {
|
||||
deferred.reject(error.message || error);
|
||||
|
|
Loading…
Reference in a new issue