Skip to content

Commit cb27b3b

Browse files
committed
controller for myAccount ok
1 parent b61c2cc commit cb27b3b

File tree

12 files changed

+1064
-62
lines changed

12 files changed

+1064
-62
lines changed

Diff for: Zenergy/Zenergy/Controllers/ApiControllers/membersController.cs

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313

1414
namespace Zenergy.Controllers.ApiControllers
1515
{
16-
<<<<<<< HEAD
17-
18-
=======
19-
>>>>>>> origin/accountManagement
2016
[Authorize]
2117
public class membersController : ApiController
2218
{

Diff for: Zenergy/Zenergy/Pages/accountManagement.html

+16-17
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,32 @@ <h2>My account</h2>
66
<div name="formInformation" class="col-md-3 col-lg-offset-4">
77
<h1>Change informations</h1>
88
<form ng-submit="changeInformations()">
9-
<!--
109
<div class="form-group">
11-
<input type="email" class="form-control" ng-model="user.mail" placeholder="Email"required>{{user.mail}}</input>
12-
</div>
13-
-->
14-
<div class="form-group">
15-
<input type="text" class="form-control" ng-model="user.firstName" placeholder="Firstname" value="{{user.firstname}}">
10+
<input type="text" class="form-control" ng-model="user.firstName" placeholder="Firstname" value="{{user.firstName}}">
1611
</div>
1712

1813
<div class="form-group">
19-
<input type="text" class="form-control" ng-model="user.lastName" placeholder="Lastname">{{user.Lastname}}</input>
14+
<input type="text" class="form-control" ng-model="user.lastName" placeholder="Lastname" value="{{user.lastName}}">
2015
</div>
2116

2217
<div class="form-group">
23-
<input type="text" class="form-control" ng-model="user.adr1" placeholder="Address">{{user.adr1}}</input>
18+
<input type="text" class="form-control" ng-model="user.adr1" placeholder="Address" value="{{user.adr1}}">
2419
</div>
2520

2621
<div class="form-group">
27-
<input type="text" class="form-control" ng-model="user.adr2" placeholder="Rest of the address ">{{user.adr2}}</input>
22+
<input type="text" class="form-control" ng-model="user.adr2" placeholder="Rest of the address " value="{{user.adr2}}">
2823
</div>
2924

3025
<div class="form-group">
31-
<input type="text" class="form-control" ng-model="user.pc" placeholder="Postal Code ">{{user.pc}}</input>
26+
<input type="text" class="form-control" ng-model="user.pc" placeholder="Postal Code " value="{{user.pc}}">
3227
</div>
3328

3429
<div class="form-group">
35-
<input type="text" class="form-control" ng-model="user.town" placeholder="Town ">{{user.town}}</input>
30+
<input type="text" class="form-control" ng-model="user.town" placeholder="Town " value="{{user.town}}">
3631
</div>
3732

3833
<div class="form-group">
39-
<input type="text" class="form-control" ng-model="user.phone" placeholder="Phone ">{{user.phone}}</input>
34+
<input type="text" class="form-control" ng-model="user.phone" placeholder="Phone " value="{{user.phone}}">
4035
</div>
4136

4237
<button type="button" id="cancel" class="btn btn-danger">Cancel</button>
@@ -47,19 +42,23 @@ <h1>Change informations</h1>
4742
<h1>Change password</h1>
4843
<form ng-submit="changePassword()">
4944
<div class="form-group">
50-
<input type="password" id="password" class="form-control" ng-model="user.password" placeholder="Password" required>{{user.password}}</input>
45+
<input type="password" id="password" class="form-control" ng-model="user.newPassword" placeholder="Password">
5146
</div>
5247
<div class="form-group">
53-
<input type="password" id="passwordBis" class="form-control" ng-model="user.passwordBis" placeholder="Confirm Password" required samepassword="password">
48+
<input type="password" id="passwordBis" class="form-control" ng-model="user.newPasswordBis" placeholder="Confirm Password" required samepassword="password">
5449
</div>
5550
<p class="text-danger" ng-if="passNotMatch">Passwords don't match</p>
5651
<input type="submit" id="submit" value="Change password" class="btn btn-primary" />
5752

5853
</form>
5954

6055
<br />
61-
<button type="button" id="submit" class="btn btn-success btn-lg">Become Member</button>
56+
<form ng-submit="becomeMember()">
57+
<input value="Become Member"type="submit" id="submit" class="btn btn-success btn-lg" ng-if="isNotMember">
58+
<h3 ng-if="isNotMember==false">You are a Zenergy member!</h3>
59+
<br/>
60+
<h4 ng-if="isNotMember==false">Membership date : {{user.dateMembership}}</h4>
61+
</form>
6262
</div>
6363
</div>
64-
</div>
65-
64+
</div>

Diff for: Zenergy/Zenergy/Pages/login.html

-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ <h3>Or use a social network</h3>
2424
</div>
2525
</div>
2626
</div>
27-
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>

Diff for: Zenergy/Zenergy/Pages/register.html

-1
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,4 @@ <h3>Or use a social network</h3>
5959
</div>
6060
</div>
6161
</div>
62-
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
6362

Original file line numberDiff line numberDiff line change
@@ -1,77 +1,92 @@
1-
zenergyApp.controller("accountManagementPageController", ["$scope", "$http", "tokenService", "$window", function ($scope, $http, $window) {
1+
zenergyApp.controller("accountManagementPageController", ["$scope", "$http", "tokenService", "$window", "$location", function ($scope, $http, tokenService, $window, $location) {
22

3-
console.log(tokenService.userId);
4-
5-
/* var response = $http({
6-
url: '/api/users/',
7-
method: 'GET',
8-
data: { userId: 1, password: CryptoJS.MD5($scope.user.password).toString(), lastName: $scope.user.lastName, firstName: $scope.user.firstName, adr1: $scope.user.adr1, adr2: $scope.user.adr2, pc: $scope.user.pc, town: $scope.user.town, mail: $scope.user.mail, phone: $scope.user.phone },
9-
headers: {
10-
'Content-Type': 'application/json'
11-
}
12-
}).then(function successCallback(response) {
13-
$scope.hasError = false;
14-
window.location.replace("/home"); // $location.path("/#");
15-
}, function errorCallback(response) {
16-
$scope.hasError = true;
17-
$scope.user.mail = '';
18-
$scope.user.password = '';
19-
});*/
3+
// Get user data
4+
var response = $http({
5+
url: '/api/users/' + tokenService.getUserId(),
6+
method: 'GET',
7+
headers: {
8+
'Content-Type': 'application/json'
9+
}
10+
}).then(function successCallback(response) {
11+
$scope.hasError = false;
12+
$scope.user = { mail: response.data.mail, password: response.data.password, lastName: response.data.lastname, firstName: response.data.firstname, adr1: response.data.adr1, adr2: response.data.adr2, pc: response.data.pc, town: response.data.town, phone: response.data.phone, member: response.data.member };
13+
$scope.isNotMember = $scope.user.member == null;
14+
if (!$scope.isNotMember) {
15+
var date = new Date(response.data.member.dateMembership);
16+
$scope.user.dateMembership = date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear();
17+
}
18+
});
2019

21-
$scope.user = { mail: '', password: '', passwordBis: '', lastName: '', firstName: '', adr1: '', adr2: '', pc: '', town: '', phone: '' };
2220
$scope.hasError = false;
2321
$scope.passNotMatch = false;
2422

25-
26-
23+
// Modify account info
2724
$scope.changeInformations = function () {
28-
2925
if (!$scope.hasError) {
3026
var response = $http({
31-
url: '/api/Account/update',
27+
url: '/api/users/' + tokenService.getUserId(),
3228
method: 'PUT',
33-
data: { userId: 1, password: CryptoJS.MD5($scope.user.password).toString(), lastName: $scope.user.lastName, firstName: $scope.user.firstName, adr1: $scope.user.adr1, adr2: $scope.user.adr2, pc: $scope.user.pc, town: $scope.user.town, mail: $scope.user.mail, phone: $scope.user.phone },
29+
data: { userId: tokenService.getUserId(), password: $scope.user.password, lastName: $scope.user.lastName, firstName: $scope.user.firstName, adr1: $scope.user.adr1, adr2: $scope.user.adr2, pc: $scope.user.pc, town: $scope.user.town, mail: $scope.user.mail, phone: $scope.user.phone },
3430
headers: {
3531
'Content-Type': 'application/json'
3632
}
3733
}).then(function successCallback(response) {
3834
$scope.hasError = false;
39-
window.location.replace("/home"); // $location.path("/#");
35+
bootbox.alert("Your account is updated!", function () {
36+
window.location.reload(true);
37+
});
4038
}, function errorCallback(response) {
4139
$scope.hasError = true;
42-
$scope.user.mail = '';
43-
$scope.user.password = '';
4440
});
4541
}
4642
};
4743

44+
// Change password
4845
$scope.changePassword = function () {
4946

50-
if ($scope.user.password != $scope.user.passwordBis) {
51-
$scope.hasError = true;
47+
if ($scope.user.newPassword != $scope.user.newPasswordBis) {
5248
$scope.passNotMatch = true;
5349
}
5450
else {
55-
$scope.hasError = false;
5651
$scope.passNotMatch = false;
5752
}
5853

59-
if (!$scope.hasError) {
54+
if (!$scope.passNotMatch) {
6055
var response = $http({
61-
url: '/api/Account/update',
62-
method: 'POST',
63-
data: { userId: 1, password: CryptoJS.MD5($scope.user.password).toString(), lastName: $scope.user.lastName, firstName: $scope.user.firstName, adr1: $scope.user.adr1, adr2: $scope.user.adr2, pc: $scope.user.pc, town: $scope.user.town, mail: $scope.user.mail, phone: $scope.user.phone },
56+
url: '/api/users/' + tokenService.getUserId(),
57+
method: 'PUT',
58+
data: { userId: tokenService.getUserId(), password: CryptoJS.MD5($scope.user.newPassword).toString(), lastName: $scope.user.lastName, firstName: $scope.user.firstName, adr1: $scope.user.adr1, adr2: $scope.user.adr2, pc: $scope.user.pc, town: $scope.user.town, mail: $scope.user.mail, phone: $scope.user.phone },
6459
headers: {
6560
'Content-Type': 'application/json'
6661
}
6762
}).then(function successCallback(response) {
6863
$scope.hasError = false;
69-
window.location.replace("/home");
64+
window.location.reload(true);
65+
bootbox.alert("Your account is updated!", function () {
66+
window.location.reload(true);
67+
});
7068
}, function errorCallback(response) {
7169
$scope.hasError = true;
72-
$scope.user.mail = '';
73-
$scope.user.password = '';
7470
});
7571
}
7672
};
73+
74+
// Add membership
75+
$scope.becomeMember = function () {
76+
var today = new Date();
77+
78+
var response = $http({
79+
url: '/api/members/',
80+
method: 'POST',
81+
data: { userId: tokenService.getUserId(), dateMembership: today },
82+
headers: {
83+
'Content-Type': 'application/json'
84+
}
85+
}).then(function successCallback(response) {
86+
$scope.hasError = false;
87+
window.location.reload(true);
88+
}, function errorCallback(response) {
89+
$scope.hasError = true;
90+
});
91+
};
7792
}]);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
zenergyApp.controller("homePageController", ["$scope", "tokenService","$http", function ($scope, tokenService, $http) {
22
$scope.name = tokenService.getUserName();
3+
$scope.userId = tokenService.getUserId();
34
}]);

Diff for: Zenergy/Zenergy/Scripts/Controllers/loginPageController.js

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
}
1414
}).then(function successCallback(response) {
1515
$scope.hasError = false;
16-
console.log(response);
1716
tokenService.saveToken(response.data.access_token, response.data.userName, response.data.userId);
1817
$location.path('/');
1918
}, function errorCallback(response) {

Diff for: Zenergy/Zenergy/Scripts/Factories/tokenService.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
zenergyApp.factory('tokenService', function ($window) {
22
return {
3-
saveToken: function (token, username) {
3+
saveToken: function (token, username, userid) {
44
$window.sessionStorage.token = token;
55
$window.sessionStorage.username = username;
6+
$window.sessionStorage.setItem("userId", userid);
67
},
78
getToken: function () {
89
return $window.sessionStorage.token;
910
},
1011
getUserName: function () {
1112
return $window.sessionStorage.username;
1213
},
14+
getUserId: function () {
15+
return $window.sessionStorage.getItem("userId");
16+
},
1317
deleteToken: function () {
1418
delete $window.sessionStorage.token;
1519
delete $window.sessionStorage.username;
20+
delete $window.sessionStorage.userId;
1621
},
1722
tokenExists: function () {
1823
return $window.sessionStorage.token !== undefined;

Diff for: Zenergy/Zenergy/Scripts/Lib/_references.js

74 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)