fix(Users): Makes sure verifying emails triggers hooks and liveQuery (#3851)

* Use RestWrite when verifying emails so hooks are called (as master)

* Fixes tests for postgres

* nit

* Makes rest.update support a full where instead of objectId

* Use rest.update to guaranteed proper beforeSave and liveQuery calls
This commit is contained in:
Florent Vilmart
2017-05-28 20:34:49 -04:00
committed by GitHub
parent 73aafa2d24
commit c2abbae92d
7 changed files with 29 additions and 31 deletions

View File

@@ -59,18 +59,13 @@ export class UserController extends AdaptableController {
updateFields._email_verify_token_expires_at = {__op: 'Delete'};
}
const masterAuth = Auth.master(this.config);
var checkIfAlreadyVerified = new RestQuery(this.config, Auth.master(this.config), '_User', {username: username, emailVerified: true});
return checkIfAlreadyVerified.execute().then(result => {
if (result.results.length) {
return Promise.resolve(result.results.length[0]);
}
return this.config.database.update('_User', query, updateFields).then((document) => {
if (!document) {
throw undefined
}
return Promise.resolve(document);
})
return rest.update(this.config, masterAuth, '_User', query, updateFields);
});
}
@@ -229,7 +224,7 @@ export class UserController extends AdaptableController {
// Mark this private
function updateUserPassword(userId, password, config) {
return rest.update(config, Auth.master(config), '_User', userId, {
return rest.update(config, Auth.master(config), '_User', { objectId: userId }, {
password: password
});
}