From 5ef8f0952a8d04698eb069eb1c0b4abd41829698 Mon Sep 17 00:00:00 2001 From: Adam Abdelaziz Date: Fri, 22 Sep 2017 12:56:09 -0400 Subject: [PATCH] Update confirmation routing and controller --- .../mno-locale-config.svc.coffee | 2 +- .../mnoe-api/current-user.svc.coffee | 7 ++--- src/app/index.route.coffee | 8 ++---- .../confirmation/confirm.controller.coffee | 27 ++++++++++++++++--- src/app/views/auth/confirmation/confirm.html | 8 +++--- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/app/components/mno-locale-config/mno-locale-config.svc.coffee b/src/app/components/mno-locale-config/mno-locale-config.svc.coffee index 29163ded..9f2bf37d 100644 --- a/src/app/components/mno-locale-config/mno-locale-config.svc.coffee +++ b/src/app/components/mno-locale-config/mno-locale-config.svc.coffee @@ -37,7 +37,7 @@ angular.module 'mnoEnterpriseAngular' # Find the locale from the User#settings localeFromUser = -> - MnoeCurrentUser.get().then( + MnoeCurrentUser.get(skip_login_check: true).then( (response) -> response.settings?.locale ) diff --git a/src/app/components/mnoe-api/current-user.svc.coffee b/src/app/components/mnoe-api/current-user.svc.coffee index 4532728b..992112a5 100644 --- a/src/app/components/mnoe-api/current-user.svc.coffee +++ b/src/app/components/mnoe-api/current-user.svc.coffee @@ -26,7 +26,7 @@ angular.module 'mnoEnterpriseAngular' # Redirect if user is already logged in @skipIfLoggedIn = -> Auth.currentUser().then( - -> + (response) -> $timeout( -> $state.go('home.impac') ) $q.reject() -> @@ -41,13 +41,14 @@ angular.module 'mnoEnterpriseAngular' ) # Get the current user - @get = -> + @get = (opts = {})-> return userPromise if userPromise? + userPromise = MnoeApiSvc.one('current_user').get().then( (response) -> response = response.plain() - if !response.logged_in + if ! (opts.skip_login_check || response.logged_in) $state.go('login') angular.copy(response, _self.user) diff --git a/src/app/index.route.coffee b/src/app/index.route.coffee index 709ea417..8c536c4b 100644 --- a/src/app/index.route.coffee +++ b/src/app/index.route.coffee @@ -61,10 +61,7 @@ angular.module 'mnoEnterpriseAngular' templateUrl: 'app/views/auth/confirmation/confirm.html' controller: 'AuthConfirmCtrl' controllerAs: 'vm' - resolve: - # Redirect the user to the platform if he is already logged in - skipIfLoggedIn: (MnoeCurrentUser) -> - MnoeCurrentUser.skipIfLoggedIn() + public: true .state 'password_recovery', data: pageTitle: 'PasswordRecovery' @@ -277,10 +274,9 @@ angular.module 'mnoEnterpriseAngular' MnoeOrganizations = $injector.get('MnoeOrganizations') MnoeAppInstances = $injector.get('MnoeAppInstances') - MnoeCurrentUser.get().then( + MnoeCurrentUser.get(skip_login_check: true).then( (response) -> # Same as MnoeCurrentUser.loginRequired - debugger unless response.logged_in if MnoeConfig.arePublicApplicationsEnabled() $location.url('/landing') diff --git a/src/app/views/auth/confirmation/confirm.controller.coffee b/src/app/views/auth/confirmation/confirm.controller.coffee index c5b4ecdf..f2affb2a 100644 --- a/src/app/views/auth/confirmation/confirm.controller.coffee +++ b/src/app/views/auth/confirmation/confirm.controller.coffee @@ -2,16 +2,35 @@ angular.module 'mnoEnterpriseAngular' .controller('AuthConfirmCtrl', ($state, $stateParams, MnoeAuthSvc, toastr, MnoErrorsHandler) -> vm = @ - vm.user = {phone_country_code: "US", confirmation_token: $stateParams.confirmation_token} + vm.user = { phone_country_code: "US", confirmation_token: $stateParams.confirmation_token} + vm.$pwdScore = {} + vm.phoneRequired = "required" MnoeAuthSvc.one("/users/confirmation").get({confirmation_token: vm.user.confirmation_token}).then( - -> - debugger + (response) -> + if response.attributes.new_email_confirmed + toastr.success('Email confirmed successfully') + $state.go('home.impac') + else if response.attributes.confirmed_at + toastr.info('User already confirmed') + $state.go('login') + else if response.attributes.no_phone_required + vm.phoneRequired = '' (error) -> - debugger + toastr.error("Confirmation token is invalid") + $state.go('login') ) vm.confirmUser = -> + delete vm.user.$pwdScore + MnoeAuthSvc.one("/users/confirmation/finalize").patch({user: vm.user}).then( + -> + toastr.success('User confirmed successfully') + $state.go('home.impac') + (error) -> + toastr.error('Confirmation unsuccessful, please try again') + vm.hasClicked = false + ) return ) diff --git a/src/app/views/auth/confirmation/confirm.html b/src/app/views/auth/confirmation/confirm.html index 71ce1641..06b8d4c3 100644 --- a/src/app/views/auth/confirmation/confirm.html +++ b/src/app/views/auth/confirmation/confirm.html @@ -274,7 +274,7 @@

Almost there

- + @@ -282,9 +282,9 @@

Almost there

- - - {{ user.$pwdScore.value }} + + + {{ vm.$pwdScore.value }}