|
14 | 14 | '$timeout', |
15 | 15 | 'settings', |
16 | 16 | 'clerk', |
17 | | - 'RELAY_CONFIG' |
| 17 | + 'RELAY_CONFIG', |
| 18 | + 'featureGating' |
18 | 19 | ]; |
19 | 20 |
|
20 | | - function MyProfileCtrl($scope, $location, $rootScope, auth, $translate, $timeout, settings, clerk, RELAY_CONFIG, $http) { |
| 21 | + function MyProfileCtrl($scope, $location, $rootScope, auth, $translate, $timeout, settings, clerk, RELAY_CONFIG, featureGating, $http) { |
21 | 22 | var vm = this; |
22 | 23 | $rootScope.setSubmenues([ |
23 | 24 | { text: 'submenu_my_profile', url: 'settings/my-profile', active: true }, |
|
44 | 45 | vm.emailResendSuccess = false; |
45 | 46 | vm.pendingNewEmail = null; |
46 | 47 | vm.twoFactorRequiredMessage = null; |
| 48 | + vm.emailChange2faStatus = 'allowed'; |
| 49 | + |
| 50 | + refreshEmailChange2faStatus(); |
| 51 | + |
| 52 | + function refreshEmailChange2faStatus() { |
| 53 | + featureGating.evaluate('update_email').then(function (status) { |
| 54 | + vm.emailChange2faStatus = status; |
| 55 | + }); |
| 56 | + } |
47 | 57 |
|
48 | 58 | function updateValidation(form) { |
49 | 59 | if (!form.pass.$modelValue || !form.confPass.$modelValue) { |
|
149 | 159 | return; |
150 | 160 | } |
151 | 161 |
|
152 | | - clerk.hasTwoFactorEnabled() |
153 | | - .then(function(enabled) { |
154 | | - if (enabled) { |
155 | | - vm.showUserNameContainer = true; |
156 | | - } else { |
157 | | - vm.twoFactorRequiredMessage = $translate.instant('two_factor_required_for_action'); |
158 | | - } |
159 | | - }); |
| 162 | + featureGating.evaluate('update_email').then(function(status) { |
| 163 | + vm.emailChange2faStatus = status; |
| 164 | + if (status === featureGating.STATUS_BLOCKED_NEEDS_2FA) { |
| 165 | + vm.twoFactorRequiredMessage = $translate.instant('two_factor_required_for_action'); |
| 166 | + return; |
| 167 | + } |
| 168 | + vm.showUserNameContainer = true; |
| 169 | + }); |
160 | 170 | } |
161 | 171 |
|
162 | 172 | function changeUsername(form) { |
|
171 | 181 | var useClerkAuth = RELAY_CONFIG.useClerkAuthentication || false; |
172 | 182 |
|
173 | 183 | if (useClerkAuth) { |
174 | | - clerk.hasTwoFactorEnabled() |
175 | | - .then(function(enabled) { |
176 | | - if (!enabled) { |
177 | | - vm.emailChangeError = $translate.instant('two_factor_required_for_action'); |
| 184 | + clerk.createEmailAddress(form.username.$modelValue) |
| 185 | + .then(function(result) { |
| 186 | + if (!result.success) { |
| 187 | + if (result.emailAlreadyExists) { |
| 188 | + vm.existingEmail = true; |
| 189 | + return; |
| 190 | + } |
| 191 | + if (result.invalidFormat) { |
| 192 | + vm.emailChangeError = $translate.instant('change_email_invalid_format'); |
| 193 | + return; |
| 194 | + } |
| 195 | + vm.emailChangeError = result.error || $translate.instant('change_email_error'); |
178 | 196 | return; |
179 | 197 | } |
180 | | - return clerk.createEmailAddress(form.username.$modelValue) |
181 | | - .then(function(result) { |
182 | | - if (!result.success) { |
183 | | - if (result.emailAlreadyExists) { |
184 | | - vm.existingEmail = true; |
185 | | - return; |
186 | | - } |
187 | | - if (result.invalidFormat) { |
188 | | - vm.emailChangeError = $translate.instant('change_email_invalid_format'); |
189 | | - return; |
190 | | - } |
191 | | - vm.emailChangeError = result.error || $translate.instant('change_email_error'); |
192 | | - return; |
193 | | - } |
194 | 198 |
|
195 | | - vm.emailChangeStep = 'otp'; |
196 | | - vm.pendingNewEmail = form.username.$modelValue; |
197 | | - }); |
| 199 | + vm.emailChangeStep = 'otp'; |
| 200 | + vm.pendingNewEmail = form.username.$modelValue; |
198 | 201 | }) |
199 | 202 | .catch(function(error) { |
200 | 203 | vm.emailChangeError = $translate.instant('change_email_error'); |
|
0 commit comments