Skip to content

Commit 9dd8609

Browse files
committed
Merge pull request #1253 from DroidsOnRoids/master
Fixed bug with invalid email verification link on email update.
2 parents 5923347 + 6dc7aa8 commit 9dd8609

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

spec/ValidationAndPasswordsReset.spec.js

+55-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,61 @@ describe("Email Verification", () => {
156156
return user.fetch();
157157
}).then(() => {
158158
expect(user.get('emailVerified')).toEqual(false);
159-
// Wait as on update emai, we need to fetch the username
159+
// Wait as on update email, we need to fetch the username
160+
setTimeout(function(){
161+
expect(emailAdapter.sendVerificationEmail).toHaveBeenCalled();
162+
done();
163+
}, 200);
164+
});
165+
},
166+
error: function(userAgain, error) {
167+
fail('Failed to save user');
168+
done();
169+
}
170+
});
171+
});
172+
173+
it('does send a validation email with valid verification link when updating the email', done => {
174+
var emailAdapter = {
175+
sendVerificationEmail: () => Promise.resolve(),
176+
sendPasswordResetEmail: () => Promise.resolve(),
177+
sendMail: () => Promise.resolve()
178+
}
179+
setServerConfiguration({
180+
serverURL: 'http://localhost:8378/1',
181+
appId: 'test',
182+
appName: 'unused',
183+
javascriptKey: 'test',
184+
dotNetKey: 'windows',
185+
clientKey: 'client',
186+
restAPIKey: 'rest',
187+
masterKey: 'test',
188+
collectionPrefix: 'test_',
189+
fileKey: 'test',
190+
verifyUserEmails: true,
191+
emailAdapter: emailAdapter,
192+
publicServerURL: "http://localhost:8378/1"
193+
});
194+
spyOn(emailAdapter, 'sendVerificationEmail').and.callFake((options) => {
195+
expect(options.link).not.toBeNull();
196+
expect(options.link).not.toMatch(/token=undefined/);
197+
Promise.resolve();
198+
});
199+
var user = new Parse.User();
200+
user.setPassword("asdf");
201+
user.setUsername("zxcv");
202+
user.signUp(null, {
203+
success: function(user) {
204+
expect(emailAdapter.sendVerificationEmail).not.toHaveBeenCalled();
205+
user.fetch()
206+
.then((user) => {
207+
user.set("email", "[email protected]");
208+
return user.save();
209+
}).then((user) => {
210+
return user.fetch();
211+
}).then(() => {
212+
expect(user.get('emailVerified')).toEqual(false);
213+
// Wait as on update email, we need to fetch the username
160214
setTimeout(function(){
161215
expect(emailAdapter.sendVerificationEmail).toHaveBeenCalled();
162216
done();

src/Controllers/UserController.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,13 @@ export class UserController extends AdaptableController {
100100
})
101101
}
102102

103-
104103
sendVerificationEmail(user) {
105104
if (!this.shouldVerifyEmails) {
106105
return;
107106
}
107+
const token = encodeURIComponent(user._email_verify_token);
108108
// We may need to fetch the user in case of update email
109109
this.getUserIfNeeded(user).then((user) => {
110-
const token = encodeURIComponent(user._email_verify_token);
111110
const username = encodeURIComponent(user.username);
112111
let link = `${this.config.verifyEmailURL}?token=${token}&username=${username}`;
113112
let options = {

0 commit comments

Comments
 (0)