Set objectId into query for Email Validation (#6930)
* Retrieve user concerned by email verification and ser objectId into query * Linter ok * Testing live query fired when email validation done * Setting objectId into query if user exists * Setting objectId into query if user exists
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
const UserController = require('../lib/Controllers/UserController')
|
||||||
|
.UserController;
|
||||||
|
const Config = require('../lib/Config');
|
||||||
describe('ParseLiveQuery', function () {
|
describe('ParseLiveQuery', function () {
|
||||||
it('can subscribe to query', async done => {
|
it('can subscribe to query', async done => {
|
||||||
await reconfigureServer({
|
await reconfigureServer({
|
||||||
@@ -241,6 +243,62 @@ describe('ParseLiveQuery', function () {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should execute live query update on email validation', async done => {
|
||||||
|
const emailAdapter = {
|
||||||
|
sendVerificationEmail: () => {},
|
||||||
|
sendPasswordResetEmail: () => Promise.resolve(),
|
||||||
|
sendMail: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
await reconfigureServer({
|
||||||
|
liveQuery: {
|
||||||
|
classNames: ['_User'],
|
||||||
|
},
|
||||||
|
startLiveQueryServer: true,
|
||||||
|
verbose: false,
|
||||||
|
silent: true,
|
||||||
|
websocketTimeout: 100,
|
||||||
|
appName: 'liveQueryEmailValidation',
|
||||||
|
verifyUserEmails: true,
|
||||||
|
emailAdapter: emailAdapter,
|
||||||
|
emailVerifyTokenValidityDuration: 20, // 0.5 second
|
||||||
|
publicServerURL: 'http://localhost:8378/1',
|
||||||
|
}).then(() => {
|
||||||
|
const user = new Parse.User();
|
||||||
|
user.set('password', 'asdf');
|
||||||
|
user.set('email', 'asdf@example.com');
|
||||||
|
user.set('username', 'zxcv');
|
||||||
|
user
|
||||||
|
.signUp()
|
||||||
|
.then(() => {
|
||||||
|
const config = Config.get('test');
|
||||||
|
return config.database.find('_User', {
|
||||||
|
username: 'zxcv',
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(async results => {
|
||||||
|
const foundUser = results[0];
|
||||||
|
const query = new Parse.Query('_User');
|
||||||
|
query.equalTo('objectId', foundUser.objectId);
|
||||||
|
const subscription = await query.subscribe();
|
||||||
|
|
||||||
|
subscription.on('update', async object => {
|
||||||
|
expect(object).toBeDefined();
|
||||||
|
expect(object.get('emailVerified')).toBe(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
const userController = new UserController(emailAdapter, 'test', {
|
||||||
|
verifyUserEmails: true,
|
||||||
|
});
|
||||||
|
userController.verifyEmail(
|
||||||
|
foundUser.username,
|
||||||
|
foundUser._email_verify_token
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(async function (done) {
|
afterEach(async function (done) {
|
||||||
const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
|
const client = await Parse.CoreManager.getLiveQueryController().getDefaultLiveQueryClient();
|
||||||
client.close();
|
client.close();
|
||||||
|
|||||||
@@ -64,15 +64,17 @@ export class UserController extends AdaptableController {
|
|||||||
updateFields._email_verify_token_expires_at = { __op: 'Delete' };
|
updateFields._email_verify_token_expires_at = { __op: 'Delete' };
|
||||||
}
|
}
|
||||||
const masterAuth = Auth.master(this.config);
|
const masterAuth = Auth.master(this.config);
|
||||||
var checkIfAlreadyVerified = new RestQuery(
|
var findUserForEmailVerification = new RestQuery(
|
||||||
this.config,
|
this.config,
|
||||||
Auth.master(this.config),
|
Auth.master(this.config),
|
||||||
'_User',
|
'_User',
|
||||||
{ username: username, emailVerified: true }
|
{ username: username }
|
||||||
);
|
);
|
||||||
return checkIfAlreadyVerified.execute().then(result => {
|
return findUserForEmailVerification.execute().then(result => {
|
||||||
if (result.results.length) {
|
if (result.results.length && result.results[0].emailVerified) {
|
||||||
return Promise.resolve(result.results.length[0]);
|
return Promise.resolve(result.results.length[0]);
|
||||||
|
} else if (result.results.length) {
|
||||||
|
query.objectId = result.results[0].objectId;
|
||||||
}
|
}
|
||||||
return rest.update(this.config, masterAuth, '_User', query, updateFields);
|
return rest.update(this.config, masterAuth, '_User', query, updateFields);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user