|
| 1 | +import angular from 'angular' |
| 2 | +import _ from 'lodash' |
| 3 | + |
1 | 4 | (function() {
|
2 |
| - 'use strict'; |
| 5 | + 'use strict' |
3 | 6 |
|
4 |
| - angular.module('tc.account').controller('RegisterController', RegisterController); |
| 7 | + angular.module('tc.account').controller('RegisterController', RegisterController) |
5 | 8 |
|
6 |
| - RegisterController.$inject = ['$log', 'CONSTANTS', '$state', '$stateParams', 'TcAuthService', 'UserService', 'ISO3166', 'Helpers']; |
| 9 | + RegisterController.$inject = ['$log', 'CONSTANTS', '$state', '$stateParams', 'TcAuthService', 'UserService', 'ISO3166', 'Helpers'] |
7 | 10 |
|
8 | 11 | function RegisterController($log, CONSTANTS, $state, $stateParams, TcAuthService, UserService, ISO3166, Helpers) {
|
9 |
| - $log = $log.getInstance("RegisterController"); |
10 |
| - $log.debug("-init"); |
11 |
| - var vm = this; |
12 |
| - vm.registering = false; |
| 12 | + $log = $log.getInstance('RegisterController') |
| 13 | + $log.debug('-init') |
| 14 | + var vm = this |
| 15 | + vm.registering = false |
13 | 16 | // prepares utm params, if available
|
14 | 17 | var utm = {
|
15 | 18 | source : $stateParams && $stateParams.utm_source ? $stateParams.utm_source : '',
|
16 | 19 | medium : $stateParams && $stateParams.utm_medium ? $stateParams.utm_medium : '',
|
17 | 20 | campaign : $stateParams && $stateParams.utm_campaign ? $stateParams.utm_campaign : ''
|
18 |
| - }; |
| 21 | + } |
19 | 22 |
|
20 | 23 |
|
21 | 24 | // Set default for toggle password directive
|
22 |
| - vm.defaultPlaceholder = 'Create Password'; |
23 |
| - vm.busyMessage = CONSTANTS.BUSY_PROGRESS_MESSAGE; |
| 25 | + vm.defaultPlaceholder = 'Create Password' |
| 26 | + vm.busyMessage = CONSTANTS.BUSY_PROGRESS_MESSAGE |
24 | 27 |
|
25 | 28 | // FIXME - This needs to be setup with https
|
26 | 29 | // lookup users country
|
27 | 30 | // Helpers.getCountyObjFromIP()
|
28 | 31 | // .then(function(obj) {
|
29 |
| - // vm.countryObj = obj; |
30 |
| - // }); |
| 32 | + // vm.countryObj = obj |
| 33 | + // }) |
31 | 34 |
|
32 |
| - vm.countries = ISO3166.getAllCountryObjects(); |
| 35 | + vm.countries = ISO3166.getAllCountryObjects() |
33 | 36 |
|
34 | 37 | vm.updateCountry = function (angucompleteCountryObj) {
|
35 |
| - var countryCode = _.get(angucompleteCountryObj, 'originalObject.code', undefined); |
| 38 | + var countryCode = _.get(angucompleteCountryObj, 'originalObject.code', undefined) |
36 | 39 |
|
37 |
| - var isValidCountry = _.isUndefined(countryCode) ? false : true; |
38 |
| - vm.registerForm.country.$setValidity('required', isValidCountry); |
39 |
| - vm.isValidCountry = isValidCountry; |
| 40 | + var isValidCountry = _.isUndefined(countryCode) ? false : true |
| 41 | + vm.registerForm.country.$setValidity('required', isValidCountry) |
| 42 | + vm.isValidCountry = isValidCountry |
40 | 43 | if (isValidCountry) {
|
41 |
| - vm.country = angucompleteCountryObj.originalObject; |
| 44 | + vm.country = angucompleteCountryObj.originalObject |
42 | 45 | }
|
43 |
| - }; |
| 46 | + } |
44 | 47 |
|
45 | 48 | vm.register = function() {
|
46 |
| - vm.registering = true; |
| 49 | + vm.registering = true |
47 | 50 | var userInfo = {
|
48 | 51 | handle: vm.username,
|
49 | 52 | firstName: vm.firstname,
|
|
57 | 60 | utmSource: utm.source,
|
58 | 61 | utmMedium: utm.medium,
|
59 | 62 | utmCampaign: utm.campaign
|
60 |
| - }; |
| 63 | + } |
61 | 64 |
|
62 | 65 | if (!vm.isSocialRegistration) {
|
63 |
| - userInfo.credential = { password: vm.password }; |
| 66 | + userInfo.credential = { password: vm.password } |
64 | 67 | } else {
|
65 | 68 | userInfo.profile = {
|
66 | 69 | userId: vm.socialUserId,
|
67 |
| - name: vm.firstname + " " + vm.lastname, |
| 70 | + name: vm.firstname + ' ' + vm.lastname, |
68 | 71 | email: vm.socialProfile.email,
|
69 | 72 | emailVerified: vm.socialProfile.email_verified,
|
70 | 73 | providerType: vm.socialProvider,
|
|
82 | 85 | }
|
83 | 86 | }
|
84 | 87 |
|
85 |
| - $log.debug('attempting to register user'); |
| 88 | + $log.debug('attempting to register user') |
86 | 89 | TcAuthService.register(body)
|
87 | 90 | .then(function(data) {
|
88 |
| - vm.registering = false; |
89 |
| - $log.debug('registered successfully'); |
| 91 | + vm.registering = false |
| 92 | + $log.debug('registered successfully') |
90 | 93 |
|
91 | 94 | // In the future, go to dashboard
|
92 |
| - $state.go('registeredSuccessfully'); |
| 95 | + $state.go('registeredSuccessfully') |
93 | 96 | })
|
94 | 97 | .catch(function(err) {
|
95 |
| - vm.registering = false; |
96 |
| - $log.error('Error in registering new user: ', err); |
97 |
| - }); |
98 |
| - }; |
| 98 | + vm.registering = false |
| 99 | + $log.error('Error in registering new user: ', err) |
| 100 | + }) |
| 101 | + } |
99 | 102 |
|
100 | 103 | vm.socialRegister = function(provider) {
|
101 | 104 | TcAuthService.socialRegistration(provider, null)
|
102 | 105 | .then(function(resp) {
|
103 | 106 | if (resp.status === 'SUCCESS') {
|
104 |
| - var socialData = resp.data; |
105 |
| - vm.socialUserId = socialData.socialUserId; |
106 |
| - vm.username = socialData.username; |
| 107 | + var socialData = resp.data |
| 108 | + vm.socialUserId = socialData.socialUserId |
| 109 | + vm.username = socialData.username |
107 | 110 | if (socialData.username) {
|
108 |
| - vm.registerForm.username.$setDirty(); |
| 111 | + vm.registerForm.username.$setDirty() |
109 | 112 | }
|
110 |
| - vm.firstname = socialData.firstname; |
| 113 | + vm.firstname = socialData.firstname |
111 | 114 | if (socialData.firstname) {
|
112 |
| - vm.registerForm.firstname.$setDirty(); |
| 115 | + vm.registerForm.firstname.$setDirty() |
113 | 116 | }
|
114 |
| - vm.lastname = socialData.lastname; |
| 117 | + vm.lastname = socialData.lastname |
115 | 118 | if (socialData.lastname) {
|
116 |
| - vm.registerForm.lastname.$setDirty(); |
| 119 | + vm.registerForm.lastname.$setDirty() |
117 | 120 | }
|
118 | 121 | if (socialData.email) {
|
119 |
| - vm.registerForm.email.$setDirty(); |
| 122 | + vm.registerForm.email.$setDirty() |
120 | 123 | }
|
121 |
| - vm.email = socialData.email; |
122 |
| - vm.socialProfile = socialData.socialProfile; |
123 |
| - vm.socialProvider = socialData.socialProvider; |
124 |
| - vm.socialContext= {'accessToken': socialData.accessToken}; |
125 |
| - vm.isSocialRegistration = true; |
| 124 | + vm.email = socialData.email |
| 125 | + vm.socialProfile = socialData.socialProfile |
| 126 | + vm.socialProvider = socialData.socialProvider |
| 127 | + vm.socialContext= {'accessToken': socialData.accessToken} |
| 128 | + vm.isSocialRegistration = true |
126 | 129 | } else {
|
127 |
| - vm.isSocialRegistration = false; |
| 130 | + vm.isSocialRegistration = false |
128 | 131 | }
|
129 | 132 | })
|
130 | 133 | .catch(function(result) {
|
131 |
| - switch (result.status) { |
132 |
| - case "SOCIAL_PROFILE_ALREADY_EXISTS": |
133 |
| - vm.errMsg = "An account with that profile already exists. Please login to access your account."; |
134 |
| - break; |
135 |
| - default: |
136 |
| - vm.errMsg = "Whoops! Something went wrong. Please try again later."; |
137 |
| - break; |
138 |
| - } |
139 |
| - vm.isSocialRegistration = false; |
140 |
| - }); |
141 |
| - |
| 134 | + switch (result.status) { |
| 135 | + case 'SOCIAL_PROFILE_ALREADY_EXISTS': |
| 136 | + vm.errMsg = 'An account with that profile already exists. Please login to access your account.' |
| 137 | + break |
| 138 | + default: |
| 139 | + vm.errMsg = 'Whoops! Something went wrong. Please try again later.' |
| 140 | + break |
| 141 | + } |
| 142 | + vm.isSocialRegistration = false |
| 143 | + }) |
142 | 144 | }
|
143 | 145 |
|
144 |
| - vm.$stateParams = $stateParams; |
| 146 | + vm.$stateParams = $stateParams |
145 | 147 | }
|
146 |
| -})(); |
| 148 | +})() |
0 commit comments