fixing angularjs auth
This commit is contained in:
parent
3ec944392e
commit
dc3a58ff85
|
@ -47,7 +47,7 @@
|
|||
<![endif]-->
|
||||
</head>
|
||||
|
||||
<body class="ng-cloak" >
|
||||
<body ng-app="medform" ng-controller="IndexCtrl">
|
||||
<header data-ng-include="'/modules/core/views/header.client.view.html'"></header>
|
||||
<section class="content">
|
||||
<!-- <section class="container"> -->
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('core').controller('HeaderController', ['$scope', 'Principal', 'Menus', '$state',
|
||||
function($scope, Principal, Menus, $state) {
|
||||
$scope.authentication = Principal;
|
||||
angular.module('core').controller('HeaderController', ['$rootScope','$scope', 'Principal', 'Menus', '$state',
|
||||
function($rootScope, $scope, Auth, Menus, $state) {
|
||||
$rootScope.authentication = Auth;
|
||||
$rootScope.user = {},
|
||||
$scope.isCollapsed = false;
|
||||
$scope.hideNav = false;
|
||||
$scope.menu = Menus.getMenu('topbar');
|
||||
|
||||
Principal.identity().then(function(user){
|
||||
$scope.authentication.user = user;
|
||||
}).then(function(){
|
||||
// Principal.identity().then(function(user){
|
||||
// $rootScope.user = user;
|
||||
// console.log('topbar')
|
||||
// console.log($scope.user);
|
||||
// },
|
||||
// function(error){
|
||||
// console.log(error);
|
||||
// }).then(function(){
|
||||
$scope.signout = function() {
|
||||
// $http.get('/auth/signout').success(function(response) {
|
||||
// $state.go('home');
|
||||
|
@ -17,12 +23,19 @@ angular.module('core').controller('HeaderController', ['$scope', 'Principal', 'M
|
|||
// $scope.error = (error.message || error);
|
||||
// });
|
||||
|
||||
Principal.signout();
|
||||
if( angular.isDefined(response_obj.error) ){
|
||||
$scope.error = response_obj.error;
|
||||
} else{
|
||||
$state.go('home');
|
||||
}
|
||||
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');
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,18 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
angular.module('core').controller('HomeController', ['$scope', 'Principal',
|
||||
function($scope, Principal) {
|
||||
angular.module('core').controller('HomeController', ['$rootScope', '$scope', 'Principal',
|
||||
function($rootScope, $scope, Principal) {
|
||||
// This provides Principal context.
|
||||
$scope.authentication = Principal;
|
||||
// $scope.user = {};
|
||||
|
||||
console.log($scope.authentication.user);
|
||||
Principal.identity().then(function(user){
|
||||
console.log(user);
|
||||
$scope.authentication.user = user;
|
||||
}, function(){
|
||||
console.log('error');
|
||||
});
|
||||
$rootScope.user = $window.user;
|
||||
console.log($rootScope.user);
|
||||
|
||||
// Principal.identity().then(function(user){
|
||||
// console.log(user);
|
||||
// $scope.user = user;
|
||||
// }, function(){
|
||||
// console.log('error');
|
||||
// });
|
||||
// console.log("user.displayName: "+Principal.user()._id);
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ section.hero-section > .jumbotron {
|
|||
background-image: url(http://yourplaceandmine.ie/wp-content/uploads/2014/09/Daingean-meeting-048_13-1080x675.jpg);
|
||||
background-repeat: no-repeat;
|
||||
background-position: 0 50%;
|
||||
background-position-top: 0px;
|
||||
/*background-position-top: 0px;*/
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
|
@ -47,4 +47,5 @@ section.hero-section > .jumbotron {
|
|||
color: white;
|
||||
padding: inherit;
|
||||
height: inherit;
|
||||
width: inherit;
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
</a>
|
||||
</div>
|
||||
<nav class="collapse navbar-collapse" collapse="!isCollapsed" role="navigation">
|
||||
<ul class="nav navbar-nav" data-ng-if="menu.shouldRender(authentication.user);">
|
||||
<ul class="nav navbar-nav" data-ng-if="menu.shouldRender(user);">
|
||||
<li data-ng-repeat="item in menu.items | orderBy: 'position'" data-ng-if="item.shouldRender(authentication.isAuthenticated());" ng-switch="item.menuItemType" ui-route="{{item.uiRoute}}" class="{{item.menuItemClass}}" ng-class="{active: ($uiRoute)}" dropdown="item.menuItemType === 'dropdown'">
|
||||
<a ng-switch-when="dropdown" class="dropdown-toggle" dropdown-toggle>
|
||||
<span data-ng-bind="item.title"></span>
|
||||
|
@ -39,7 +39,7 @@
|
|||
<ul class="nav navbar-nav navbar-right" data-ng-show="authentication.isAuthenticated()">
|
||||
<li class="dropdown" dropdown>
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" dropdown-toggle>
|
||||
<span data-ng-bind="authentication.user.displayName"></span> <b class="caret"></b>
|
||||
<span data-ng-bind="user.displayName"></span> <b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
|
|
|
@ -13,14 +13,14 @@
|
|||
Make beautiful forms in a snap.
|
||||
</p>
|
||||
<br><br> <br><br>
|
||||
<a class="btn btn-info">
|
||||
<a class="btn btn-info" href="/#!/signup">
|
||||
Signup now
|
||||
</a>
|
||||
|
||||
</div>
|
||||
<div class="row" data-ng-if="authentication.isAuthenticated()">
|
||||
<p class="lead">
|
||||
Hi there {{authentication.user.displayName}}
|
||||
Hi there {{user.displayName}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="row" data-ng-if="authentication.isAuthenticated()">
|
||||
|
|
|
@ -12,14 +12,14 @@ angular.module('forms').controller('ViewSubmissionController', ['$scope', '$stat
|
|||
|
||||
// Return all form's submissions
|
||||
$scope.findAll = function() {
|
||||
$scope.submissions = submissions.query({
|
||||
$scope.submissions = Submissions.query({
|
||||
formId: $stateParams.formId
|
||||
});
|
||||
};
|
||||
|
||||
// Find a specific submission
|
||||
$scope.findOne = function() {
|
||||
$scope.submission = submissions.get({
|
||||
$scope.submission = Submissions.get({
|
||||
submissionId: $scope.submissionId,
|
||||
formId: $stateParams.formId
|
||||
});
|
||||
|
|
71
public/modules/index.js
Normal file
71
public/modules/index.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name AvianServer.controller:IndexCtrl
|
||||
* @description
|
||||
* # IndexCtrl
|
||||
* Controller of the AvianServer
|
||||
*/
|
||||
angular.module('AvianServer')
|
||||
.controller('IndexCtrl', function ($scope, $location, User, Auth, $state) {
|
||||
Auth.ensureHasCurrentUser(User);
|
||||
$scope.user = Auth.getUserState();
|
||||
$scope.authorization = Auth;
|
||||
|
||||
|
||||
$scope.login = function() {
|
||||
Auth.currentUser = User.login($scope.credentials,
|
||||
function() {
|
||||
|
||||
// console.log(response);
|
||||
// Auth.currentUser = $rootScope.loginResult.user;
|
||||
Auth.login();
|
||||
|
||||
// console.log( $rootScope.loginResult.user);
|
||||
|
||||
$location.path('home');
|
||||
},
|
||||
function(res) {
|
||||
|
||||
$scope.loginError = res.data.error;
|
||||
console.log(res);
|
||||
|
||||
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.user = User.save($scope.registration,
|
||||
function() {
|
||||
},
|
||||
function(res) {
|
||||
if(res && res.data) {
|
||||
$scope.registerError = res.data.error;
|
||||
}else {
|
||||
console.log('No response received');
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.logout = function() {
|
||||
User.logout(function() {
|
||||
Auth.logout();
|
||||
$state.go('index');
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
});
|
|
@ -3,28 +3,56 @@
|
|||
// Config HTTP Error Handling
|
||||
angular.module('users').config(['$httpProvider',
|
||||
function($httpProvider) {
|
||||
// Set the httpProvider "not authorized" interceptor
|
||||
$httpProvider.interceptors.push(['$q', '$state', 'Principal',
|
||||
function($q, $state, Principal) {
|
||||
return {
|
||||
responseError: function(rejection) {
|
||||
switch (rejection.status) {
|
||||
case 401:
|
||||
// Deauthenticate the global user
|
||||
Principal.authenticate(null);
|
||||
$httpProvider.interceptors.push(function($q, $location) {
|
||||
return {
|
||||
responseError: function(response) {
|
||||
console.log('intercepted rejection of ', response.config.url, response.status);
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
// save the current location so that login can redirect back
|
||||
$location.nextAfterLogin = $location.path();
|
||||
$location.path('/login');
|
||||
}
|
||||
return $q.reject(response);
|
||||
}
|
||||
};
|
||||
});
|
||||
}]);
|
||||
|
||||
// Redirect to signin page
|
||||
$state.go('signin');
|
||||
break;
|
||||
case 403:
|
||||
// Add unauthorized behaviour
|
||||
break;
|
||||
}
|
||||
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
};
|
||||
}
|
||||
]);
|
||||
}
|
||||
]);
|
||||
// Config HTTP Error Handling
|
||||
// angular.module('users').config(['$httpProvider',
|
||||
// function($httpProvider) {
|
||||
// // Set the httpProvider "not authorized" interceptor
|
||||
// $httpProvider.interceptors.push(['$q', '$location', 'Principal',
|
||||
// function($q, $state, Principal) {
|
||||
// return {
|
||||
// responseSuccess: function(response) {
|
||||
// Principal.identity().then(function(user){
|
||||
// console.log(user);
|
||||
// // $rootScope.user = user;
|
||||
// }, function(error){
|
||||
// console.log("Coudn't get current user. \n ERROR: "+error);
|
||||
// });
|
||||
|
||||
// },
|
||||
// responseError: function(rejection) {
|
||||
// switch (rejection.status) {
|
||||
// case 401:
|
||||
// // Deauthenticate the global user
|
||||
// Principal.authenticate(null);
|
||||
|
||||
// // Redirect to signin page
|
||||
// $location.path('/signin');
|
||||
// break;
|
||||
// case 403:
|
||||
// // Add unauthorized behaviour
|
||||
// break;
|
||||
// }
|
||||
|
||||
// return $q.reject(rejection);
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// ]);
|
||||
// }
|
||||
// ]);
|
|
@ -3,13 +3,41 @@
|
|||
// Setting up route
|
||||
angular.module('users').config(['$stateProvider',
|
||||
function($stateProvider) {
|
||||
// Users state routing
|
||||
$stateProvider.
|
||||
|
||||
|
||||
var checkLoggedin = function($q, $timeout, $location, User, Auth) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
console.log(Auth.getUserState);
|
||||
|
||||
if (Auth.currentUser && Auth.currentUser.email) {
|
||||
$timeout(deferred.resolve);
|
||||
}
|
||||
else {
|
||||
Auth.currentUser = User.getCurrent(function() {
|
||||
Auth.login();
|
||||
$timeout(deferred.resolve);
|
||||
},
|
||||
function() {
|
||||
Auth.logout();
|
||||
$timeout(deferred.reject);
|
||||
$location.path('/login');
|
||||
});
|
||||
}
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
// Users state routing
|
||||
$stateProvider.
|
||||
state('profile', {
|
||||
// parent: 'restricted',
|
||||
// data: {
|
||||
// roles: ['user', 'admin'],
|
||||
// },
|
||||
resolve: {
|
||||
loggedin: checkLoggedin
|
||||
},
|
||||
url: '/settings/profile',
|
||||
templateUrl: 'modules/users/views/settings/edit-profile.client.view.html'
|
||||
}).
|
||||
|
@ -18,6 +46,9 @@ angular.module('users').config(['$stateProvider',
|
|||
// data: {
|
||||
// roles: ['user', 'admin'],
|
||||
// },
|
||||
resolve: {
|
||||
loggedin: checkLoggedin
|
||||
},
|
||||
url: '/settings/password',
|
||||
templateUrl: 'modules/users/views/settings/change-password.client.view.html'
|
||||
}).
|
||||
|
@ -26,6 +57,9 @@ angular.module('users').config(['$stateProvider',
|
|||
// data: {
|
||||
// roles: ['user', 'admin'],
|
||||
// },
|
||||
resolve: {
|
||||
loggedin: checkLoggedin
|
||||
},
|
||||
url: '/settings/accounts',
|
||||
templateUrl: 'modules/users/views/settings/social-accounts.client.view.html'
|
||||
}).
|
||||
|
@ -34,6 +68,10 @@ angular.module('users').config(['$stateProvider',
|
|||
url: '/signup',
|
||||
templateUrl: 'modules/users/views/authentication/signup.client.view.html'
|
||||
}).
|
||||
state('signup-success', {
|
||||
url: '/signup-success',
|
||||
templateUrl: 'modules/users/views/authentication/signup.client.view.html'
|
||||
}).
|
||||
state('signin', {
|
||||
url: '/signin',
|
||||
templateUrl: 'modules/users/views/authentication/signin.client.view.html'
|
||||
|
|
|
@ -4,7 +4,6 @@ angular.module('users').controller('AuthenticationController', ['$scope', '$loca
|
|||
function($scope, $location, Principal, $state) {
|
||||
|
||||
$scope.authentication = Principal;
|
||||
// $scope.authentication.user = Principal.getUser();
|
||||
|
||||
// If user is signed in then redirect back home
|
||||
if ($scope.authentication.isAuthenticated()) $state.go('home');
|
||||
|
|
|
@ -12,3 +12,21 @@
|
|||
right: 10px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
section.auth {
|
||||
margin-top: 5em;
|
||||
}
|
||||
section.auth > h3{
|
||||
font-size: 3em;
|
||||
font-weight: 500;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
section.auth.signup-view > h3 {
|
||||
font-size: 4.4em;
|
||||
padding-bottom: 0.5em;
|
||||
}
|
||||
|
||||
section.auth.signup-view.success > h3 {
|
||||
padding-bottom: 1.2em;
|
||||
}
|
52
public/modules/users/services/auth.js
Normal file
52
public/modules/users/services/auth.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('AvianServer')
|
||||
.factory('Auth', function($cookies) {
|
||||
var userState =
|
||||
{
|
||||
// isLoggedIn: $cookies.get('isLoggedIn')
|
||||
isLoggedIn: false
|
||||
};
|
||||
|
||||
return {
|
||||
currentUser: null,
|
||||
|
||||
// Note: we can't make the User a dependency of Auth
|
||||
// because that would create a circular dependency
|
||||
// Auth <- $http <- $resource <- LoopBackResource <- User <- Auth
|
||||
ensureHasCurrentUser: function(User) {
|
||||
if (this.currentUser) {
|
||||
console.log('Using cached current user.');
|
||||
console.log(this.currentUser);
|
||||
} else{
|
||||
console.log('Fetching current user from the server.');
|
||||
this.currentUser = User.getCurrent(function() {
|
||||
// success
|
||||
userState.isLoggedIn = true;
|
||||
$cookies.put('isLoggedIn', 'true');
|
||||
},
|
||||
function(response) {
|
||||
userState.isLoggedIn = false;
|
||||
$cookies.put('isLoggedIn', 'false');
|
||||
console.log('User.getCurrent() err', response);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getUserState: function() {
|
||||
return userState;
|
||||
},
|
||||
|
||||
login: function() {
|
||||
userState.isLoggedIn = true;
|
||||
$cookies.put('isLoggedIn', 'true');
|
||||
this.ensureHasCurrentUser(null);
|
||||
},
|
||||
|
||||
logout: function() {
|
||||
this.currentUser = null;
|
||||
userState.isLoggedIn = false;
|
||||
$cookies.put('isLoggedIn', 'false');
|
||||
},
|
||||
};
|
||||
});
|
|
@ -1,28 +0,0 @@
|
|||
// 'use strict';
|
||||
|
||||
// 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);
|
||||
|
||||
// // 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');
|
||||
// }
|
||||
// // }
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
// }
|
||||
// ]);
|
|
@ -1,163 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('users').factory('Principal', ['$window', '$q', '$timeout', '$http', '$state',
|
||||
function($window, $q, $timeout, $http, $state) {
|
||||
|
||||
var service = {
|
||||
_currentUser: null,
|
||||
|
||||
isIdentityResolved: function() {
|
||||
if(service._currentUser === null) return false;
|
||||
return true;
|
||||
},
|
||||
isAuthenticated: function() {
|
||||
return !!service._currentUser;
|
||||
},
|
||||
isInRole: function(role) {
|
||||
if (!service.isAuthenticated() || !service._currentUser.roles) return false;
|
||||
|
||||
return service._currentUser.roles.indexOf(role) !== -1;
|
||||
},
|
||||
isInAnyRole: function(roles) {
|
||||
if (!service.isAuthenticated() || !service._currentUser.roles) return false;
|
||||
|
||||
for (var i = 0; i < roles.length; i++) {
|
||||
if (this.isInRole(roles[i])) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
authenticate: function(user) {
|
||||
service._currentUser = user;
|
||||
|
||||
// store the user in $window
|
||||
if (user) $window.user = user;
|
||||
else $window.user = null;
|
||||
},
|
||||
signin: function(credentials) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
$http.post('/auth/signin', credentials).success(function(response) {
|
||||
console.log(response);
|
||||
// If successful we assign the response to the global user model
|
||||
service.authenticate(response);
|
||||
deferred.resolve(response);
|
||||
}).error(function(error) {
|
||||
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
signup: function(credentials) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
$http.post('/auth/signup', credentials).success(function(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
deferred.resolve(response);
|
||||
}).error(function(error) {
|
||||
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
signout: function() {
|
||||
var deferred = $q.defer();
|
||||
$http.get('/auth/signout').success(function(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
deferred.resolve(null);
|
||||
service.authenticate(null);
|
||||
}).error(function(error) {
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
resetPassword: function(passwordDetails, token) {
|
||||
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);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
// Submit forgotten password account id
|
||||
askForPasswordReset: function(credentials) {
|
||||
var deferred = $q.defer();
|
||||
$http.post('/auth/forgot', credentials).success(function(response) {
|
||||
// Show user success message and clear form
|
||||
|
||||
deferred.resolve(response);
|
||||
|
||||
}).error(function(error) {
|
||||
// Show user error message
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
identity: function() {
|
||||
|
||||
// if (service.isAuthenticated()) {
|
||||
// return service._currentUser;
|
||||
// } else if($window.user){
|
||||
// service.authenticate($window.user);
|
||||
// return service._currentUser;
|
||||
// }else {
|
||||
// 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;
|
||||
// });
|
||||
// }
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
]);
|
92
public/modules/users/services/user.js
Normal file
92
public/modules/users/services/user.js
Normal file
|
@ -0,0 +1,92 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('users').factory('User', ['$window', '$q', '$timeout', '$http', '$state',
|
||||
function($window, $q, $timeout, $http, $state) {
|
||||
|
||||
|
||||
var userService = {
|
||||
getCurrent: function() {
|
||||
deferred = $q.defer();
|
||||
|
||||
$http.get('/users/me')
|
||||
.success(function(response) {
|
||||
deferred.resolve(response);
|
||||
})
|
||||
.error(function() {
|
||||
deferred.reject("User's session has expired");
|
||||
});
|
||||
},
|
||||
login: function(credentials) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
$http.post('/auth/signin', credentials).success(function(response) {
|
||||
console.log(response);
|
||||
deferred.resolve(response);
|
||||
}).error(function(error) {
|
||||
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
logout: function() {
|
||||
var deferred = $q.defer();
|
||||
$http.get('/auth/signout').success(function(response) {
|
||||
deferred.resolve(null);
|
||||
}).error(function(error) {
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
signup: function(credentials) {
|
||||
|
||||
var deferred = $q.defer();
|
||||
|
||||
$http.post('/auth/signup', credentials).success(function(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
deferred.resolve(response);
|
||||
}).error(function(error) {
|
||||
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
resetPassword: function(passwordDetails, token) {
|
||||
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);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
// Submit forgotten password account id
|
||||
askForPasswordReset: function(credentials) {
|
||||
var deferred = $q.defer();
|
||||
$http.post('/auth/forgot', credentials).success(function(response) {
|
||||
// Show user success message and clear form
|
||||
|
||||
deferred.resolve(response);
|
||||
|
||||
}).error(function(error) {
|
||||
// Show user error message
|
||||
deferred.reject(error.message || error);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
return userService;
|
||||
|
||||
}
|
||||
]);
|
|
@ -1,4 +1,4 @@
|
|||
<section class="row text-center">
|
||||
<section class="row text-center auth">
|
||||
<h3 class="col-md-12">You need to be logged in to access this page</h3>
|
||||
<a href="/#!/sigin" class="col-md-12">Login</a>
|
||||
</section>
|
|
@ -1,4 +1,4 @@
|
|||
<section class="row" data-ng-controller="AuthenticationController">
|
||||
<section class="row auth" data-ng-controller="AuthenticationController">
|
||||
<h3 class="col-md-12 text-center">Sign in with your account</h3>
|
||||
<!-- <div class="col-md-12 text-center">
|
||||
<a href="/auth/facebook" class="undecorated-link">
|
||||
|
@ -18,7 +18,7 @@
|
|||
</a>
|
||||
</div> -->
|
||||
<!-- <h3 class="col-md-12 text-center">Or with your account</h3> -->
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-5 col-md-2">
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<form class="signin form-horizontal" ng-submit="signin()" autocomplete="off">
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
|
|
33
public/modules/users/views/authentication/signup-success.client.view.html
Executable file
33
public/modules/users/views/authentication/signup-success.client.view.html
Executable file
|
@ -0,0 +1,33 @@
|
|||
<section class="row auth signup-view success" data-ng-controller="AuthenticationController">
|
||||
<!-- <h3 class="col-md-12 text-center">Sign up using your social accounts</h3>
|
||||
<div class="col-md-12 text-center">
|
||||
<a href="/auth/facebook" class="undecorated-link">
|
||||
<img src="/modules/users/img/buttons/facebook.png">
|
||||
</a>
|
||||
<a href="/auth/twitter" class="undecorated-link">
|
||||
<img src="/modules/users/img/buttons/twitter.png">
|
||||
</a>
|
||||
<a href="/auth/google" class="undecorated-link">
|
||||
<img src="/modules/users/img/buttons/google.png">
|
||||
</a>
|
||||
<a href="/auth/linkedin" class="undecorated-link">
|
||||
<img src="/modules/users/img/buttons/linkedin.png">
|
||||
</a>
|
||||
<a href="/auth/github" class="undecorated-link">
|
||||
<img src="/modules/users/img/buttons/github.png">
|
||||
</a>
|
||||
</div> -->
|
||||
<h3 class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6 text-center">Signup with your email</h3>
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<h2>Congrats! You've successfully registered an account at MedForms. </h2>
|
||||
<p>Before you continue, make sure to check your email for our verification email. If you don't receive it within 24h drop us a line</p>
|
||||
<ul>
|
||||
<li>
|
||||
Click
|
||||
<em href="#!/">Here</em>
|
||||
to continue
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
18
public/modules/users/views/authentication/signup.client.view.html
Executable file → Normal file
18
public/modules/users/views/authentication/signup.client.view.html
Executable file → Normal file
|
@ -1,5 +1,5 @@
|
|||
<section class="row" data-ng-controller="AuthenticationController">
|
||||
<h3 class="col-md-12 text-center">Sign up using your social accounts</h3>
|
||||
<section class="row auth signup-view" data-ng-controller="AuthenticationController">
|
||||
<!-- <h3 class="col-md-12 text-center">Sign up using your social accounts</h3>
|
||||
<div class="col-md-12 text-center">
|
||||
<a href="/auth/facebook" class="undecorated-link">
|
||||
<img src="/modules/users/img/buttons/facebook.png">
|
||||
|
@ -16,11 +16,15 @@
|
|||
<a href="/auth/github" class="undecorated-link">
|
||||
<img src="/modules/users/img/buttons/github.png">
|
||||
</a>
|
||||
</div>
|
||||
<h3 class="col-md-12 text-center">Or with your email</h3>
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-5 col-md-2">
|
||||
</div> -->
|
||||
<h3 class="col-md-12 text-center">Signup with your email</h3>
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<form name="userForm" data-ng-submit="signup()" class="signin form-horizontal" novalidate autocomplete="off">
|
||||
<fieldset>
|
||||
<div data-ng-show="error" id="signup_errors" class="text-center text-danger">
|
||||
Couldn't submit form due to errors: <br>
|
||||
<strong data-ng-bind="error"></strong>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="firstName">First Name</label>
|
||||
<input type="text" required id="firstName" name="firstName" class="form-control" data-ng-model="credentials.firstName" placeholder="First Name">
|
||||
|
@ -45,9 +49,7 @@
|
|||
<button type="submit" class="btn btn-large btn-primary">Sign up</button> or
|
||||
<a href="/#!/signin" class="show-signup">Sign in</a>
|
||||
</div>
|
||||
<div data-ng-show="error" class="text-center text-danger">
|
||||
<strong data-ng-bind="error"></strong>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<section class="row" data-ng-controller="PasswordController">
|
||||
<section class="auth row" data-ng-controller="PasswordController">
|
||||
<h3 class="col-md-12 text-center">Restore your password</h3>
|
||||
<p class="small text-center">Enter your account username.</p>
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-5 col-md-2">
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<form data-ng-submit="askForPasswordReset()" class="signin form-horizontal" autocomplete="off">
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<section class="row" data-ng-controller="PasswordController">
|
||||
<section class="row auth" data-ng-controller="PasswordController">
|
||||
<h3 class="col-md-12 text-center">Reset your password</h3>
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-5 col-md-2">
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<form data-ng-submit="resetUserPassword()" class="signin form-horizontal" autocomplete="off">
|
||||
<fieldset>
|
||||
<div class="form-group">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<section class="row" data-ng-controller="SettingsController">
|
||||
<section class="row auth" data-ng-controller="SettingsController">
|
||||
<h3 class="col-md-12 text-center">Change your password</h3>
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<form data-ng-submit="changeUserPassword()" class="signin form-horizontal" autocomplete="off">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<section class="row" data-ng-controller="SettingsController">
|
||||
<section class="row auth" data-ng-controller="SettingsController">
|
||||
<h3 class="col-md-12 text-center">Edit your profile</h3>
|
||||
<div class="col-xs-offset-2 col-xs-8 col-md-offset-3 col-md-6">
|
||||
<form name="userForm" data-ng-submit="updateUserProfile(userForm.$valid)" class="signin form-horizontal" autocomplete="off">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<section class="row" data-ng-controller="SettingsController">
|
||||
<section class="row auth" data-ng-controller="SettingsController">
|
||||
<h3 class="col-md-12 text-center" data-ng-show="hasConnectedAdditionalSocialAccounts()">Connected social accounts:</h3>
|
||||
<div class="col-md-12 text-center">
|
||||
<div data-ng-repeat="(providerName, providerData) in user.additionalProvidersData" class="remove-account-container">
|
||||
|
|
Loading…
Reference in a new issue