Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Working Registration & User Information edits
  • Loading branch information
adl13006 committed Nov 25, 2015
1 parent c154073 commit 107340c
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 73 deletions.
39 changes: 5 additions & 34 deletions TeamDBAwesome/TeamDBAwesome/js/homeController.js
@@ -1,4 +1,4 @@
angular.module('routerApp').controller('homeController', function ($scope, $http, urlService, $q, $state, $cookies, $rootScope) {
angular.module('routerApp').controller('homeController', function ($scope, $http, urlService, $q, $state, $cookies, $rootScope,HolderService) {

/* BEGIN FUNCTIONS FUNCTIONS */

Expand All @@ -25,28 +25,10 @@ angular.module('routerApp').controller('homeController', function ($scope, $http
// 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
};

var sub = HolderService.getBlankCustomer();
if (newUser.company == null) {
newUser.company = null;
}

sub.FName = newUser.firstName;
sub.LName = newUser.lastName;
sub.Address = newUser.addr;
Expand All @@ -61,31 +43,20 @@ angular.module('routerApp').controller('homeController', function ($scope, $http
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",
url: "http://localhost:50031/api/NewCustomer",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
alert("success");
$scope.messages = 'You are now registered and may now log in. ';
}).
error(function (error, status, headers, config) {
//alert("failure");
console.log(error);
$scope.messages = 'There was a network error. Try again later.';
});
}

Expand Down
103 changes: 67 additions & 36 deletions TeamDBAwesome/TeamDBAwesome/js/userController.js
@@ -1,39 +1,70 @@
// The user controller will deal with
angular.module('routerApp').controller('userController', function($q,$window, $scope,$state, $stateParams, $location, $http, $cookies, urlService,$rootScope) {
/* Retrieve Url */
var url = urlService.web;
$location.hash("top");
$scope.COOKIE = $cookies.getAll();
angular.module('routerApp').controller('userController', function ($q, $window, $scope, $state, $stateParams, $location, $http, $cookies, urlService, $rootScope, HolderService) {
/* Retrieve Url */
var url = urlService.web;
$location.hash("top");
$scope.COOKIE = $cookies.getAll();

/* Begin Function Definitions */
$scope.authenticateUser = function(id,pass){
return $q(function(resolve,reject){
var param = id + " " + pass;
var promise = $http.post(url + "/authenticateUser",param)
.success(function(data,status) {
console.log(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');
});
})
}
// Customer Information Editing
// Retrieve Data
$scope.getUserInfo = function () {
var customerid = 1;
$scope.user = {};
$http.get("http://localhost:50031/api/GetCustomer?PersonID=" + customerid)
.success(function (response) {
$scope.user = angular.copy(response);
console.log($scope.user);
console.log(response);
})
}
// Update User Information
$scope.updateUser = function () {
console.log("Update User");
var promise = $http({
method: "post",
url: "http://localhost:50031/api/NewCustomer",
headers: {
contentType: "application/json"
},
data: $scope.user
}).
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.logout = function(){
$scope.messages = 'You have been logged out.';
$cookies.remove("PWD");
$cookies.remove("DEPID");
$cookies.remove('LOGIN');
$state.go('user');
}
/* Begin Function Definitions */
$scope.authenticateUser = function (id, pass) {
return $q(function (resolve, reject) {
var param = id + " " + pass;
var promise = $http.post(url + "/authenticateUser", param)
.success(function (data, status) {
console.log(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');
});
})
}

$scope.logout = function () {
$scope.messages = 'You have been logged out.';
$cookies.remove("PWD");
$cookies.remove("DEPID");
$cookies.remove('LOGIN');
$state.go('user');
}

$scope.myData = [
{
Expand All @@ -54,10 +85,10 @@ angular.module('routerApp').controller('userController', function($q,$window, $s
"company": "Fuelton",
"employed": false
}
];
];

/* End Function Definitions */
/* End Function Definitions */

/* Begin Logic */
/* Begin Logic */

});
67 changes: 64 additions & 3 deletions TeamDBAwesome/TeamDBAwesome/pages/user-account.html
@@ -1,6 +1,67 @@
<div data-ng-controller="userController"><a id="top"></a>
<div data-ng-controller="userController" data-ng-init="getUserInfo()"><a id="top"></a>

<h1> Account Settings Change here </h1>
<div id="grid1" ui-grid="{ data: myData }" class="grid"></div>
<div class="col-md-6 col-md-offset-3">
<h2>Your Account Information</h2>
<div ng-show="messages" class="alert alert-danger">{{messages}}</div>
<form name="form" role="form">
<div class="form-group" ng-class="{ 'has-error': form.firstName.$dirty && form.firstName.$error.required }">
<label for="username">First name</label>
<input type="text" name="firstName" id="firstName" class="form-control" ng-model="user.FName" required />
<span ng-show="form.firstName.$dirty && form.firstName.$error.required" class="help-block">First name is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.lastName.$dirty && form.lastName.$error.required }">
<label for="username">Last name</label>
<input type="text" name="lastName" id="Text1" class="form-control" ng-model="user.LName" required />
<span ng-show="form.lastName.$dirty && form.lastName.$error.required" class="help-block">Last name is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.addr.$dirty && form.addr.$error.required }">
<label for="addr">Address</label>
<input type="text" name="addr" id="addr" class="form-control" ng-model="user.Address" required />
<span ng-show="form.addr.$dirty && form.addr.$error.required" class="help-block">Address is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.city.$dirty && form.city.$error.required }">
<label for="city">City</label>
<input type="text" name="city" id="city" class="form-control" ng-model="user.City" required />
<span ng-show="form.city.$dirty && form.city.$error.required" class="help-block">City is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.state.$dirty && form.state.$error.required }">
<label for="state">State</label>
<input type="text" name="state" id="state" class="form-control" ng-model="user.State" required />
<span ng-show="form.state.$dirty && form.state.$error.required" class="help-block">State is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.country.$dirty && form.country.$error.required }">
<label for="country">Country</label>
<input type="text" name="country" id="country" class="form-control" ng-model="user.Country" required />
<span ng-show="form.country.$dirty && form.country.$error.required" class="help-block">Country is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.postal.$dirty && form.postal.$error.required }">
<label for="postal">Zip Code</label>
<input type="text" name="postal" id="postal" class="form-control" ng-model="user.Post" required />
<span ng-show="form.postal.$dirty && form.postal.$error.required" class="help-block">Postal is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.phone.$dirty && form.phone.$error.required }">
<label for="phone">Phone Number</label>
<input type="text" name="phone" id="phone" class="form-control" ng-model="user.Phone" required />
<span ng-show="form.phone.$dirty && form.phone.$error.required" class="help-block">Phone number is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.fax.$dirty && form.fax.$error.required }">
<label for="fax">Fax Number</label>
<input type="text" name="fax" id="fax" class="form-control" ng-model="user.Fax" required />
<span ng-show="form.fax.$dirty && form.fax.$error.required" class="help-block">Fax number is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.email.$dirty && form.email.$error.required }">
<label for="email">Email</label>
<input type="text" name="email" id="email" class="form-control" ng-model="user.Email" required />
<span ng-show="form.email.$dirty && form.email.$error.required" class="help-block">Email is required</span>
</div>
<div class="form-group">
<label for="company">Company name (Optional)</label>
<input type="text" name="company" id="company" class="form-control" ng-model="user.Company" />
</div>
<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="updateUser(user)" class="btn btn-primary">Submit Changes</button>
</div>
</form>
</div>

</div>

0 comments on commit 107340c

Please sign in to comment.