Uh oh!
There was an error while loading. Please reload this page.
Require verification after email change - #2765
Conversation
loay
commented
Sep 22, 2016
@bajtos@raymondfeng |
If you add
I would like you to address this complexly.
|
loay
commented
Sep 23, 2016
Thanks @bajtos having a look |
loay
commented
Sep 28, 2016
@bajtos PTAL. Thanks |
bajtos
commented
Sep 29, 2016
@loay AFAICT, you are still resetting |
loay
commented
Sep 30, 2016
yeah, it didn't work for me, as I would run to the same problem as before, either timeout or infinite loop, as the validations of newEmail are not in the |
bajtos
commented
Oct 5, 2016
What is stopping you from adding the validation to the "before save" hook? It should also improve the performance a bit, because there will be one database query less when email is not changed. |
loay
commented
Nov 4, 2016
@bajtos I moved the |
| }); | ||
| describe('Verification after updating email', function() { | ||
| var nonVerifiedUser; |
There was a problem hiding this comment.
I find the variable name confusing. You are creating the user with emailVerified set to true and then store it in a variable called nonVerifiedUser.
Can you use a different name please? As far as I am concerned, user, userInstance or testUser are good enough. Feel free to come up with your own name though!
| }); | ||
| if (ctx.instance) { | ||
| var emailChanged = ctx.instance.email !== ctx.hookState.originalUserData[0].email; | ||
| if (!ctx.Model.settings.emailVerificationRequired) return next(); |
There was a problem hiding this comment.
How about simplifying this and the following line to the followin?
if(emailChanged&&ctx.Model.settings.emailVerificationRequired){ctx.instance.emailVerified=false;}| var emailChanged = ctx.hookState.originalUserData.some(function(data) { | ||
| return data.email != ctx.data.email; | ||
| }); | ||
| if (!ctx.Model.settings.emailVerificationRequired) return next(); |
There was a problem hiding this comment.
Same comment applies here.
if(emailChanged&&ctx.Model.settings.emailVerificationRequired){ctx.data.emailVerified=false;}| User.settings.emailVerificationRequired = true; | ||
| async.series([ | ||
| function createUser(next) { | ||
| User.create(originalMyEmailCred, function(err, specialInstance) { |
There was a problem hiding this comment.
AFAICT, this setup is shared by both tests. Please extract it into a shared beforeEach hook.
beforeEach(setupTestUser);it(...);it(...);functionsetupTestUser(done){User.create(originalMyEmailCred,function(err,inst){if(err)returndone(err);nonVerifiedUser=inst;// use a different name than nonVerifiedUserdone();});}loay
commented
Nov 9, 2016
@bajtos I have addressed the changes. PTAL. Thanks. |
When the User model is configured to require email verification, then any change of the email address should trigger re-verification.
bajtos
left a comment
There was a problem hiding this comment.
I made few final coding style tweaks myself and force-pushed to your feature branch. The patch is good to be merged now.
bajtos
commented
Nov 9, 2016
@loay landed, thank you. Please back-port to 2.x yourself. |
connect to https://github.com/strongloop-internal/scrum-loopback/issues/1029