Skip to content

Commit c81c0a6

Browse files
committed
dev-demo: add email-password-reset plugin
AdminForth/1777/image
1 parent d3bfe09 commit c81c0a6

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "adminuser" ADD COLUMN "email_confirmed" BOOLEAN DEFAULT true;

dev-demo/migrations/prisma/sqlite/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ model adminuser {
1717
avatar String?
1818
1919
is_active Boolean @default(true)
20+
email_confirmed Boolean? @default(true)
21+
2022
@@index([is_active])
2123
}
2224

dev-demo/resources/adminuser.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DashboardPlugin from '../../plugins/adminforth-dashboard/index.js';
1010
import UserSoftDelete from '../../plugins/adminforth-user-soft-delete/index.js';
1111
import KeyValueAdapterRam from '../../adapters/adminforth-key-value-adapter-ram/index.js';
1212
import OAuthPlugin from './configs/oauthPluginConfig.js';
13+
import EmailInvitePlugin from '../../plugins/adminforth-email-invite/index.js';
1314

1415
async function allowedForSuperAdmin({ adminUser }: { adminUser: AdminUser }): Promise<boolean> {
1516
return adminUser.dbUser.role === 'superadmin';
@@ -68,9 +69,7 @@ export default {
6869
editingNote: { edit: 'Leave empty to keep password unchanged' },
6970
type: AdminForthDataTypes.STRING,
7071
showIn: { // to show field only on create and edit pages
71-
show: false,
72-
list: false,
73-
filter: false,
72+
all: false,
7473
},
7574
masked: true, // to show stars in input field
7675

@@ -115,6 +114,10 @@ export default {
115114
edit: true,
116115
},
117116
},
117+
{
118+
name: 'email_confirmed',
119+
type: AdminForthDataTypes.BOOLEAN
120+
},
118121
],
119122
plugins: [
120123
new TwoFactorsAuthPlugin (
@@ -203,11 +206,28 @@ export default {
203206
return false;
204207
}
205208
}),
209+
new EmailInvitePlugin({
210+
emailField: 'email',
211+
sendFrom: 'noreply@yourapp.com',
212+
passwordField: 'password',
213+
adapter: {
214+
validate: async () => {
215+
216+
},
217+
sendEmail: async (from, to, text, html, subject) => {
218+
console.log('Sending email with html:', html);
219+
return { ok: true };
220+
}
221+
},
222+
emailConfirmedField: 'email_confirmed', // Enable email confirmation
223+
}),
206224
],
207225
hooks: {
208226
create: {
209227
beforeSave: async ({ record, adminUser, resource }: { record: any, adminUser: AdminUser, resource: AdminForthResource }) => {
210-
record.password_hash = await AdminForth.Utils.generatePasswordHash(record.password);
228+
if (record.password) {
229+
record.password_hash = await AdminForth.Utils.generatePasswordHash(record.password);
230+
}
211231
return { ok: true };
212232
}
213233
},

0 commit comments

Comments
 (0)