Skip to content
Permalink
2736dcd30e
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
89 lines (83 sloc) 3.22 KB
angular.module('routerApp').controller('homeController', function ($scope, $http, urlService, $q, $state, $cookies, $rootScope, HolderService) {
/* BEGIN FUNCTIONS FUNCTIONS */
console.log($cookies.get('userid'));
// Function to register new users.
$scope.createUser = function (newUser) {
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) {
console.log(data);
$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.';
});
}
// Log in admins
$scope.toAdminPage = function (user) {
console.log(user);
console.log(!user.password);
if (!user.password) $scope.messages = "Please enter a password.";
else {
$http.get("http://localhost:50031/api/GetEmployee?PersonID=" + user.username)
.success(function (response) {
if (response.employeeid == 0) {
$scope.messages = 'You have entered an incorrect Employee username';
}
else {
console.log(response);
$cookies.put('userid', user.username);
$cookies.put('name', response.firstname);
$cookies.put('isAdmin', response.isAdmin);
console.log($cookies.get('userid'));
$state.go('admin-home');
}
})
}
}
// Log in Users
$scope.toUserPage = function (user) {
if (!user.password) $scope.messages = "Please enter a password.";
else {
$http.get("http://localhost:50031/api/GetCustomer?PersonID=" + user.username)
.success(function (response) {
if (response.CustomerID == 0) {
$scope.messages = 'You have entered an incorrect User';
}
else {
$cookies.put("userid", user.username);
console.log($cookies.get('userid'));
console.log(response);
$cookies.put('name', response.FName);
$state.go('user-home');
}
})
.error(function (error, status, headers, config) {
$scope.messages = 'We could not find that user in the database.';
});
}
}
});