Skip to content
Permalink
be7c2bce84
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
80 lines (71 sloc) 2.73 KB
angular.module('routerApp').controller('homeController', function ($scope, $http, urlService, $q, $state, $cookies, $rootScope, HolderService) {
/* BEGIN FUNCTIONS FUNCTIONS */
// 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) {
// we need a get employee
if (!angular.isNumber(user.username)) $scope.messages = 'Please enter your person number';
/* $http.get("http://localhost:50031/api/GetCustomer?PersonID=" + user.username)
.success(function (response) {
if (response.employeeID == null) {
$scope.messages = 'You have entered an incorrect Employee username';
}
else {*/
$cookies.put('userid', user.username);
console.log($cookies.get('userid'));
$state.go('admin-home');
//}
//})
}
$scope.toUserPage = function (user) {
if (!angular.isNumber(user.username)) $scope.messages = 'Please enter your person number';
$http.get("http://localhost:50031/api/GetCustomer?PersonID=" + user.username)
.success(function (response) {
console.log(response);
if (response.customerID == null) {
$scope.messages = 'You have entered an incorrect User';
}
else {
$cookies.put("userid", user.username);
console.log($cookies.get('userid'));
$state.go('user-home');
}
})
}
/* BEGIN LOGIC */
var url = urlService.web;
/* END LOGIC */
});