@things-factory/auth-ui 8.0.0-beta.9 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/client/auth-style-sign.ts +194 -0
  2. package/client/bootstrap.ts +51 -0
  3. package/client/components/abstract-auth-page.ts +301 -0
  4. package/client/components/abstract-password-reset.ts +168 -0
  5. package/client/components/abstract-sign.ts +127 -0
  6. package/client/components/change-password.ts +153 -0
  7. package/client/components/contact-us.ts +113 -0
  8. package/client/components/create-domain-popup.ts +141 -0
  9. package/client/components/create-role.ts +123 -0
  10. package/client/components/create-user.ts +95 -0
  11. package/client/components/credential-manager.ts +64 -0
  12. package/client/components/delete-user-popup.ts +117 -0
  13. package/client/components/domain-switch.ts +127 -0
  14. package/client/components/invite-customer.ts +104 -0
  15. package/client/components/invite-user.ts +96 -0
  16. package/client/components/my-login-history.ts +101 -0
  17. package/client/components/ownership-transfer-popup.ts +110 -0
  18. package/client/components/partner-info-card.ts +89 -0
  19. package/client/components/partner-role-editor.ts +153 -0
  20. package/client/components/profile-component.ts +332 -0
  21. package/client/components/role-edit-form.ts +92 -0
  22. package/client/components/role-privilege-editor.ts +267 -0
  23. package/client/components/role-selector.ts +102 -0
  24. package/client/components/user-role-editor.ts +499 -0
  25. package/client/constants/application.ts +9 -0
  26. package/client/constants/index.ts +1 -0
  27. package/client/entries/auth/activate.ts +272 -0
  28. package/client/entries/auth/checkin.ts +190 -0
  29. package/client/entries/auth/forgot-password.ts +103 -0
  30. package/client/entries/auth/reset-password.ts +22 -0
  31. package/client/entries/auth/result.ts +193 -0
  32. package/client/entries/auth/signin.ts +18 -0
  33. package/client/entries/auth/signup.ts +109 -0
  34. package/client/entries/auth/unlock-user.ts +22 -0
  35. package/client/entries/oauth2/oauth2-decision-error-page.ts +50 -0
  36. package/client/entries/oauth2/oauth2-decision-page.ts +196 -0
  37. package/client/entries/public/home.ts +246 -0
  38. package/client/index.ts +124 -0
  39. package/client/pages/app-binding/app-binding.ts +423 -0
  40. package/client/pages/app-binding/app-bindings.ts +171 -0
  41. package/client/pages/appliance/appliance.ts +452 -0
  42. package/client/pages/appliance/home.ts +177 -0
  43. package/client/pages/appliance/register.ts +183 -0
  44. package/client/pages/application/application.ts +428 -0
  45. package/client/pages/application/applications.ts +182 -0
  46. package/client/pages/application/register.ts +211 -0
  47. package/client/pages/attribute/attribute-set-item-list.ts +237 -0
  48. package/client/pages/attribute/attribute-set-management.ts +282 -0
  49. package/client/pages/auth-provider/auth-provider-management.ts +381 -0
  50. package/client/pages/domain/domain-management.ts +410 -0
  51. package/client/pages/partner/partner-management.ts +112 -0
  52. package/client/pages/profile.ts +32 -0
  53. package/client/pages/role/role-management.ts +134 -0
  54. package/client/pages/user/user-management.ts +224 -0
  55. package/client/route.ts +67 -0
  56. package/client/themes/auth-theme.css +65 -0
  57. package/client/utils/password-rule.ts +37 -0
  58. package/dist-client/components/abstract-auth-page.js +10 -10
  59. package/dist-client/components/abstract-auth-page.js.map +1 -1
  60. package/dist-client/components/abstract-password-reset.d.ts +2 -1
  61. package/dist-client/components/abstract-password-reset.js +14 -7
  62. package/dist-client/components/abstract-password-reset.js.map +1 -1
  63. package/dist-client/components/abstract-sign.js +11 -12
  64. package/dist-client/components/abstract-sign.js.map +1 -1
  65. package/dist-client/components/contact-us.d.ts +1 -1
  66. package/dist-client/components/contact-us.js +7 -10
  67. package/dist-client/components/contact-us.js.map +1 -1
  68. package/dist-client/components/create-user.js +5 -28
  69. package/dist-client/components/create-user.js.map +1 -1
  70. package/dist-client/components/invite-user.js +11 -19
  71. package/dist-client/components/invite-user.js.map +1 -1
  72. package/dist-client/components/ownership-transfer-popup.js +3 -3
  73. package/dist-client/components/ownership-transfer-popup.js.map +1 -1
  74. package/dist-client/components/profile-component.d.ts +1 -5
  75. package/dist-client/components/profile-component.js +4 -64
  76. package/dist-client/components/profile-component.js.map +1 -1
  77. package/dist-client/components/role-privilege-editor.js +1 -2
  78. package/dist-client/components/role-privilege-editor.js.map +1 -1
  79. package/dist-client/components/user-role-editor.js +18 -18
  80. package/dist-client/components/user-role-editor.js.map +1 -1
  81. package/dist-client/entries/auth/checkin.js +1 -1
  82. package/dist-client/entries/auth/checkin.js.map +1 -1
  83. package/dist-client/entries/auth/forgot-password.js +2 -11
  84. package/dist-client/entries/auth/forgot-password.js.map +1 -1
  85. package/dist-client/entries/auth/signup.js +7 -13
  86. package/dist-client/entries/auth/signup.js.map +1 -1
  87. package/dist-client/index.js +1 -1
  88. package/dist-client/index.js.map +1 -1
  89. package/dist-client/pages/user/user-management.d.ts +1 -5
  90. package/dist-client/pages/user/user-management.js +7 -6
  91. package/dist-client/pages/user/user-management.js.map +1 -1
  92. package/dist-client/tsconfig.tsbuildinfo +1 -1
  93. package/dist-server/tsconfig.tsbuildinfo +1 -1
  94. package/package.json +12 -12
  95. package/server/index.ts +0 -0
  96. package/translations/en.json +2 -6
  97. package/translations/ja.json +2 -6
  98. package/translations/ko.json +2 -6
  99. package/translations/ms.json +2 -6
  100. package/translations/zh.json +2 -6
@@ -0,0 +1,110 @@
1
+ import '@material/web/button/elevated-button.js'
2
+
3
+ import gql from 'graphql-tag'
4
+ import { css, html, LitElement } from 'lit'
5
+ import { customElement, property, query } from 'lit/decorators.js'
6
+
7
+ import { client, gqlContext } from '@operato/graphql'
8
+ import { i18next, localize } from '@operato/i18n'
9
+ import { OxPrompt } from '@operato/popup/ox-prompt.js'
10
+
11
+ @customElement('ownership-transfer-popup')
12
+ class OwnershipTransferPopup extends localize(i18next)(LitElement) {
13
+ static styles = [
14
+ css`
15
+ :host {
16
+ display: flex;
17
+ flex-direction: column;
18
+ background-color: var(--md-sys-color-background);
19
+ padding: var(--spacing-large);
20
+ overflow: auto;
21
+ }
22
+ .container {
23
+ display: flex;
24
+ flex-direction: column;
25
+ flex: 1;
26
+ }
27
+ input {
28
+ border: var(--border-dim-color);
29
+ border-radius: var(--border-radius);
30
+ margin: var(--input-margin);
31
+ padding: var(--input-padding);
32
+ min-width: 250px;
33
+ font: var(--input-font);
34
+ }
35
+ .input-container {
36
+ margin: auto;
37
+ display: flex;
38
+ }
39
+ .input-container md-elevated-button {
40
+ margin: auto 0px auto var(--spacing-large);
41
+ }
42
+ `
43
+ ]
44
+
45
+ @property({ type: Object }) user: any
46
+
47
+ @query('input[name=email]') emailInput!: HTMLInputElement
48
+
49
+ render() {
50
+ return html`
51
+ <div class="container">
52
+ <div>${i18next.t('text.please enter the email of the user you want to transfer owner')}</div>
53
+ <div class="input-container">
54
+ <input name="email" />
55
+ <md-elevated-button @click=${this.transferOwnership}>${i18next.t('button.confirm')}</md-elevated-button>
56
+ </div>
57
+ </div>
58
+ `
59
+ }
60
+
61
+ async transferOwnership() {
62
+ if (!this.doubleCheckEmail()) {
63
+ this.showToast(i18next.t('text.email is not matched'))
64
+
65
+ return
66
+ }
67
+
68
+ if (
69
+ await OxPrompt.open({
70
+ title: i18next.t('text.are_you_sure'),
71
+ text: i18next.t('text.are_you_sure_to_transfer_owner'),
72
+ confirmButton: { text: i18next.t('button.confirm') },
73
+ cancelButton: { text: i18next.t('button.cancel') }
74
+ })
75
+ ) {
76
+ const response = await client.mutate({
77
+ mutation: gql`
78
+ mutation transferOwner($email: EmailAddress!) {
79
+ transferOwner(email: $email)
80
+ }
81
+ `,
82
+ variables: { email: this.user.email },
83
+ context: gqlContext()
84
+ })
85
+
86
+ if (!response.errors?.length) {
87
+ await OxPrompt.open({
88
+ type: 'success',
89
+ title: i18next.t('text.completed'),
90
+ text: i18next.t('text.owner_transfer_completed'),
91
+ confirmButton: { text: i18next.t('button.confirm') }
92
+ })
93
+
94
+ history.back()
95
+
96
+ this.dispatchEvent(new CustomEvent('ownershipTransferred', { bubbles: true, composed: true }))
97
+ }
98
+ } else {
99
+ history.back()
100
+ }
101
+ }
102
+
103
+ doubleCheckEmail() {
104
+ return this.emailInput.value === this.user.email
105
+ }
106
+
107
+ showToast(message) {
108
+ document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))
109
+ }
110
+ }
@@ -0,0 +1,89 @@
1
+ import { css, html, LitElement } from 'lit'
2
+ import { customElement, property } from 'lit/decorators.js'
3
+
4
+ import { i18next } from '@operato/i18n'
5
+
6
+ @customElement('partner-info-card')
7
+ export class PartnerInfoCard extends LitElement {
8
+ static styles = [
9
+ css`
10
+ input {
11
+ border: var(--border-dim-color);
12
+ border-radius: var(--border-radius);
13
+ margin: var(--input-margin);
14
+ padding: var(--input-padding);
15
+ background-color: transparent;
16
+ font: var(--input-font);
17
+
18
+ flex: 1;
19
+ }
20
+ #vendors {
21
+ display: flex;
22
+ max-height: 45vh;
23
+ flex-direction: row;
24
+ background-color: var(--md-sys-color-surface-variant);
25
+ margin: 0;
26
+ padding: 0;
27
+ border-radius: var(--border-radius);
28
+ box-shadow: var(--box-shadow);
29
+ overflow: hidden;
30
+ }
31
+ [field-2column] {
32
+ overflow: auto;
33
+ flex: 1;
34
+ background-color: var(--md-sys-color-surface-variant);
35
+ padding: var(--spacing-medium);
36
+ border-radius: var(--border-radius);
37
+ display: grid;
38
+ grid-template-columns: 1fr 1fr;
39
+ gap: 5px 15px;
40
+ clear: both;
41
+ max-width: var(--input-container-max-width);
42
+ }
43
+ [field] {
44
+ display: flex;
45
+ flex-direction: column;
46
+ padding-bottom: var(--spacing-medium);
47
+ }
48
+ label {
49
+ display: flex;
50
+ flex-direction: column;
51
+
52
+ font: var(--label-font);
53
+ color: var(--label-color, var(--md-sys-color-on-surface));
54
+ text-transform: var(--label-text-transform);
55
+ }
56
+ @media screen and (max-width: 480px) {
57
+ [field] {
58
+ grid-column: span 2;
59
+ }
60
+ }
61
+ `
62
+ ]
63
+
64
+ @property({ type: Object }) partner: any
65
+
66
+ render() {
67
+ const partner = this.partner || {}
68
+
69
+ return html`
70
+ <div id="vendors">
71
+ <div field-2column>
72
+ <div field>
73
+ <label
74
+ >${i18next.t('label.name')}
75
+ <input type="text" name="name" readonly .value=${partner.name || ''} />
76
+ </label>
77
+ </div>
78
+
79
+ <div field>
80
+ <label
81
+ >${i18next.t('label.description')}
82
+ <input type="text" name="description" readonly .value=${partner.description || ''} />
83
+ </label>
84
+ </div>
85
+ </div>
86
+ </div>
87
+ `
88
+ }
89
+ }
@@ -0,0 +1,153 @@
1
+ import '@material/web/button/elevated-button.js'
2
+ import './role-selector.js'
3
+
4
+ import gql from 'graphql-tag'
5
+ import { css, html, LitElement } from 'lit'
6
+ import { customElement, property, query } from 'lit/decorators.js'
7
+
8
+ import { client, gqlContext } from '@operato/graphql'
9
+ import { i18next, localize } from '@operato/i18n'
10
+ import { OxPrompt } from '@operato/popup/ox-prompt.js'
11
+ import { ButtonContainerStyles } from '@operato/styles'
12
+
13
+ import { RoleSelector } from './role-selector'
14
+
15
+ @customElement('partner-role-editor')
16
+ class PartnerRoleEditor extends localize(i18next)(LitElement) {
17
+ static styles = [
18
+ ButtonContainerStyles,
19
+ css`
20
+ :host {
21
+ display: flex;
22
+ flex-direction: column;
23
+
24
+ border: 1px solid var(--md-sys-color-primary);
25
+ padding: var(--spacing-medium);
26
+ font: normal 15px var(--theme-font);
27
+ color: var(--md-sys-color-secondary);
28
+ }
29
+
30
+ md-elevated-button {
31
+ margin-right: var(--spacing-small);
32
+ }
33
+ `
34
+ ]
35
+
36
+ @property({ type: Object }) customer: any
37
+ @property({ type: Array }) roles: any[] = []
38
+ @property({ type: Array }) grantingRoles: any[] = []
39
+
40
+ @query('role-selector') roleSelector!: RoleSelector
41
+
42
+ render() {
43
+ const roles = this.roles || []
44
+ const grantingRoles = this.grantingRoles || []
45
+
46
+ return html`
47
+ <role-selector .roles="${roles}" .userRoles="${grantingRoles}"></role-selector>
48
+
49
+ <div class="button-container">
50
+ <md-elevated-button @click=${this.onSave}>${i18next.t('button.save')}</md-elevated-button>
51
+ <md-elevated-button @click=${this.onTerminateContract} danger
52
+ >${i18next.t('button.terminate contract')}</md-elevated-button
53
+ >
54
+ </div>
55
+ `
56
+ }
57
+
58
+ updated(changes) {
59
+ if (changes.has('customer')) {
60
+ this.refreshRoles()
61
+ }
62
+ }
63
+
64
+ async refreshRoles() {
65
+ const response = await client.query({
66
+ query: gql`
67
+ query roles($customerId: String!) {
68
+ roles {
69
+ items {
70
+ id
71
+ name
72
+ description
73
+ }
74
+ total
75
+ }
76
+ grantingRoles(customerId: $customerId) {
77
+ id
78
+ role {
79
+ id
80
+ name
81
+ description
82
+ }
83
+ }
84
+ }
85
+ `,
86
+ variables: { customerId: this.customer.id },
87
+ context: gqlContext()
88
+ })
89
+
90
+ if (!response.errors?.length) {
91
+ this.roles = response.data.roles.items
92
+ this.grantingRoles = response.data.grantingRoles.map(grantingRole => grantingRole.role)
93
+ } else {
94
+ this.roles = []
95
+ this.grantingRoles = []
96
+ }
97
+ }
98
+
99
+ async onSave() {
100
+ const roles = this.roleSelector.selectedRoles()
101
+
102
+ const response = await client.mutate({
103
+ mutation: gql`
104
+ mutation grantRoles($customerId: String!, $roles: [RolePatch!]!) {
105
+ grantRoles(customerId: $customerId, roles: $roles)
106
+ }
107
+ `,
108
+ variables: { customerId: this.customer.id, roles },
109
+ context: gqlContext()
110
+ })
111
+
112
+ if (!response.errors?.length) {
113
+ this.showToast(i18next.t('text.data_updated_successfully'))
114
+ }
115
+ }
116
+
117
+ async onTerminateContract() {
118
+ if (
119
+ await OxPrompt.open({
120
+ title: i18next.t('text.are_you_sure'),
121
+ text: i18next.t('text.are_you_sure_to_terminate_contract'),
122
+ confirmButton: { text: i18next.t('button.terminate contract') },
123
+ cancelButton: { text: i18next.t('button.cancel') }
124
+ })
125
+ ) {
126
+ const response = await client.mutate({
127
+ mutation: gql`
128
+ mutation terminateContract($partnerName: String!) {
129
+ terminateContract(partnerName: $partnerName)
130
+ }
131
+ `,
132
+ variables: { partnerName: this.customer.name },
133
+ context: gqlContext()
134
+ })
135
+
136
+ if (!response.errors?.length) {
137
+ const answer = this.dispatchEvent(new CustomEvent('contractTerminated'))
138
+
139
+ if (answer) {
140
+ await OxPrompt.open({
141
+ type: 'success',
142
+ title: i18next.t('text.completed'),
143
+ confirmButton: { text: i18next.t('button.confirm') }
144
+ })
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+ showToast(message) {
151
+ document.dispatchEvent(new CustomEvent('notify', { detail: { message, option: { timer: 1000 } } }))
152
+ }
153
+ }
@@ -0,0 +1,332 @@
1
+ import '@operato/i18n/ox-i18n.js'
2
+ import '@operato/i18n/ox-i18n-selector.js'
3
+ import './change-password'
4
+ import './delete-user-popup'
5
+ import './my-login-history'
6
+
7
+ import { gql } from 'graphql-tag'
8
+ import { css, html, LitElement, nothing } from 'lit'
9
+ import { customElement, property, query, state } from 'lit/decorators.js'
10
+ import { startRegistration } from '@simplewebauthn/browser'
11
+
12
+ import { client } from '@operato/graphql'
13
+ import { i18next, localize } from '@operato/i18n'
14
+ import { notify, openPopup } from '@operato/layout'
15
+ import { auth, getLanguages } from '@things-factory/auth-base/dist-client'
16
+
17
+ const isAvailableWebauthn = 'PublicKeyCredential' in window
18
+ @customElement('profile-component')
19
+ export class ProfileComponent extends localize(i18next)(LitElement) {
20
+ static styles = [
21
+ css`
22
+ :host {
23
+ display: block;
24
+ background-color: var(--md-sys-color-background);
25
+ padding: 15px 0;
26
+ }
27
+ .wrap {
28
+ max-width: var(--profile-wrap-max-width, 400px);
29
+ margin: auto;
30
+ display: grid;
31
+ grid-template-columns: 1fr 1fr;
32
+ }
33
+
34
+ * {
35
+ box-sizing: border-box;
36
+ }
37
+
38
+ *:focus {
39
+ outline: none;
40
+ }
41
+
42
+ input {
43
+ margin: var(--spacing-small) 0;
44
+ border: 1px solid rgba(0, 0, 0, 0.2);
45
+ padding: 9px;
46
+ border-radius: var(--border-radius);
47
+ font: var(--auth-input-field-font);
48
+ width: var(--auth-input-field-width);
49
+ }
50
+ input:focus {
51
+ border: 1px solid var(--focus-background-color);
52
+ }
53
+
54
+ .user {
55
+ background: url(/assets/images/icon-profile.png) center top no-repeat;
56
+ margin: var(--profile-icon-margin);
57
+ padding: 180px 20px 20px 20px;
58
+ color: var(--md-sys-color-secondary);
59
+ font: var(--header-bar-title);
60
+ text-align: center;
61
+ }
62
+
63
+ hr {
64
+ width: 100%;
65
+ border: dotted 1px rgba(0, 0, 0, 0.1);
66
+ }
67
+
68
+ .wrap * {
69
+ grid-column: span 2;
70
+ }
71
+
72
+ label {
73
+ font: bold 14px var(--theme-font);
74
+ color: var(--md-sys-color-primary);
75
+ text-transform: capitalize;
76
+ grid-column: 1;
77
+ }
78
+
79
+ .wrap *.inline {
80
+ grid-column: unset;
81
+ }
82
+
83
+ ox-i18n-selector {
84
+ --i18n-selector-field-width: var(--auth-input-field-width);
85
+ --i18n-selector-field-margin: var(--change-password-field-margin);
86
+ --i18n-selector-field-padding: var(--spacing-medium);
87
+ --i18n-selector-field-border-radius: var(--border-radius);
88
+ margin: var(--change-password-field-margin);
89
+ }
90
+
91
+ md-text-button {
92
+ text-transform: capitalize;
93
+ }
94
+
95
+ footer {
96
+ padding: 20px;
97
+ text-align: center;
98
+ }
99
+
100
+ footer p {
101
+ font-size: 14px;
102
+ margin-bottom: 5px;
103
+ color: var(--md-sys-color-on-background);
104
+ }
105
+
106
+ footer a {
107
+ color: var(--md-sys-color-primary);
108
+ text-decoration: none;
109
+ font-weight: bold;
110
+ }
111
+ `
112
+ ]
113
+
114
+ @property({ type: String }) userId?: string
115
+ @property({ type: String }) email?: string
116
+ @property({ type: String }) name?: string
117
+
118
+ @state() languages: { code: string; display: string }[] = []
119
+ @state() passwordRule: {
120
+ lowerCase?: boolean
121
+ upperCase?: boolean
122
+ digit?: boolean
123
+ specialCharacter?: boolean
124
+ allowRepeat?: boolean
125
+ useTightPattern?: boolean
126
+ useLoosePattern?: boolean
127
+ tightCharacterLength?: number
128
+ looseCharacterLength?: number
129
+ } = {}
130
+
131
+ @query('#name') nameEl!: HTMLInputElement
132
+ @query('#locale') localeEl!: HTMLInputElement
133
+
134
+ async connectedCallback(): Promise<void> {
135
+ super.connectedCallback()
136
+
137
+ const response = await client.query({
138
+ query: gql`
139
+ query {
140
+ passwordRule {
141
+ lowerCase
142
+ upperCase
143
+ digit
144
+ specialCharacter
145
+ allowRepeat
146
+ useTightPattern
147
+ useLoosePattern
148
+ tightCharacterLength
149
+ looseCharacterLength
150
+ }
151
+ }
152
+ `
153
+ })
154
+
155
+ this.passwordRule = response.data
156
+ }
157
+
158
+ async firstUpdated() {
159
+ auth.on('profile', ({ credential }) => {
160
+ this.setCredential(credential)
161
+ })
162
+
163
+ this.setCredential(auth.credential)
164
+
165
+ this.languages = await getLanguages()
166
+ }
167
+
168
+ setCredential(credential) {
169
+ if (credential) {
170
+ this.userId = credential.id
171
+ this.name = credential.name
172
+ this.email = credential.email
173
+ } else {
174
+ this.userId = ''
175
+ this.name = ''
176
+ this.email = ''
177
+ }
178
+ }
179
+
180
+ render() {
181
+ return html`
182
+ <div class="wrap">
183
+ <div class="user">${this.email || ''}</div>
184
+
185
+ <label for="name"><ox-i18n slot="title" msgid="label.name"></ox-i18n></label>
186
+ <input id="name" @change=${e => this.onNameChanged(e.target.value)} .value=${this.name || ''} />
187
+
188
+ <hr />
189
+
190
+ <label for="locale"><ox-i18n slot="title" msgid="label.language"></ox-i18n></label>
191
+ <ox-i18n-selector
192
+ id="locale"
193
+ @change=${e => this.onLocaleChanged(e.detail)}
194
+ value=${i18next.language || 'en-US'}
195
+ .languages=${this.languages}
196
+ ></ox-i18n-selector>
197
+
198
+ <hr />
199
+
200
+ <label for="change-password">
201
+ <ox-i18n msgid="label.password"></ox-i18n>
202
+ </label>
203
+
204
+ <change-password id="change-password" .passwordRule=${this.passwordRule}></change-password>
205
+
206
+ ${isAvailableWebauthn
207
+ ? html`
208
+ <md-text-button @click=${() => this.registerUser()}
209
+ >${i18next.t('button.security-key registration')}</md-text-button
210
+ >
211
+ `
212
+ : nothing}
213
+
214
+ <footer>
215
+ <p>
216
+ ${i18next.t('text.click login history')}
217
+ <a href="javascript:void(0);" @click=${this.openLoginHistory.bind(this)}
218
+ >${i18next.t('label.login_history')}</a
219
+ >
220
+ </p>
221
+ </footer>
222
+ </div>
223
+ `
224
+ }
225
+
226
+ async onNameChanged(name) {
227
+ if (!name) return
228
+
229
+ var oldName = this.name
230
+
231
+ try {
232
+ const message = await auth.updateProfile({
233
+ name
234
+ })
235
+
236
+ notify({
237
+ level: 'info',
238
+ message
239
+ })
240
+ } catch (e: any) {
241
+ this.nameEl.value = oldName || ''
242
+
243
+ notify({
244
+ level: 'error',
245
+ message: 'message' in e ? e.message : e
246
+ })
247
+ }
248
+ }
249
+
250
+ async onLocaleChanged(value) {
251
+ if (!value) return
252
+
253
+ var oldLocale = i18next.language
254
+
255
+ try {
256
+ const message = await auth.updateProfile({
257
+ locale: value
258
+ })
259
+
260
+ i18next.changeLanguage(value)
261
+
262
+ notify({
263
+ level: 'info',
264
+ message
265
+ })
266
+ } catch (e: any) {
267
+ this.localeEl.value = oldLocale
268
+
269
+ notify({
270
+ level: 'error',
271
+ message: 'message' in e ? e.message : e
272
+ })
273
+ }
274
+ }
275
+
276
+ openLoginHistory() {
277
+ openPopup(html` <my-login-history></my-login-history> `, {
278
+ title: i18next.t('label.login_history')
279
+ })
280
+ }
281
+
282
+ deleteUser() {
283
+ openPopup(html` <delete-user-popup></delete-user-popup> `, {
284
+ title: i18next.t('label.delete account')
285
+ })
286
+ }
287
+
288
+ async registerUser() {
289
+ try {
290
+ const options = await fetch('/auth/register-webauthn/challenge').then(res => res.json())
291
+ const attResp = await startRegistration(options)
292
+ const verification = await fetch('/auth/verify-registration', {
293
+ method: 'POST',
294
+ headers: {
295
+ 'Content-Type': 'application/json'
296
+ },
297
+ body: JSON.stringify(attResp)
298
+ }).then(res => res.json())
299
+
300
+ if (verification.verified) {
301
+ notify({
302
+ level: 'info',
303
+ message: i18next.t('text.user credential registered successfully')
304
+ })
305
+ } else {
306
+ console.error(await verification.text())
307
+
308
+ notify({
309
+ level: 'error',
310
+ message: i18next.t('error.user credential registeration not allowed')
311
+ })
312
+ }
313
+ } catch (error) {
314
+ notify({
315
+ level: 'error',
316
+ message: i18next.t('error.user credential registeration failed')
317
+ })
318
+ }
319
+ }
320
+
321
+ get applicationMeta() {
322
+ var iconLink: HTMLLinkElement | null = document.querySelector('link[rel="application-icon"]')
323
+ var titleMeta: HTMLMetaElement | null = document.querySelector('meta[name="application-name"]')
324
+ var descriptionMeta: HTMLMetaElement | null = document.querySelector('meta[name="application-description"]')
325
+
326
+ return {
327
+ icon: iconLink?.href || '',
328
+ title: titleMeta?.content || 'Things Factory',
329
+ description: descriptionMeta?.content || 'Reimagining Software'
330
+ }
331
+ }
332
+ }