aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/RegistrationPage.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/demobank-ui/src/pages/RegistrationPage.tsx')
-rw-r--r--packages/demobank-ui/src/pages/RegistrationPage.tsx159
1 files changed, 91 insertions, 68 deletions
diff --git a/packages/demobank-ui/src/pages/RegistrationPage.tsx b/packages/demobank-ui/src/pages/RegistrationPage.tsx
index 89bfbcb35..e7ed8a2b8 100644
--- a/packages/demobank-ui/src/pages/RegistrationPage.tsx
+++ b/packages/demobank-ui/src/pages/RegistrationPage.tsx
@@ -98,78 +98,101 @@ function RegistrationForm({ onComplete, onCancel }: { onComplete: () => void, on
async function doRegistrationAndLogin(name: string, username: string, password: string, onComplete: () => void) {
await handleError(async () => {
- const creationResponse = await api.createAccount("" as AccessToken, { name, username, password });
- if (creationResponse.type === "fail") {
- switch (creationResponse.case) {
- case HttpStatusCode.BadRequest: return notify({
- type: "error",
- title: i18n.str`Server replied with invalid phone or email.`,
- description: creationResponse.detail.hint as TranslatedString,
- debug: creationResponse.detail,
- })
- case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({
- type: "error",
- title: i18n.str`Registration is disabled because the bank ran out of bonus credit.`,
- description: creationResponse.detail.hint as TranslatedString,
- debug: creationResponse.detail,
- })
- case HttpStatusCode.Unauthorized: return notify({
- type: "error",
- title: i18n.str`No enough permission to create that account.`,
- description: creationResponse.detail.hint as TranslatedString,
- debug: creationResponse.detail,
- })
- case TalerErrorCode.BANK_REGISTER_PAYTO_URI_REUSE: return notify({
- type: "error",
- title: i18n.str`That account id is already taken.`,
- description: creationResponse.detail.hint as TranslatedString,
- debug: creationResponse.detail,
- })
- case TalerErrorCode.BANK_REGISTER_USERNAME_REUSE: return notify({
- type: "error",
- title: i18n.str`That username is already taken.`,
- description: creationResponse.detail.hint as TranslatedString,
- debug: creationResponse.detail,
- })
- case TalerErrorCode.BANK_RESERVED_USERNAME_CONFLICT: return notify({
- type: "error",
- title: i18n.str`That username can't be used because is reserved.`,
- description: creationResponse.detail.hint as TranslatedString,
- debug: creationResponse.detail,
- })
- case TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT: return notify({
- type: "error",
- title: i18n.str`Only admin is allow to set debt limit.`,
- description: creationResponse.detail.hint as TranslatedString,
- debug: creationResponse.detail,
- })
- default: assertUnreachable(creationResponse)
+ createAccount: {
+ const resp = await api.createAccount("" as AccessToken, { name, username, password });
+ if (resp.type === "fail") {
+ switch (resp.case) {
+ case HttpStatusCode.BadRequest: return notify({
+ type: "error",
+ title: i18n.str`Server replied with invalid phone or email.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({
+ type: "error",
+ title: i18n.str`Registration is disabled because the bank ran out of bonus credit.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case HttpStatusCode.Unauthorized: return notify({
+ type: "error",
+ title: i18n.str`No enough permission to create that account.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_REGISTER_PAYTO_URI_REUSE: return notify({
+ type: "error",
+ title: i18n.str`That account id is already taken.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_REGISTER_USERNAME_REUSE: return notify({
+ type: "error",
+ title: i18n.str`That username is already taken.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_RESERVED_USERNAME_CONFLICT: return notify({
+ type: "error",
+ title: i18n.str`That username can't be used because is reserved.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_NON_ADMIN_PATCH_DEBT_LIMIT: return notify({
+ type: "error",
+ title: i18n.str`Only admin is allow to set debt limit.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_MISSING_TAN_INFO: return notify({
+ type: "error",
+ title: i18n.str`No information for the selected authentication channel.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_TAN_CHANNEL_NOT_SUPPORTED: return notify({
+ type: "error",
+ title: i18n.str`Authentication channel is not supported.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case TalerErrorCode.BANK_NON_ADMIN_SET_TAN_CHANNEL: return notify({
+ type: "error",
+ title: i18n.str`Only admin can create accounts with second factor authentication.`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ default: assertUnreachable(resp)
+ }
}
}
- const resp = await api.getAuthenticationAPI(username).createAccessToken(password, {
- scope: "readwrite",
- duration: { d_us: "forever" },
- refreshable: true,
- })
+ login: {
+ const resp = await api.getAuthenticationAPI(username).createAccessToken(password, {
+ scope: "readwrite",
+ duration: { d_us: "forever" },
+ refreshable: true,
+ })
- if (resp.type === "ok") {
- backend.logIn({ username, token: resp.body.access_token });
- } else {
- switch (resp.case) {
- case "wrong-credentials": return notify({
- type: "error",
- title: i18n.str`Wrong credentials for "${username}"`,
- description: resp.detail.hint as TranslatedString,
- debug: resp.detail,
- })
- case "not-found": return notify({
- type: "error",
- title: i18n.str`Account not found`,
- description: resp.detail.hint as TranslatedString,
- debug: resp.detail,
- })
- default: assertUnreachable(resp)
+ if (resp.type === "ok") {
+ backend.logIn({ username, token: resp.body.access_token });
+ } else {
+ switch (resp.case) {
+ case "wrong-credentials": return notify({
+ type: "error",
+ title: i18n.str`Wrong credentials for "${username}"`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ case "not-found": return notify({
+ type: "error",
+ title: i18n.str`Account not found`,
+ description: resp.detail.hint as TranslatedString,
+ debug: resp.detail,
+ })
+ default: assertUnreachable(resp)
+ }
}
+
}
onComplete()
})