Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

WIP user password validation

Robin Dekkers170ea7e34c2f
diff --git a/ui/app/or-app/src/pages/page-roles.ts b/ui/app/or-app/src/pages/page-roles.ts
index c1d575631..0bae8e438 100644
--- a/ui/app/or-app/src/pages/page-roles.ts
+++ b/ui/app/or-app/src/pages/page-roles.ts
@@ -32,6 +32,7 @@ export function pageRolesProvider<S extends AppStateKeyed>(
};
}
+
@customElement("page-roles")
class PageRoles<S extends AppStateKeyed> extends Page<S> {
static get styles() {
@@ -48,27 +49,29 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
}
#title {
- margin: 0 auto;
- padding: 20px;
+ padding: 0 20px;
font-size: 18px;
font-weight: bold;
width: calc(100% - 40px);
- max-width: 1400px;
+ max-width: 1360px;
+ margin: 20px auto;
}
#title or-icon {
margin-right: 10px;
+ margin-left: 14px;
}
.panel {
- width: calc(100% - 80px);
- max-width: 1400px;
+ width: calc(100% - 90px);
+ padding: 0 20px;
+ max-width: 1320px;
background-color: white;
border: 1px solid #e5e5e5;
border-radius: 5px;
position: relative;
margin: 0 auto;
- padding: 20px;
+ padding: 24px;
}
.panel-title {
@@ -77,12 +80,29 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
line-height: 1em;
color: var(--internal-or-asset-viewer-title-text-color);
margin-bottom: 20px;
+ margin-top: 0;
flex: 0 0 auto;
letter-spacing: 0.025em;
}
- #table-users {
- width: 100%;
+
+ #table-roles,
+ #table-roles table{
+ width: 100%;
+ white-space: nowrap;
+ }
+
+ .mdc-data-table__row {
+ border-top-color: lightgrey;
+ }
+
+ td, th {
+ width: 25%;
+ border: none;
+ }
+
+ td.large, th.large {
+ width: 50%
}
.meta-item-container {
@@ -90,7 +110,7 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
overflow: hidden;
max-height: 0;
transition: max-height 0.25s ease-out;
- padding: 0 20px 0 30px;
+ padding: 0 20px;
}
or-input {
@@ -170,6 +190,9 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
.hide-mobile {
display: none;
}
+ td, th {
+ width: 50%
+ }
}
`,
];
@@ -234,6 +257,9 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
}
private _updateRoles() {
+ if(this._compositeRoles.some(role => role.compositeRoleIds.length === 0)) {
+ return
+ }
const roles = [...this._compositeRoles, ...this._roles];
manager.rest.api.UserResource.updateRoles(manager.displayRealm, roles).then(response => {
this.getRoles()
@@ -255,6 +281,27 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
}
+ private addRemoveRole(e, r, index) {
+ if(e.detail.value) {
+ this._compositeRoles[index].compositeRoleIds = [...this._compositeRoles[index].compositeRoleIds, r.id]
+ } else {
+ this._compositeRoles[index].compositeRoleIds = this._compositeRoles[index].compositeRoleIds.filter(id=> id !== r.id)
+ }
+ this.requestUpdate('_compositeRoles')
+ }
+
+ private expanderToggle(ev: MouseEvent, index:number) {
+ const metaRow = this.shadowRoot.getElementById('attribute-meta-row-'+index)
+ const expanderIcon = this.shadowRoot.getElementById('mdc-data-table-icon-'+index) as OrIcon
+ if(metaRow.classList.contains('expanded')){
+ metaRow.classList.remove("expanded");
+ expanderIcon.icon = "chevron-right";
+ } else {
+ metaRow.classList.add("expanded");
+ expanderIcon.icon = "chevron-down";
+ }
+ }
+
protected render(): TemplateResult | void {
if (!manager.authenticated) {
return html`
@@ -267,17 +314,7 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
<or-translate value="notSupported"></or-translate>
`;
}
- const expanderToggle = (ev: MouseEvent, index:number) => {
- const metaRow = this.shadowRoot.getElementById('attribute-meta-row-'+index)
- const expanderIcon = this.shadowRoot.getElementById('mdc-data-table-icon-'+index) as OrIcon
- if(metaRow.classList.contains('expanded')){
- metaRow.classList.remove("expanded");
- expanderIcon.icon = "chevron-right";
- } else {
- metaRow.classList.add("expanded");
- expanderIcon.icon = "chevron-down";
- }
- };
+
const readonly = !manager.hasRole(ClientRole.WRITE_USER);
const readRoles = this._roles.filter(role => role.name.includes('read')).sort((a, b) => a.name.localeCompare(b.name))
const writeRoles = this._roles.filter(role => role.name.includes('write')).sort((a, b) => a.name.localeCompare(b.name))
@@ -285,29 +322,28 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
return html`
<div id="wrapper">
<div id="title">
- <or-icon icon="account-group"></or-icon>${i18next.t(
- "role"
+ <or-icon icon="account-box-multiple"></or-icon>${i18next.t(
+ "role_plural"
)}
</div>
<div class="panel">
<p class="panel-title">${i18next.t("role")}</p>
- <div id="table-users" class="mdc-data-table">
+ <div id="table-roles" class="mdc-data-table">
<table class="mdc-data-table__table" aria-label="attribute list" >
<thead>
<tr class="mdc-data-table__header-row">
<th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="name"></or-translate></th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="description"></or-translate></th>
- <th class="mdc-data-table__header-cell hide-mobile" role="columnheader" scope="col"><or-translate value="permissions"></or-translate></th>
+ <th class="mdc-data-table__header-cell hide-mobile large" role="columnheader" scope="col"><or-translate value="permissions"></or-translate></th>
</tr>
</thead>
<tbody class="mdc-data-table__content">
${this._compositeRoles.map(
(role, index) => {
- const compositeRoleName = role.compositeRoleIds.map(id => this._rolesMapper[id]).join(', ');
+ const compositeRoleName = role.compositeRoleIds.map(id => this._rolesMapper[id]).sort((a, b) => a.localeCompare(b)).join(', ');
return html`
- <tr id="mdc-data-table-row-${index}" class="mdc-data-table__row" @click="${(ev) => expanderToggle(ev, index)}">
- <td
- class="padded-cell mdc-data-table__cell"
+ <tr id="mdc-data-table-row-${index}" class="mdc-data-table__row" @click="${(ev) => this.expanderToggle(ev, index)}">
+ <td class="padded-cell mdc-data-table__cell"
>
<or-icon id="mdc-data-table-icon-${index}" icon="chevron-right"></or-icon>
<span>${role.name}</span>
@@ -315,12 +351,12 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
<td class="padded-cell mdc-data-table__cell">
${role.description}
</td>
- <td class="padded-cell hide-mobile mdc-data-table__cell">
+ <td class="padded-cell hide-mobile mdc-data-table__cell large">
${compositeRoleName}
</td>
</tr>
- <tr id="attribute-meta-row-${index}" class="attribute-meta-row${!role.name ? " expanded" : ""}">
- <td colspan="4">
+ <tr id="attribute-meta-row-${index}" class="attribute-meta-row${!role.id ? " expanded" : ""}">
+ <td colspan="100%">
<div class="meta-item-container">
<div class="row">
@@ -338,7 +374,7 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
${readRoles.map(r => {
return html`
- <or-input ?readonly="${readonly}" .label="${r.name.split(":")[1]}: ${r.description}" .type="${InputType.CHECKBOX}" .value="${role.compositeRoleIds && role.compositeRoleIds.find(id => id === r.id)}" @or-input-changed="${(e: OrInputChangedEvent) => e.detail.value ? role.compositeRoleIds = [...role.compositeRoleIds, r.id]: role.compositeRoleIds = role.compositeRoleIds.filter(id=> id !== r.id) }"></or-input>
+ <or-input ?readonly="${readonly}" .label="${r.name.split(":")[1]}: ${r.description}" .type="${InputType.CHECKBOX}" .value="${role.compositeRoleIds && role.compositeRoleIds.find(id => id === r.id)}" @or-input-changed="${(e: OrInputChangedEvent) => this.addRemoveRole(e, r, index) }"></or-input>
`
})}
@@ -348,7 +384,7 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
<strong>${i18next.t("write")}</strong>
${writeRoles.map(r => {
return html`
- <or-input ?readonly="${readonly}" .label="${r.name.split(":")[1]}: ${r.description}" .type="${InputType.CHECKBOX}" .value="${role.compositeRoleIds && role.compositeRoleIds.find(id => id === r.id)}" @or-input-changed="${(e: OrInputChangedEvent) => e.detail.value ? role.compositeRoleIds = [...role.compositeRoleIds, r.id]: role.compositeRoleIds = role.compositeRoleIds.filter(id=> id !== r.id) }"></or-input>
+ <or-input ?readonly="${readonly}" .label="${r.name.split(":")[1]}: ${r.description}" .type="${InputType.CHECKBOX}" .value="${role.compositeRoleIds && role.compositeRoleIds.find(id => id === r.id)}" @or-input-changed="${(e: OrInputChangedEvent) => this.addRemoveRole(e, r, index) }"></or-input>
`
})}
</div>
@@ -357,20 +393,19 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
<div class="column">
${otherRoles.map(r => {
return html`
- <or-input ?readonly="${readonly}" .label="${r.name.split(":")[1]}: ${r.description}" .type="${InputType.CHECKBOX}" .value="${role.compositeRoleIds && role.compositeRoleIds.find(id => id === r.id)}" @or-input-changed="${(e: OrInputChangedEvent) => e.detail.value ? role.compositeRoleIds = [...role.compositeRoleIds, r.id]: role.compositeRoleIds = role.compositeRoleIds.filter(id=> id !== r.id) }"></or-input>
+ <or-input ?readonly="${readonly}" .label="${r.name.split(":")[1]}: ${r.description}" .type="${InputType.CHECKBOX}" .value="${role.compositeRoleIds && role.compositeRoleIds.find(id => id === r.id)}" @or-input-changed="${(e: OrInputChangedEvent) => this.addRemoveRole(e, r, index) }"></or-input>
`
})}
</div>
</div>
- <div class="row">
-
+ <div class="row" style="margin-bottom: 0;">
${role.id && !readonly ? html`
- <or-input .label="${i18next.t("delete")}" .type="${InputType.BUTTON}" @click="${() => this._deleteRole(role)}"></or-input>
- <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._updateRoles()}"></or-input>
+ <or-input .label="${i18next.t("delete")}" .type="${InputType.BUTTON}" @click="${() => this._deleteRole(role)}"></or-input>
+ <or-input ?disabled="${this._compositeRoles.some(role => role.compositeRoleIds.length === 0)}" style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._updateRoles()}"></or-input>
` : html`
<or-input .label="${i18next.t("cancel")}" .type="${InputType.BUTTON}" @click="${() => {this._compositeRoles.splice(-1,1); this._compositeRoles = [...this._compositeRoles]}}"></or-input>
- <or-input style="margin-left: auto;" .label="${i18next.t("create")}" .type="${InputType.BUTTON}" @click="${() => this._updateRoles()}"></or-input>
+ <or-input ?disabled="${this._compositeRoles.some(role => role.compositeRoleIds.length === 0)}" style="margin-left: auto;" .label="${i18next.t("create")}" .type="${InputType.BUTTON}" @click="${() => this._updateRoles()}"></or-input>
`}
</div>
</div>
@@ -380,8 +415,8 @@ class PageRoles<S extends AppStateKeyed> extends Page<S> {
})}
${!!this._compositeRoles[this._compositeRoles.length -1].id && !readonly ? html`
<tr class="mdc-data-table__row">
- <td colspan="4">
- <a class="button" @click="${() => this._compositeRoles = [...this._compositeRoles, {compositeRoleIds:[]}]}"><or-icon icon="plus"></or-icon><strong>${i18next.t("add")} ${i18next.t("role")}</strong></a>
+ <td colspan="100%">
+ <a class="button" @click="${() => this._compositeRoles = [...this._compositeRoles, {composite:true, name:"", compositeRoleIds:[]}]}"><or-icon icon="plus"></or-icon><strong>${i18next.t("add")} ${i18next.t("role")}</strong></a>
</td>
</tr>
` : ``}
diff --git a/ui/app/or-app/src/pages/page-users.ts b/ui/app/or-app/src/pages/page-users.ts
index f0698a19e..83f25c583 100644
--- a/ui/app/or-app/src/pages/page-users.ts
+++ b/ui/app/or-app/src/pages/page-users.ts
@@ -16,7 +16,7 @@ import { Page } from "../types";
import { ClientRole, Role, User } from "@openremote/model";
import { i18next } from "@openremote/or-translate";
import { OrIcon } from "@openremote/or-icon";
-import { InputType, OrInputChangedEvent } from "@openremote/or-input";
+import { InputType, OrInput, OrInputChangedEvent } from "@openremote/or-input";
import {showOkCancelDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
const tableStyle = require("@material/data-table/dist/mdc.data-table.css");
@@ -48,27 +48,28 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
}
#title {
- margin: 0 auto;
- padding: 20px;
+ padding: 0 20px;
font-size: 18px;
font-weight: bold;
width: calc(100% - 40px);
- max-width: 1400px;
+ max-width: 1360px;
+ margin: 20px auto;
}
#title or-icon {
margin-right: 10px;
+ margin-left: 14px;
}
.panel {
- width: calc(100% - 80px);
- max-width: 1400px;
+ width: calc(100% - 90px);
+ max-width: 1320px;
background-color: white;
border: 1px solid #e5e5e5;
border-radius: 5px;
position: relative;
margin: 0 auto;
- padding: 20px;
+ padding: 24px;
}
.panel-title {
@@ -77,12 +78,23 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
line-height: 1em;
color: var(--internal-or-asset-viewer-title-text-color);
margin-bottom: 20px;
+ margin-top: 0;
flex: 0 0 auto;
letter-spacing: 0.025em;
}
- #table-users {
+ #table-users,
+ #table-users table {
width: 100%;
+ white-space: nowrap;
+ }
+
+ .mdc-data-table__row {
+ border-top-color: lightgrey;
+ }
+
+ td, th {
+ width: 25%
}
.meta-item-container {
@@ -90,7 +102,7 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
overflow: hidden;
max-height: 0;
transition: max-height 0.25s ease-out;
- padding: 0 20px 0 30px;
+ padding: 0 20px;
}
or-input {
@@ -144,8 +156,11 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
.button or-icon {
--or-icon-fill: var(--or-app-color4);
}
-
- @media screen and (max-width: 769px){
+
+ @media screen and (max-width: 768px){
+ .hide-mobile {
+ display: none;
+ }
.row {
display: block;
flex-direction: column;
@@ -154,6 +169,10 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
.panel {
border-radius: 0;
}
+
+ td, th {
+ width: 50%
+ }
}
`,
];
@@ -229,24 +248,43 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
);
}
- private _createUser(user, passwords, role) {
- manager.rest.api.UserResource.create(manager.displayRealm, user).then((response:any) => {
- if(passwords && passwords.resetPassword && passwords.repeatPassword) {
- if(passwords.resetPassword !== passwords.repeatPassword) {
- this.validPassword = false;
- return;
+ private checkPassword(index) {
+
+
+ const repeatPasswordComponent = this.shadowRoot.getElementById("repeatPassword-"+index) as OrInput
+ const passwordComponent = this.shadowRoot.getElementById("password-"+index)
+
+ const repeatPassword = repeatPasswordComponent.shadowRoot.querySelector('input');
+ const password = passwordComponent.shadowRoot.querySelector('input');
+ if(repeatPassword.value !== password.value) {
+ if(repeatPasswordComponent) {
+ const error = i18next.t("samePassword");
+ repeatPassword.setCustomValidity(error);
+ repeatPasswordComponent.helperText = error;
}
- const credentials = {value: passwords.resetPassword}
- const id = response.data.id;
- manager.rest.api.UserResource.resetPassword(manager.displayRealm, id, credentials);
- if(role) {
- this._updateRole(response.data, role);
- } else {
- this.getUsers()
+ return false
+ } else {
+ if(repeatPasswordComponent) {
+ repeatPassword.setCustomValidity("");
+ repeatPasswordComponent.helperText = ""
}
+ return password.value
}
- });
-
+ }
+ private _createUser(user, index) {
+ const password = this.checkPassword(index)
+ manager.rest.api.UserResource.create(manager.displayRealm, user).then((response:any) => {
+ if(password){
+ const id = response.data.id;
+ const credentials = {value: password}
+ manager.rest.api.UserResource.resetPassword(manager.displayRealm, id, credentials);
+ }
+ if(this._userRoleMapper["newUser"]) {
+ this._updateRole(response.data, this._userRoleMapper["newUser"]);
+ } else {
+ this.getUsers()
+ }
+ });
}
private _updateRole(user, value) {
@@ -254,6 +292,7 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
const role = this._compositeRoles.find(c => c.id === value);
if(role){
role['assigned'] = true;
+ delete this._userRoleMapper["newUser"];
manager.rest.api.UserResource.updateUserRoles(manager.displayRealm, user.id, [role]).then(response => {
this.getUsers()
})
@@ -261,17 +300,14 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
}
}
- private _updateUser(user, passwords, role) {
- if(passwords && passwords.resetPassword && passwords.repeatPassword) {
- if(passwords.resetPassword !== passwords.repeatPassword) {
- this.validPassword = false;
- return;
- };
- const credentials = {value: passwords.resetPassword}
- manager.rest.api.UserResource.resetPassword(manager.displayRealm, user.id, credentials);
+ private _updateUser(user, index) {
+ const password = this.checkPassword(index)
+ if(password){
+ const credentials = {value: password}
+ manager.rest.api.UserResource.resetPassword(manager.displayRealm, user.id, credentials);
}
- if(role) {
- this._updateRole(user, role)
+ if(this._userRoleMapper[user.id]) {
+ this._updateRole(user, this._userRoleMapper[user.id])
}
manager.rest.api.UserResource.update(manager.displayRealm, user.id, user);
}
@@ -332,62 +368,64 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
<thead>
<tr class="mdc-data-table__header-row">
<th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="username"></or-translate></th>
- <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="email"></or-translate></th>
+ <th class="mdc-data-table__header-cell hide-mobile" role="columnheader" scope="col"><or-translate value="email"></or-translate></th>
<th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="user_role"></or-translate></th>
- <th class="mdc-data-table__header-cell" role="columnheader" scope="col"><or-translate value="status"></or-translate></th>
+ <th class="mdc-data-table__header-cell hide-mobile" role="columnheader" scope="col"><or-translate value="status"></or-translate></th>
</tr>
</thead>
<tbody class="mdc-data-table__content">
${this._users.map(
(user, index) => {
- let passwords = {resetPassword: "", repeatPassword:""};
- let role = undefined;
const isSameUser = user.username === manager.username;
return html`
<tr id="mdc-data-table-row-${index}" class="mdc-data-table__row" @click="${(ev) => expanderToggle(ev, index)}">
- <td
- class="padded-cell mdc-data-table__cell"
- >
+ <td class="padded-cell mdc-data-table__cell">
<or-icon id="mdc-data-table-icon-${index}" icon="chevron-right"></or-icon>
<span>${user.username}</span>
</td>
- <td class="padded-cell mdc-data-table__cell">
+ <td class="padded-cell mdc-data-table__cell hide-mobile">
${user.email}
</td>
- <td class="padded-cell mdc-data-table__cell">
+ <td class="padded-cell mdc-data-table__cell">
${this._userRoleMapper[user.id] ? this._userRoleMapper[user.id].name : null}
</td>
- <td class="padded-cell mdc-data-table__cell">
+ <td class="padded-cell mdc-data-table__cell hide-mobile">
${user.enabled ? "Active" : "In active"}
</td>
</tr>
- <tr id="attribute-meta-row-${index}" class="attribute-meta-row${!user.username ? " expanded" : ""}">
- <td colspan="4">
+ <tr id="attribute-meta-row-${index}" class="attribute-meta-row${!user.id ? " expanded" : ""}">
+ <td colspan="100%">
<div class="meta-item-container">
<div class="row">
<div class="column">
- <or-input ?readonly="${readonly}" .label="${i18next.t("user")}" .type="${InputType.TEXT}" min="1" required .value="${user.username}" @or-input-changed="${(e: OrInputChangedEvent) => user.username = e.detail.value}"></or-input>
+ <or-input ?readonly="${readonly}" .label="${i18next.t("username")}" .type="${InputType.TEXT}" min="1" required .value="${user.username}" @or-input-changed="${(e: OrInputChangedEvent) => user.username = e.detail.value}"></or-input>
<or-input ?readonly="${readonly}" .label="${i18next.t("email")}" .type="${InputType.EMAIL}" min="1" .value="${user.email}" @or-input-changed="${(e: OrInputChangedEvent) => user.email = e.detail.value}"></or-input>
<or-input ?readonly="${readonly}" .label="${i18next.t("firstName")}" .type="${InputType.TEXT}" min="1" .value="${user.firstName}" @or-input-changed="${(e: OrInputChangedEvent) => user.firstName = e.detail.value}"></or-input>
<or-input ?readonly="${readonly}" .label="${i18next.t("surname")}" .type="${InputType.TEXT}" min="1" .value="${user.lastName}" @or-input-changed="${(e: OrInputChangedEvent) => user.lastName = e.detail.value}"></or-input>
</div>
<div class="column">
- <or-input ?readonly="${readonly}" ?disabled="${isSameUser}" .value="${this._userRoleMapper[user.id] ? this._userRoleMapper[user.id].id : null}" .type="${InputType.SELECT}" .options="${selectOptions}" .label="${i18next.t("role")}" @or-input-changed="${(e: OrInputChangedEvent) => role = e.detail.value}"></or-input>
-
- <or-input ?readonly="${readonly}" .label="${i18next.t("password")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => passwords.resetPassword = e.detail.value}"></or-input>
- <or-input helperText="${this.validPassword ? "" : i18next.t("samePassword")}" helperPersistent ?readonly="${readonly}" .label="${i18next.t("repeatPassword")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => {passwords.repeatPassword = e.detail.value; }}"></or-input>
+ ${this._userRoleMapper[user.id] ? html`
+ <or-input ?readonly="${readonly}" ?disabled="${isSameUser}" .value="${this._userRoleMapper[user.id].id}" .type="${InputType.SELECT}" .options="${selectOptions}" .label="${i18next.t("role")}" @or-input-changed="${(e: OrInputChangedEvent) => {this._userRoleMapper[user.id] = e.detail.value;}}"></or-input>
+ ` : html`
+ <or-input ?readonly="${readonly}" ?disabled="${isSameUser}" .type="${InputType.SELECT}" .options="${selectOptions}" .label="${i18next.t("role")}" @or-input-changed="${(e: OrInputChangedEvent) => {this._userRoleMapper["newUser"] = e.detail.value;}}"></or-input>
+ `}
+
+ <or-input id="password-${index}" ?readonly="${readonly}" .label="${i18next.t("password")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => { this.checkPassword(index) }}"></or-input>
+ <or-input id="repeatPassword-${index}" helperPersistent ?readonly="${readonly}" .label="${i18next.t("repeatPassword")}" .type="${InputType.PASSWORD}" min="1" @or-input-changed="${(e: OrInputChangedEvent) => { this.checkPassword(index) }}"></or-input>
<or-input ?readonly="${readonly}" .label="${i18next.t("enabled")}" .type="${InputType.SWITCH}" min="1" required .value="${user.enabled}" @or-input-changed="${(e: OrInputChangedEvent) => user.enabled = e.detail.value}"></or-input>
</div>
</div>
- <div class="row">
+ <div class="row" style="margin-bottom: 0;">
${user.id && !readonly ? html`
- <or-input .label="${i18next.t("delete")}" .type="${InputType.BUTTON}" @click="${() => this._deleteUser(user)}"></or-input>
- <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._updateUser(user, passwords, role)}"></or-input>
+ ${!isSameUser ? html`
+ <or-input .label="${i18next.t("delete")}" .type="${InputType.BUTTON}" @click="${() => this._deleteUser(user)}"></or-input>
+ ` : ``}
+ <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._updateUser(user, index)}"></or-input>
` : html`
<or-input .label="${i18next.t("cancel")}" .type="${InputType.BUTTON}" @click="${() => {this._users.splice(-1,1); this._users = [...this._users]}}"></or-input>
- <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._createUser(user, passwords, role)}"></or-input>
+ <or-input style="margin-left: auto;" .label="${i18next.t("save")}" .type="${InputType.BUTTON}" @click="${() => this._createUser(user, index)}"></or-input>
`}
</div>
</div>
@@ -397,8 +435,8 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
})}
${!!this._users[this._users.length -1].id && !readonly ? html`
<tr class="mdc-data-table__row">
- <td colspan="4">
- <a class="button" @click="${() => this._users = [...this._users, {enabled: true}]}"><or-icon icon="plus"></or-icon><strong>${i18next.t("add")} ${i18next.t("user")}</strong></a>
+ <td colspan="100%">
+ <a class="button" @click="${() => this._users = [...this._users, {enabled: true}]}"><or-icon icon="plus"></or-icon><strong>${i18next.t("add")} ${i18next.t("user")}</strong></a>
</td>
</tr>
` : ``}
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 66eaf58c2..ecfaa12ee 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -402,6 +402,7 @@ const style = css`
#menu-anchor {
max-width: 100%;
+ width: 100%;
}
.mdc-checkbox-list input {
@@ -429,11 +430,14 @@ const style = css`
width: 32px;
}
+ .mdc-text-field.mdc-text-field--invalid:not(.mdc-text-field--disabled) + .mdc-text-field-helper-line .mdc-text-field-helper-text {
+ color: var(--mdc-theme-error, #b00020)
+ }
+
.mdc-checkbox-list input:checked + label {
color: var(--or-app-color2);
background-color: var(--mdc-theme-primary);
}
-
.or-input--rounded {
border-radius: 50% !important;
}
@@ -985,6 +989,7 @@ export class OrInput extends LitElement {
if (!(this.type === InputType.RANGE && this.disableSliderNumberInput)) {
const classes = {
"mdc-text-field": true,
+ "mdc-text-field--invalid": !this.valid,
"mdc-text-field--filled": !outlined,
"mdc-text-field--outlined": outlined,
"mdc-text-field--textarea": type === InputType.TEXTAREA || type === InputType.JSON,