Skip to content

Commit 463006d

Browse files
committed
use registerService in modalRegister
1 parent ba99301 commit 463006d

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

public/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232
<script src="node_modules/angular-localforage/dist/angular-localForage.js"></script>
3333
<!-- main app file -->
3434
<script src="js/app.js"></script>
35+
<!-- constance -->
36+
<script src="js/httpConfig.js"></script>
3537
<!-- controllers -->
3638
<script src="js/controllers/mainCtrl.js"></script>
3739
<script src="js/controllers/externalCtrl.js"></script>
3840
<!-- services (the interesting part indeed) -->
3941
<script src="js/services/colorCheckerService.js"></script>
4042
<script src="js/services/colorChangerService.js"></script>
4143
<script src="js/services/stateService.js"></script>
44+
<script src="js/services/registerService.js"></script>
4245
<!-- directives -->
4346
<script src="js/directives/topbar.js"></script>
4447
<script src="js/directives/modalOverlay.js"></script>

public/js/directives/modalRegister.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
$scope.password = '';
1717
$scope.passwordConf = '';
1818
$scope.hideModal = () => stateService.set('modalRegister', false);
19-
$scope.register = () => {
19+
$scope.register = async () => {
2020
if($scope.password !== $scope.passwordConf) {
2121
alert('Passwords are not equal!')
2222
} else {
2323
const params = {
2424
email: $scope.email,
2525
password: $scope.password
2626
};
27-
registerService.register(params);
27+
const response = await registerService.register(params);
28+
console.log(response);
2829
}
2930
}
3031
}

public/js/services/registerService.js

+9-22
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,21 @@
22
'use strict';
33

44
angular
5-
.module('accTrader')
5+
.module('app')
66
.service('registerService', Service);
77

8-
Service.$inject = ['$http'];
9-
10-
function Service($http) {
11-
this.registerUser = function (registerInfo) {
8+
Service.$inject = ['$http', 'httpConfig'];
129

10+
function Service($http, httpConfig) {
11+
this.register = function (params) {
1312
return $http({
14-
url: 'https://acctrader.herokuapp.com/v1/sign_up',
15-
headers: {
16-
'Content-Type': 'application/vnd.api+json'
17-
},
13+
url: httpConfig.baseUrl + '/user/register',
14+
headers: { 'Content-Type': 'application/json' },
1815
method: 'POST',
19-
data: {
20-
user: {
21-
email: registerInfo.email,
22-
nick: registerInfo.nick,
23-
password: registerInfo.password,
24-
password_confirmation: registerInfo.password_confirmation
25-
}
26-
}
16+
data: params
2717
})
28-
.then(function(response) {
29-
return response.data;
30-
}, function(err) {
31-
return err;
32-
});
18+
.then(response => { return response.data })
19+
.catch(err => { console.log(err) })
3320
};
3421
}
3522
})();

0 commit comments

Comments
 (0)