got authentication working
This commit is contained in:
parent
ebca4591fa
commit
0045f3d9cb
|
@ -134,7 +134,7 @@ FormSchema.pre('save', function (next) {
|
|||
|
||||
//Convert types from FDF to 'FormField' types
|
||||
if(_typeConvMap[ field.fieldType+'' ]){
|
||||
field.fieldType = _pdfConvMap[ field.fieldType+'' ];
|
||||
field.fieldType = _typeConvMap[ field.fieldType+'' ];
|
||||
}
|
||||
|
||||
field.created = Date.now();
|
||||
|
|
|
@ -10,12 +10,12 @@ module.exports = function(app) {
|
|||
var users = require('../../app/controllers/users.server.controller');
|
||||
|
||||
// Setting up the users profile api
|
||||
app.route('/users/me').get(users.me);
|
||||
app.route('/users').put(users.update);
|
||||
app.route('/users/accounts').delete(users.removeOAuthProvider);
|
||||
app.route('/users/me').get(users.requiresLogin, users.me);
|
||||
app.route('/users').put(users.requiresLogin, users.update);
|
||||
app.route('/users/accounts').delete(users.requiresLogin, users.removeOAuthProvider);
|
||||
|
||||
// Setting up the users password api
|
||||
app.route('/users/password').post(users.changePassword);
|
||||
app.route('/users/password').post(users.requiresLogin, users.changePassword);
|
||||
app.route('/auth/forgot').post(users.forgot);
|
||||
app.route('/auth/reset/:token').get(users.validateResetToken);
|
||||
app.route('/auth/reset/:token').post(users.reset);
|
||||
|
|
16
data1435634800654.fdf
Normal file
16
data1435634800654.fdf
Normal file
|
@ -0,0 +1,16 @@
|
|||
%FDF-1.2
|
||||
%âãÏÓ
|
||||
1 0 obj
|
||||
<<
|
||||
/FDF
|
||||
<<
|
||||
/Fields []
|
||||
>>
|
||||
>>
|
||||
endobj
|
||||
trailer
|
||||
|
||||
<<
|
||||
/Root 1 0 R
|
||||
>>
|
||||
%%EOF
|
|
@ -9,15 +9,15 @@ angular.module(ApplicationConfiguration.applicationModuleName).config(['$locatio
|
|||
$locationProvider.hashPrefix('!');
|
||||
}
|
||||
]);
|
||||
angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', 'Authorization', 'Principal',
|
||||
function($rootScope, Authorization, Principal) {
|
||||
angular.module(ApplicationConfiguration.applicationModuleName).run(['$rootScope', 'Principal',
|
||||
function($rootScope, Principal) {
|
||||
$rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) {
|
||||
// track the state the user wants to go to; authorization service needs this
|
||||
$rootScope.toState = toState;
|
||||
$rootScope.toStateParams = toStateParams;
|
||||
// if the principal is resolved, do an authorization check immediately. otherwise,
|
||||
// it'll be done when the state it resolved.
|
||||
if (Principal.isIdentityResolved()) Authorization.authorize();
|
||||
// if (Principal.isIdentityResolved()) Authorization.authorize();
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
|
|
@ -7,9 +7,10 @@ angular.module('core').controller('HeaderController', ['$scope', 'Principal', 'M
|
|||
$scope.hideNav = false;
|
||||
$scope.menu = Menus.getMenu('topbar');
|
||||
|
||||
Principal.identity().then(function(user){
|
||||
$scope.authentication.user = user;
|
||||
}).then(function(){
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.authentication.user = user;
|
||||
// }).then(function(){
|
||||
$scope.authentication.user = Principal.identity();
|
||||
$scope.signout = function() {
|
||||
var response_obj = Principal.signout();
|
||||
if( angular.isDefined(response_obj.error) ){
|
||||
|
@ -34,7 +35,7 @@ angular.module('core').controller('HeaderController', ['$scope', 'Principal', 'M
|
|||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
// });
|
||||
|
||||
}
|
||||
]);
|
|
@ -5,10 +5,15 @@ angular.module('core').controller('HomeController', ['$scope', 'Principal',
|
|||
function($scope, Principal) {
|
||||
// This provides Principal context.
|
||||
$scope.authentication = Principal;
|
||||
$scope.authentication.user = undefined;
|
||||
Principal.identity().then(function(user){
|
||||
$scope.authentication.user = user;
|
||||
});
|
||||
$scope.authentication.user = Principal.identity();
|
||||
|
||||
console.log($scope.authentication.user);
|
||||
// Principal.identity().then(function(user){
|
||||
// console.log(user);
|
||||
// $scope.authentication.user = user;
|
||||
// }, function(){
|
||||
// console.log('error');
|
||||
// });
|
||||
// console.log("user.displayName: "+Principal.user()._id);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,13 +10,14 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$http
|
|||
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
||||
|
||||
$scope.signup = function() {
|
||||
var response_obj = Principal.signup($scope.credentials);
|
||||
|
||||
if( angular.isDefined(response_obj.error) ){
|
||||
$scope.error = response_obj.error;
|
||||
} else{
|
||||
$state.go('home');
|
||||
}
|
||||
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;
|
||||
|
@ -30,13 +31,22 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$http
|
|||
|
||||
$scope.signin = function() {
|
||||
console.log('signin');
|
||||
var response_obj = Principal.signin($scope.credentials);
|
||||
if( angular.isDefined(response_obj.error) ){
|
||||
$scope.error = response_obj.error;
|
||||
$location.path('/signin');
|
||||
} else{
|
||||
$location.path('/');
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
angular.module('users').controller('SettingsController', ['$scope', '$http', '$state', 'Users', 'Principal',
|
||||
function($scope, $http, $state, Users, Principal) {
|
||||
|
||||
Principal.identity().then(function(user){
|
||||
$scope.user = user;
|
||||
}).then(function(){
|
||||
// Principal.identity().then(function(user){
|
||||
// $scope.user = user;
|
||||
// }).then(function(){
|
||||
$scope.user = Principal.identity();
|
||||
|
||||
// If user is not signed in then redirect back home
|
||||
if (!$scope.user) $state.go('home');
|
||||
|
@ -71,6 +72,6 @@ angular.module('users').controller('SettingsController', ['$scope', '$http', '$s
|
|||
});
|
||||
};
|
||||
|
||||
});
|
||||
// });
|
||||
}
|
||||
]);
|
|
@ -1,28 +1,28 @@
|
|||
'use strict';
|
||||
// 'use strict';
|
||||
|
||||
angular.module('users').service('Authorization', ['$rootScope', '$location', 'Principal',
|
||||
function($rootScope, $location, Principal) {
|
||||
// angular.module('users').service('Authorization', ['$rootScope', '$location', 'Principal',
|
||||
// function($rootScope, $location, Principal) {
|
||||
|
||||
this.authorize = function() {
|
||||
return Principal.identity().then(function(){
|
||||
var isAuthenticated = Principal.isAuthenticated();
|
||||
if( angular.isDefined($rootScope.toState.data) ){
|
||||
// if ($rootScope.toState.data.roles && $rootScope.toState.data.roles.length > 0 && !principal.isInAnyRole($rootScope.toState.data.roles)) {
|
||||
if (!isAuthenticated){ //$location.path('/access_denied'); // user is signed in but not authorized for desired state
|
||||
// console.log('isAuthenticated: '+isAuthenticated);
|
||||
// this.authorize = function() {
|
||||
// return Principal.identity().then(function(){
|
||||
// var isAuthenticated = Principal.isAuthenticated();
|
||||
// if( angular.isDefined($rootScope.toState.data) ){
|
||||
// // if ($rootScope.toState.data.roles && $rootScope.toState.data.roles.length > 0 && !principal.isInAnyRole($rootScope.toState.data.roles)) {
|
||||
// if (!isAuthenticated){ //$location.path('/access_denied'); // user is signed in but not authorized for desired state
|
||||
// // console.log('isAuthenticated: '+isAuthenticated);
|
||||
|
||||
// else {
|
||||
// user is not authenticated. so the state they wanted before you
|
||||
// send them to the signin state, so you can return them when you're done
|
||||
$rootScope.returnToState = $rootScope.toState;
|
||||
$rootScope.returnToStateParams = $rootScope.toStateParams;
|
||||
// // else {
|
||||
// // user is not authenticated. so the state they wanted before you
|
||||
// // send them to the signin state, so you can return them when you're done
|
||||
// $rootScope.returnToState = $rootScope.toState;
|
||||
// $rootScope.returnToStateParams = $rootScope.toStateParams;
|
||||
|
||||
// now, send them to the signin state so they can log in
|
||||
$location.path('/signin');
|
||||
}
|
||||
// }
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
]);
|
||||
// // now, send them to the signin state so they can log in
|
||||
// $location.path('/signin');
|
||||
// }
|
||||
// // }
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
// ]);
|
|
@ -2,23 +2,24 @@
|
|||
|
||||
angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeout', '$state',
|
||||
function($window, $http, $q, $timeout, $state) {
|
||||
var _identity,
|
||||
_authenticated = false;
|
||||
|
||||
return {
|
||||
var service = {
|
||||
_currentUser: null,
|
||||
|
||||
isIdentityResolved: function() {
|
||||
return angular.isDefined(_identity);
|
||||
if(service._currentUser === null) return false
|
||||
return true;
|
||||
},
|
||||
isAuthenticated: function() {
|
||||
return _authenticated;
|
||||
return !!service._currentUser;
|
||||
},
|
||||
isInRole: function(role) {
|
||||
if (!_authenticated || !_identity.roles) return false;
|
||||
if (!service.isAuthenticated() || !service._currentUser.roles) return false;
|
||||
|
||||
return _identity.roles.indexOf(role) !== -1;
|
||||
return service._currentUser.roles.indexOf(role) !== -1;
|
||||
},
|
||||
isInAnyRole: function(roles) {
|
||||
if (!_authenticated || !_identity.roles) return false;
|
||||
if (!service.isAuthenticated() || !service._currentUser.roles) return false;
|
||||
|
||||
for (var i = 0; i < roles.length; i++) {
|
||||
if (this.isInRole(roles[i])) return true;
|
||||
|
@ -27,24 +28,23 @@ angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeou
|
|||
return false;
|
||||
},
|
||||
authenticate: function(user) {
|
||||
_identity = user;
|
||||
_authenticated = (user !== null);
|
||||
|
||||
// for this demo, we'll store the identity in localStorage. For you, it could be a cookie, sessionStorage, whatever
|
||||
service._currentUser = user;
|
||||
|
||||
// store the user in $window
|
||||
if (user) $window.user = user;
|
||||
else $window.user = null;
|
||||
},
|
||||
signin: function(credentials) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
var self = this;
|
||||
$http.post('/auth/signin', credentials).success(function(response) {
|
||||
console.log(response);
|
||||
// If successful we assign the response to the global user model
|
||||
self.authenticate(response);
|
||||
service.authenticate(response);
|
||||
deferred.resolve(response);
|
||||
}).error(function(response) {
|
||||
_authenticated = false;
|
||||
deferred.resolve({ error: response.message });
|
||||
}).error(function(error) {
|
||||
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
@ -55,9 +55,9 @@ angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeou
|
|||
$http.post('/auth/signup', credentials).success(function(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
deferred.resolve(response);
|
||||
}).error(function(response) {
|
||||
}).error(function(error) {
|
||||
|
||||
deferred.resolve({ error: response.message });
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
|
@ -66,63 +66,66 @@ angular.module('users').factory('Principal', ['$window', '$http', '$q', '$timeou
|
|||
var deferred = $q.defer();
|
||||
$http.get('/auth/signout').success(function(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
deferred.resolve({});
|
||||
}).error(function(response) {
|
||||
deferred.resolve({ error: response.message });
|
||||
deferred.resolve(null);
|
||||
service.authenticate(null);
|
||||
}).error(function(error) {
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
_authenticated = false;
|
||||
_identity = undefined;
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
identity: function(force) {
|
||||
var self = this;
|
||||
identity: function() {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (force === true) _identity = undefined;
|
||||
|
||||
// check and see if we have retrieved the user data from the server. if we have, reuse it by immediately resolving
|
||||
if (angular.isDefined(_identity)) {
|
||||
|
||||
deferred.resolve(_identity);
|
||||
return deferred.promise;
|
||||
}else if($window.user){
|
||||
// console.log($window.user);
|
||||
// self.authenticate($window.user);
|
||||
// var user = $window.user;
|
||||
_identity = $window.user;
|
||||
self.authenticate(_identity);
|
||||
deferred.resolve(_identity);
|
||||
|
||||
return deferred.promise;
|
||||
if (service.isAuthenticated()) {
|
||||
return service._currentUser;
|
||||
} else if($window.user){
|
||||
service.authenticate($window.user);
|
||||
return service._currentUser;
|
||||
}else {
|
||||
|
||||
// otherwise, retrieve the user data from the server, update the user object, and then resolve.
|
||||
$http.get('/users/me', { ignoreErrors: true })
|
||||
.success(function(response) {
|
||||
self.authenticate(response);
|
||||
$window.user = response;
|
||||
deferred.resolve(_identity);
|
||||
})
|
||||
.error(function() {
|
||||
_identity = null;
|
||||
_authenticated = false;
|
||||
$window.user = null;
|
||||
$state.path('signin');
|
||||
deferred.resolve(_identity);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
return $http.get('/user/me')
|
||||
.success(function(response) {
|
||||
service.authenticate(response.data.user);
|
||||
return response.data.user;
|
||||
})
|
||||
.error(function() {
|
||||
service.authenticate(null);
|
||||
// $state.go('signin');
|
||||
return null;
|
||||
});
|
||||
}
|
||||
},
|
||||
getUser: function(){
|
||||
this.identity(false).then( function(user){
|
||||
return user;
|
||||
});
|
||||
|
||||
// var deferred = $q.defer();
|
||||
|
||||
// console.log($window.user);
|
||||
// console.log(service.isAuthenticated());
|
||||
|
||||
// // check and see if we have retrieved the user data from the server. if we have, reuse it by immediately resolving
|
||||
// if (service.isAuthenticated() === true ) {
|
||||
// deferred.resolve(service.currentUser);
|
||||
// }else if($window.user){
|
||||
|
||||
// service.authenticate($window.user);
|
||||
// deferred.resolve(service._currentUser);
|
||||
// }else {
|
||||
|
||||
// // otherwise, retrieve the user data from the server, update the user object, and then resolve.
|
||||
// $http.get('/users/me')
|
||||
// .success(function(response) {
|
||||
// service.authenticate(response);
|
||||
// deferred.resolve(response);
|
||||
// })
|
||||
// .error(function() {
|
||||
// service.authenticate(null);
|
||||
// deferred.reject("User's session has expired");
|
||||
// });
|
||||
// }
|
||||
|
||||
// return deferred.promise;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return service;
|
||||
|
||||
}
|
||||
]);
|
||||
|
|
BIN
uploads/pdfs/snthsnthsnth_submission_1435632549359.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632549359.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435632661000.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632661000.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435632781061.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632781061.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435632856522.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632856522.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435632957499.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632957499.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435632962281.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435632962281.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435633073378.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435633073378.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435633149735.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435633149735.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435633184152.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435633184152.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435633203001.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435633203001.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435633260318.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435633260318.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435633896176.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435633896176.pdf
Normal file
Binary file not shown.
BIN
uploads/pdfs/snthsnthsnth_submission_1435634016101.pdf
Normal file
BIN
uploads/pdfs/snthsnthsnth_submission_1435634016101.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435634600171.pdf
Normal file
BIN
uploads/tmp/1435634600171.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435634785530.pdf
Normal file
BIN
uploads/tmp/1435634785530.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435634989526.pdf
Normal file
BIN
uploads/tmp/1435634989526.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435635144882.pdf
Normal file
BIN
uploads/tmp/1435635144882.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435635243340.pdf
Normal file
BIN
uploads/tmp/1435635243340.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435635881310.pdf
Normal file
BIN
uploads/tmp/1435635881310.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435636804671.pdf
Normal file
BIN
uploads/tmp/1435636804671.pdf
Normal file
Binary file not shown.
BIN
uploads/tmp/1435637027799.pdf
Normal file
BIN
uploads/tmp/1435637027799.pdf
Normal file
Binary file not shown.
Loading…
Reference in a new issue