fix(user): check if email is someone else
This commit is contained in:
@ -640,12 +640,31 @@ module.exports = function(User) {
|
|||||||
emailVerified: false,
|
emailVerified: false,
|
||||||
emailVerifyTTL: new Date()
|
emailVerifyTTL: new Date()
|
||||||
};
|
};
|
||||||
return Observable.forkJoin(
|
|
||||||
this.update$(updateConfig),
|
// defer prevents the promise from firing prematurely (before subscribe)
|
||||||
this.requestAuthEmail(false, newEmail),
|
return Observable.defer(() => User.doesExist(null, newEmail))
|
||||||
(user, message) => ({ user, message })
|
.do(exists => {
|
||||||
)
|
if (exists && !isOwnEmail) {
|
||||||
.map(({ message }) => message);
|
// newEmail is not associated with this account,
|
||||||
|
// but is associated with different account
|
||||||
|
throw wrapHandledError(
|
||||||
|
new Error('email already in use'),
|
||||||
|
{
|
||||||
|
type: 'info',
|
||||||
|
message:
|
||||||
|
`${newEmail} is already associated with another account.`
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.flatMap(()=>{
|
||||||
|
return Observable.forkJoin(
|
||||||
|
this.update$(updateConfig),
|
||||||
|
this.requestAuthEmail(false, newEmail),
|
||||||
|
(user, message) => ({ user, message })
|
||||||
|
)
|
||||||
|
.map(({ message }) => message);
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return 'Something unexpected happened whilst updating your email.';
|
return 'Something unexpected happened whilst updating your email.';
|
||||||
|
Reference in New Issue
Block a user