2015-07-01 23:14:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('users').controller('AuthenticationController', ['$scope', '$location', '$state', '$rootScope', 'User', 'Auth',
|
|
|
|
function($scope, $location, $state, $rootScope, User, Auth) {
|
|
|
|
|
2015-07-27 18:11:43 +00:00
|
|
|
$scope = $rootScope;
|
|
|
|
$scope.credentials = {};
|
2015-08-25 21:33:52 +00:00
|
|
|
$scope.error = '';
|
2015-07-01 23:14:39 +00:00
|
|
|
|
2015-07-27 18:11:43 +00:00
|
|
|
$scope.signin = function() {
|
2015-07-28 22:29:07 +00:00
|
|
|
User.login($scope.credentials).then(
|
2015-07-27 18:11:43 +00:00
|
|
|
function(response) {
|
|
|
|
Auth.login(response);
|
|
|
|
$scope.user = $rootScope.user = Auth.ensureHasCurrentUser(User);
|
2015-07-01 23:14:39 +00:00
|
|
|
|
2015-07-28 22:29:07 +00:00
|
|
|
if($state.previous.name !== 'home' && $state.previous.name !== 'verify' && $state.previous.name !== ''){
|
2015-07-27 18:11:43 +00:00
|
|
|
$state.go($state.previous.name);
|
|
|
|
}else{
|
2015-07-28 22:29:07 +00:00
|
|
|
$state.go('listForms');
|
2015-07-27 18:11:43 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
function(error) {
|
|
|
|
$rootScope.user = Auth.ensureHasCurrentUser(User);
|
|
|
|
$scope.user = $rootScope.user;
|
2015-07-01 23:14:39 +00:00
|
|
|
|
2015-07-27 18:11:43 +00:00
|
|
|
$scope.error = error;
|
|
|
|
console.log('loginError: '+error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2015-07-01 23:14:39 +00:00
|
|
|
|
2015-07-27 18:11:43 +00:00
|
|
|
$scope.signup = function() {
|
2016-03-30 01:16:36 +00:00
|
|
|
console.log($scope.credentials);
|
2015-07-27 18:11:43 +00:00
|
|
|
User.signup($scope.credentials).then(
|
2015-08-25 21:33:52 +00:00
|
|
|
function(response) {
|
|
|
|
console.log('signup-success');
|
|
|
|
$state.go('signup-success');
|
|
|
|
},
|
|
|
|
function(error) {
|
2015-09-15 22:21:49 +00:00
|
|
|
console.log('Error: ');
|
|
|
|
console.log(error);
|
2015-08-25 21:33:52 +00:00
|
|
|
if(error) {
|
|
|
|
$scope.error = error;
|
|
|
|
console.log(error);
|
|
|
|
}else {
|
|
|
|
console.log('No response received');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-07-27 18:11:43 +00:00
|
|
|
};
|
2015-07-01 23:14:39 +00:00
|
|
|
|
|
|
|
}
|
2016-03-30 01:16:36 +00:00
|
|
|
]);
|