feat: Add Parse.User as function parameter to Parse Server options verifyUserEmails, preventLoginWithUnverifiedEmail on login (#8850)
This commit is contained in:
@@ -267,6 +267,41 @@ describe('Custom Pages, Email Verification, Password Reset', () => {
|
|||||||
expect(loginRes.message).toEqual('User email is not verified.');
|
expect(loginRes.message).toEqual('User email is not verified.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('provides function arguments in verifyUserEmails on login', async () => {
|
||||||
|
const user = new Parse.User();
|
||||||
|
user.setUsername('user');
|
||||||
|
user.setPassword('pass');
|
||||||
|
user.set('email', 'test@example.com');
|
||||||
|
await user.signUp();
|
||||||
|
|
||||||
|
const verifyUserEmails = {
|
||||||
|
method: async (params) => {
|
||||||
|
expect(params.object).toBeInstanceOf(Parse.User);
|
||||||
|
expect(params.ip).toBeDefined();
|
||||||
|
expect(params.master).toBeDefined();
|
||||||
|
expect(params.installationId).toBeDefined();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const verifyUserEmailsSpy = spyOn(verifyUserEmails, 'method').and.callThrough();
|
||||||
|
await reconfigureServer({
|
||||||
|
appName: 'test',
|
||||||
|
publicServerURL: 'http://localhost:1337/1',
|
||||||
|
verifyUserEmails: verifyUserEmails.method,
|
||||||
|
preventLoginWithUnverifiedEmail: verifyUserEmails.method,
|
||||||
|
preventSignupWithUnverifiedEmail: true,
|
||||||
|
emailAdapter: MockEmailAdapterWithOptions({
|
||||||
|
fromAddress: 'parse@example.com',
|
||||||
|
apiKey: 'k',
|
||||||
|
domain: 'd',
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await Parse.User.logIn('user', 'pass').catch(e => e);
|
||||||
|
expect(res.code).toBe(205);
|
||||||
|
expect(verifyUserEmailsSpy).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
|
|
||||||
it('allows user to login only after user clicks on the link to confirm email address if preventLoginWithUnverifiedEmail is set to true', async () => {
|
it('allows user to login only after user clicks on the link to confirm email address if preventLoginWithUnverifiedEmail is set to true', async () => {
|
||||||
let sendEmailOptions;
|
let sendEmailOptions;
|
||||||
const emailAdapter = {
|
const emailAdapter = {
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ export class UsersRouter extends ClassesRouter {
|
|||||||
master: req.auth.isMaster,
|
master: req.auth.isMaster,
|
||||||
ip: req.config.ip,
|
ip: req.config.ip,
|
||||||
installationId: req.auth.installationId,
|
installationId: req.auth.installationId,
|
||||||
|
object: Parse.User.fromJSON(Object.assign({ className: '_User' }, user)),
|
||||||
};
|
};
|
||||||
// Get verification conditions which can be booleans or functions; the purpose of this async/await
|
// Get verification conditions which can be booleans or functions; the purpose of this async/await
|
||||||
// structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the
|
// structure is to avoid unnecessarily executing subsequent functions if previous ones fail in the
|
||||||
|
|||||||
Reference in New Issue
Block a user