Skip to content
Permalink
107340c508
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
100 lines (90 sloc) 3.43 KB
angular.module('routerApp').controller('homeController', function ($scope, $http, urlService, $q, $state, $cookies, $rootScope,HolderService) {
/* BEGIN FUNCTIONS FUNCTIONS */
$scope.authenticateAdmin = function (id, pass) {
return $q(function (resolve, reject) {
var param = id + " " + pass;
var promise = $http.post(url + "/authenticateAdmin", param)
.success(function (data) {
if (data.STATUS == 555) {
$scope.authenticated = false;
resolve('We did it');
} else {
$scope.authenticated = true;
resolve('We did it');
}
})
.error(function (data, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
reject('We did not do it');
});
})
}
// Function to register new users.
$scope.createUser = function (newUser) {
// TODO: Make Service fit into things.
var sub = HolderService.getBlankCustomer();
if (newUser.company == null) {
newUser.company = null;
}
sub.FName = newUser.firstName;
sub.LName = newUser.lastName;
sub.Address = newUser.addr;
sub.City = newUser.city;
sub.State = newUser.state;
sub.Post = newUser.postal;
sub.Country = newUser.country;
sub.Phone = newUser.phone;
sub.Fax = newUser.fax;
sub.Email = newUser.email;
sub.Company = newUser.company;
sub.SupportRepID = 0;
console.log(sub);
var promise = $http({
method: "post",
url: "http://localhost:50031/api/NewCustomer",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You are now registered and may now log in. ';
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
});
}
$scope.toAdminPage = function (user) {
//$cookies.put('LOGIN','ADMIN ' + $cookies.get('DEPID') + ' ' + $cookies.get('PWD') )
//var promise = $scope.authenticateAdmin(user.username,user.password);
//promise.then(function(){
// if($scope.authenticated == true){
// $cookies.put('ADMIN',user.username);
//$cookies.put('PWD',user.password);
// $scope.messages = null;
$state.go('admin-home');
//}
// else if ($scope.authenticated == false){
// $scope.messages = 'Incorrect Login Information.';
// }
// });
}
$scope.toUserPage = function (user) {
//$cookies.put('LOGIN','ADMIN ' + $cookies.get('DEPID') + ' ' + $cookies.get('PWD') )
//var promise = $scope.authenticateAdmin(user.username,user.password);
//promise.then(function(){
// if($scope.authenticated == true){
// $cookies.put('ADMIN',user.username);
//$cookies.put('PWD',user.password);
// $scope.messages = null;
$state.go('user-home');
//}
// else if ($scope.authenticated == false){
// $scope.messages = 'Incorrect Login Information.';
// }
// });
}
/* BEGIN LOGIC */
var url = urlService.web;
/* END LOGIC */
});