Skip to content

Commit

Permalink
Add login by email.
Browse files Browse the repository at this point in the history
  • Loading branch information
robgietema committed Apr 27, 2024
1 parent c786327 commit d07da6c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Add profile metadata @robgietema
- Add @site endpoint @robgietema
- Add upgrade profile functionality @robgietema
- Add login by email @robgietema

### Bugfix

Expand Down
12 changes: 10 additions & 2 deletions src/migrations/202203200907_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export const up = async (knex) => {
.onDelete('CASCADE');
table.integer('position_in_parent');
table.integer('version');
table.string('owner').references('user.id');
table
.string('owner')
.references('user.id')
.onUpdate('CASCADE')
.onDelete('CASCADE');
table.jsonb('json').notNull();
table.jsonb('lock').notNull();
table.boolean('inherit_roles').notNull().defaultTo(true);
Expand All @@ -37,7 +41,11 @@ export const up = async (knex) => {
await knex.schema.createTable('version', (table) => {
table.integer('version');
table.dateTime('created');
table.string('actor').references('user.id');
table
.string('actor')
.references('user.id')
.onUpdate('CASCADE')
.onDelete('CASCADE');
table
.uuid('document')
.index()
Expand Down
1 change: 1 addition & 0 deletions src/migrations/202203200908_redirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const up = (knex) =>
.uuid('document')
.notNull()
.references('document.uuid')
.onUpdate('CASCADE')
.onDelete('CASCADE');
table.string('path').notNull().index();
table.primary(['document', 'path']);
Expand Down
1 change: 1 addition & 0 deletions src/migrations/202203200909_catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const up = async (knex) => {
.uuid('document')
.primary()
.references('document.uuid')
.onUpdate('CASCADE')
.onDelete('CASCADE');
});
await knex.schema.createTable('index', (table) => {
Expand Down
9 changes: 7 additions & 2 deletions src/routes/authentication/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ export default [
});
}

// Find user
const user = await User.fetchById(req.body.login, {}, trx);
// Find user by id
let user = await User.fetchById(req.body.login, {}, trx);

// Find user by email
if (!user) {
user = await User.fetchOne({ email: req.body.login }, {}, trx);
}

// If user not found
if (!user) {
Expand Down
19 changes: 15 additions & 4 deletions src/routes/content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,6 @@ export default [
...omit(pick(req.body, keys(properties)), omitProperties),
};

// Trigger onBeforeAdd
await config.events.trigger('onBeforeAdd', req.document, trx, json);

// Handle files, images and relation lists
json = await handleFiles(json, type);
json = await handleImages(json, type);
Expand Down Expand Up @@ -387,6 +384,9 @@ export default [
document.id
}`;

// Trigger onBeforeAdd
await config.events.trigger('onBeforeAdd', document, json, trx);

// Insert document in database
document = await req.document.createRelatedAndFetch(
'_children',
Expand Down Expand Up @@ -422,7 +422,7 @@ export default [
// Fetch related lists
await document.fetchRelationLists(trx);

// Trigger onBeforeAdd
// Trigger onAfterAdd
await config.events.trigger('onAfterAdd', document, trx);

// Send data back to client
Expand Down Expand Up @@ -529,6 +529,14 @@ export default [
await Document.replacePath(path, newPath, trx);
}

// Trigger onBeforeAdd
await config.events.trigger(
'onBeforeModified',
req.document,
{ ...json, id: newId, path: newPath },
trx,
);

// Save document with new values
await req.document.update(
{
Expand Down Expand Up @@ -599,6 +607,9 @@ export default [
await req.document.fetchRelated('_parent', trx);
const parent = req.document._parent;

// Trigger onBeforeAdd
await config.events.trigger('onBeforeDelete', req.document, trx);

// Remove document (versions will be cascaded)
await req.document.delete(trx);

Expand Down

0 comments on commit d07da6c

Please sign in to comment.