Skip to content
Permalink
aa8ed949f2
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
129 lines (116 sloc) 4.17 KB
angular.module('routerApp').controller('homeController', function ($scope, $http, urlService, $q, $state, $cookies, $rootScope) {
/* 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 = {
FName: null,
LName: null,
Address: null,
City: null,
State: null,
Post: null,
Country: null,
Phone: null,
Fax: null,
Email: null,
Company: null,
//SUPPORT REP ID SHOULD BE 0 for NEW customer
SupportRepID: null,
PersonID: null,
CustomerID: null
};
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);
//Unsure of how to handle local host for now
/*
$http.post("http://localhost:3306/api/NewCustomer",sub)
.success(function (data, status, headers, config) {
$scope.messages = 'You are now registered and may now log in. ';
})
.error(function (data, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
});*/
var promise = $http({
method: "post",
url: "http://localhost:3306/api/NewCustomer",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
alert("success");
}).
error(function (error, status, headers, config) {
//alert("failure");
console.log(error);
});
}
$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 */
});