Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic function for change_email policy #191

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion admin-panel/app/[lang]/account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ const Page = () => {
})
}

const handleChangeEmail = () => {
loginRedirect({
locale: locale || undefined, policy: 'change_email',
})
}

return (
<section>
<section className='flex flex-col gap-4 w-32'>
<Button onClick={handleChangePassword}>
{t('account.changePassword')}
</Button>
<Button onClick={handleChangeEmail}>
{t('account.changeEmail')}
</Button>
</section>
)
}
Expand Down
3 changes: 2 additions & 1 deletion admin-panel/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"account": "Account"
},
"account": {
"changePassword": "Change Password"
"changePassword": "Change Password",
"changeEmail": "Change Email"
},
"common": {
"enable": "Enable",
Expand Down
3 changes: 2 additions & 1 deletion admin-panel/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"account": "Compte"
},
"account": {
"changePassword": "Changer le mot de passe"
"changePassword": "Changer le mot de passe",
"changeEmail": "Changer l'email"
},
"common": {
"enable": "Activer",
Expand Down
8 changes: 8 additions & 0 deletions server/src/__tests__/normal/identity-main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
const { code } = json as { code: string }
const codeStore = JSON.parse(await mockedKV.get(`AC-${code}`) ?? '')
Expand Down Expand Up @@ -692,6 +693,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
const appRecord = await getApp(db)
const { code } = json as { code: string }
Expand Down Expand Up @@ -755,6 +757,7 @@ describe(
requireOtpMfa: true,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
global.process.env.OTP_MFA_IS_REQUIRED = false as unknown as string
},
Expand All @@ -778,6 +781,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
global.process.env.EMAIL_MFA_IS_REQUIRED = false as unknown as string
},
Expand All @@ -801,6 +805,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: true,
requireChangePassword: false,
requireChangeEmail: false,
})
global.process.env.SMS_MFA_IS_REQUIRED = false as unknown as string
},
Expand All @@ -824,6 +829,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
global.process.env.ENFORCE_ONE_MFA_ENROLLMENT = ['email', 'otp'] as unknown as string
},
Expand All @@ -847,6 +853,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
global.process.env.ENABLE_USER_APP_CONSENT = true as unknown as string
},
Expand Down Expand Up @@ -1014,6 +1021,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
const consent = db.prepare('SELECT * from user_app_consent WHERE "userId" = 1 AND "appId" = 1').get()
expect(consent).toBeTruthy()
Expand Down
8 changes: 8 additions & 0 deletions server/src/__tests__/normal/identity-mfa.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})

const user = await db.prepare('SELECT * from "user" WHERE id = 1').get() as userModel.Raw
Expand Down Expand Up @@ -324,6 +325,7 @@ describe(
requireOtpMfa: true,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})

const user = await db.prepare('SELECT * from "user" WHERE id = 1').get() as userModel.Raw
Expand Down Expand Up @@ -547,6 +549,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
expect(await mockedKV.get(`${adapterConfig.BaseKVKey.OtpMfaCode}-${json.code}`)).toBe('1')
},
Expand Down Expand Up @@ -1520,6 +1523,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
expect(await mockedKV.get(`${adapterConfig.BaseKVKey.SmsMfaCode}-${json.code}`)).toBe('1')

Expand Down Expand Up @@ -1943,6 +1947,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
expect(await mockedKV.get(`${adapterConfig.BaseKVKey.EmailMfaCode}-${json.code}`)).toBe('1')
},
Expand Down Expand Up @@ -2042,6 +2047,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
expect(await mockedKV.get(`${adapterConfig.BaseKVKey.OtpMfaCode}-${json.code}`)).toBe('1')
},
Expand Down Expand Up @@ -2104,6 +2110,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
expect(await mockedKV.get(`${adapterConfig.BaseKVKey.SmsMfaCode}-${json.code}`)).toBe('1')
},
Expand Down Expand Up @@ -2285,6 +2292,7 @@ describe(
requireOtpMfa: false,
requireSmsMfa: false,
requireChangePassword: false,
requireChangeEmail: false,
})
expect(await mockedKV.get(`${adapterConfig.BaseKVKey.EmailMfaCode}-${json.code}`)).toBe('1')
},
Expand Down
Loading
Loading