Skip to content

Commit

Permalink
Resolved issues with the email confirmation being attempted twice
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Aug 17, 2015
1 parent 3b26cd5 commit 2aa86a8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
54 changes: 28 additions & 26 deletions app/src/app/user/profile/profile.ts
Expand Up @@ -24,44 +24,41 @@ namespace app.user.profile {
onBoard: false
},
resolve: /*@ngInject*/{
emailConfirmationToken:(
emailConfirmed:(
userService:common.services.user.UserService,
$stateParams:IStateParams,
ngJwtAuthService:NgJwtAuth.NgJwtAuthService,
notificationService:common.services.notification.NotificationService,
$location:ng.ILocationService
$location:ng.ILocationService,
$q:ng.IQService
) => {
if(!_.isEmpty($stateParams.emailConfirmationToken)) {
userService.confirmEmail(<common.models.User>ngJwtAuthService.getUser(), $stateParams.emailConfirmationToken)

let emailToken = $stateParams.emailConfirmationToken;

$location.search('emailConfirmationToken', null);

return userService.confirmEmail(<common.models.User>ngJwtAuthService.getUser(), emailToken)
.then(() => {
notificationService.toast('Your email has successfully been updated').pop();

$location.search('emailConfirmationToken', null);
_.delay(() => notificationService.toast('Your email has successfully been updated').pop(), 1000);

return true;

}, (err) => {
notificationService.toast('Your email has not been updated, please try again').pop();
_.delay(() => notificationService.toast('Your email has not been updated, please try again').pop(), 1000);

return false;
});

}

return $q.when(false);
},
countries:(
countriesService:common.services.countries.CountriesService
) => {
return countriesService.getAllCountries()
},
timezones:(
timezonesService:common.services.timezones.TimezonesService
) => {
return timezonesService.getAllTimezones();
},
userProfile:(
userService:common.services.user.UserService,
ngJwtAuthService:NgJwtAuth.NgJwtAuthService
) => {
return userService.getProfile(<common.models.User>ngJwtAuthService.getUser())
},
genderOptions:() => {
return common.models.UserProfile.genderOptions;
}
countries:(countriesService:common.services.countries.CountriesService) => countriesService.getAllCountries(),
timezones:(timezonesService:common.services.timezones.TimezonesService) => timezonesService.getAllTimezones(),
userProfile:(userService:common.services.user.UserService) => userService.getProfile(userService.getAuthUser()),
genderOptions:() => common.models.UserProfile.genderOptions,
},
data: {
title: "User Profile",
Expand All @@ -84,17 +81,22 @@ namespace app.user.profile {

export class ProfileController {

static $inject = ['userService', 'user', 'notificationService', 'countries', 'timezones', 'userProfile', 'genderOptions'];
static $inject = ['userService', 'user', 'notificationService', 'emailConfirmed', 'countries', 'timezones', 'userProfile', 'genderOptions'];
constructor(
private userService:common.services.user.UserService,
public user:common.models.User,
private notificationService:common.services.notification.NotificationService,
private emailConfirmed:boolean,
public countries:common.services.countries.ICountryDefinition,
public timezones:common.services.timezones.ITimezoneDefinition,
public userProfile:common.models.UserProfile,
public genderOptions:common.models.IGenderOption[]
) {

if (emailConfirmed){
this.user = userService.getAuthUser(); //if the email has been confirmed, the auth user's email will have updated
}

user._userProfile = userProfile;

}
Expand Down
4 changes: 2 additions & 2 deletions app/src/app/user/user.ts
Expand Up @@ -25,8 +25,8 @@ namespace app.user {
}
},
resolve: {
user:(ngJwtAuthService:NgJwtAuth.NgJwtAuthService) => {
return <common.models.User>ngJwtAuthService.getUser()
user:(userService:common.services.user.UserService):common.models.User => {
return userService.getAuthUser();
}
},
data: {
Expand Down
16 changes: 12 additions & 4 deletions app/src/common/services/user/userService.ts
Expand Up @@ -133,10 +133,9 @@ namespace common.services.user {
public confirmEmail(user:common.models.User, emailConfirmToken:string):ng.IPromise<any> {
user.emailConfirmed = moment().toISOString();
return this.ngRestAdapter
.skipInterceptor((rejection:ng.IHttpPromiseCallbackArg<any>) => {
return rejection.status == 422;
})
.patch('/users/' + user.userId, _.pick(user, 'emailConfirmed'), {'email-confirm-token':emailConfirmToken});
.skipInterceptor((rejection:ng.IHttpPromiseCallbackArg<any>) => rejection.status == 422)
.patch('/users/' + user.userId, _.pick(user, 'emailConfirmed'), {'email-confirm-token':emailConfirmToken})
;
}

/**
Expand All @@ -160,6 +159,15 @@ namespace common.services.user {
return new common.models.UserProfile(res.data);
});
}

/**
* Get the auth user
* @returns {common.models.User}
*/
public getAuthUser():common.models.User {
return <common.models.User>this.ngJwtAuthService.getUser();
}

}

angular.module(namespace, [])
Expand Down

0 comments on commit 2aa86a8

Please sign in to comment.