Skip to content

Commit

Permalink
Update confirmation routing and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
adamaziz15 committed Oct 2, 2017
1 parent c25c9d5 commit 5ef8f09
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
7 changes: 4 additions & 3 deletions src/app/components/mnoe-api/current-user.svc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
->
Expand All @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions src/app/index.route.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')
Expand Down
27 changes: 23 additions & 4 deletions src/app/views/auth/confirmation/confirm.controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
8 changes: 4 additions & 4 deletions src/app/views/auth/confirmation/confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,17 @@ <h2>Almost there</h2>
<option value="ZA">ZA +27</option>
<option value="ZM">ZM +260</option>
<option value="ZW">ZW +263</option></select>
<input placeholder="*Phone" required="required" ng-model="vm.user.phone" class="form-control" type="text" name="user[phone]" id="user_phone" />
<input placeholder="*Phone" required="{{vm.phoneRequired}}" ng-model="vm.user.phone" class="form-control" type="text" name="user[phone]" id="user_phone" />
</div>
</div>
</div>
<br>
<div class='row'>
<div class='col-sm-12'>
<div class='input-group'>
<input placeholder="*Choose Password" ng-model="vm.user.password" class="form-control" ng-minlength="6" mno-password-strength="true" password-score="vm.user.$pwdScore" required="required" type="password" name="user[password]" id="user_password" />
<span class='input-group-addon classic pw-strength-indicator' ng-class='vm.user.$pwdScore.class'>
{{ user.$pwdScore.value }}
<input placeholder="*Choose Password" ng-model="vm.user.password" class="form-control" ng-minlength="6" mno-password-strength="true" password-score="vm.$pwdScore" required="required" type="password" name="user[password]" id="user_password" />
<span class='input-group-addon classic pw-strength-indicator' ng-class='vm.$pwdScore.class'>
{{ vm.$pwdScore.value }}
</span>
</div>
<div class='text-center ng-hide' ng-show='vm.user.$pwdScore.showTip'>
Expand Down

0 comments on commit 5ef8f09

Please sign in to comment.