Add password confirmation to snapshot creation (#9349)

* Add password confirmation to snapshot creation

* Remove confirm_password before sending

* change layout

* style changes

* Adjust styling

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Joakim Sørensen 2021-06-07 10:45:20 +02:00 committed by GitHub
parent c68b76e2da
commit ce419fae7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 27 deletions

View File

@ -29,7 +29,6 @@ class SupervisorFormfieldLabel extends LitElement {
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return css` return css`
:host { :host {
cursor: pointer;
display: flex; display: flex;
align-items: center; align-items: center;
} }

View File

@ -85,6 +85,8 @@ export class SupervisorSnapshotContent extends LitElement {
@property() public snapshotPassword = ""; @property() public snapshotPassword = "";
@property() public confirmSnapshotPassword = "";
public willUpdate(changedProps) { public willUpdate(changedProps) {
super.willUpdate(changedProps); super.willUpdate(changedProps);
if (!this.hasUpdated) { if (!this.hasUpdated) {
@ -160,9 +162,9 @@ export class SupervisorSnapshotContent extends LitElement {
</ha-formfield> </ha-formfield>
</div>` </div>`
: ""} : ""}
${this.snapshot && this.snapshotType === "partial" ${this.snapshotType === "partial"
? html` ? html`<div class="partial-picker">
${this.snapshot.homeassistant ${this.snapshot && this.snapshot.homeassistant
? html` ? html`
<ha-formfield <ha-formfield
.label=${html`<supervisor-formfield-label .label=${html`<supervisor-formfield-label
@ -182,10 +184,6 @@ export class SupervisorSnapshotContent extends LitElement {
</ha-formfield> </ha-formfield>
` `
: ""} : ""}
`
: ""}
${this.snapshotType === "partial"
? html`
${foldersSection?.templates.length ${foldersSection?.templates.length
? html` ? html`
<ha-formfield <ha-formfield
@ -226,18 +224,19 @@ export class SupervisorSnapshotContent extends LitElement {
<div class="section-content">${addonsSection.templates}</div> <div class="section-content">${addonsSection.templates}</div>
` `
: ""} : ""}
` </div> `
: ""} : ""}
${!this.snapshot ${!this.snapshot
? html`<ha-formfield ? html`<ha-formfield
class="password"
.label=${this.supervisor.localize("snapshot.password_protection")} .label=${this.supervisor.localize("snapshot.password_protection")}
> >
<ha-checkbox <ha-checkbox
.checked=${this.snapshotHasPassword} .checked=${this.snapshotHasPassword}
@change=${this._toggleHasPassword} @change=${this._toggleHasPassword}
> >
</ha-checkbox </ha-checkbox>
></ha-formfield>` </ha-formfield>`
: ""} : ""}
${this.snapshotHasPassword ${this.snapshotHasPassword
? html` ? html`
@ -249,6 +248,18 @@ export class SupervisorSnapshotContent extends LitElement {
@value-changed=${this._handleTextValueChanged} @value-changed=${this._handleTextValueChanged}
> >
</paper-input> </paper-input>
${!this.snapshot
? html` <paper-input
.label=${this.supervisor.localize(
"snapshot.confirm_password"
)}
type="password"
name="confirmSnapshotPassword"
.value=${this.confirmSnapshotPassword}
@value-changed=${this._handleTextValueChanged}
>
</paper-input>`
: ""}
` `
: ""} : ""}
`; `;
@ -256,35 +267,38 @@ export class SupervisorSnapshotContent extends LitElement {
static get styles(): CSSResultGroup { static get styles(): CSSResultGroup {
return css` return css`
ha-checkbox { .partial-picker ha-formfield {
--mdc-checkbox-touch-target-size: 16px;
display: block; display: block;
margin: 4px 12px 8px 0;
} }
ha-formfield { .partial-picker ha-checkbox {
display: contents; --mdc-checkbox-touch-target-size: 32px;
}
.partial-picker {
display: block;
margin: 0px -6px;
padding-right: 6px;
padding-bottom: 8px;
border-bottom: 1px solid var(--divider-color);
} }
supervisor-formfield-label { supervisor-formfield-label {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
} }
paper-input[type="password"] {
display: block;
margin: 4px 0 4px 16px;
}
.details { .details {
color: var(--secondary-text-color); color: var(--secondary-text-color);
} }
.section-content { .section-content {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-left: 16px; margin-left: 30px;
} }
.security { ha-formfield.password {
margin-top: 16px; display: block;
margin: 0 -14px -16px;
} }
.snapshot-types { .snapshot-types {
display: flex; display: flex;
margin-left: -13px;
} }
.sub-header { .sub-header {
margin-top: 8px; margin-top: 8px;
@ -303,6 +317,9 @@ export class SupervisorSnapshotContent extends LitElement {
if (this.snapshotHasPassword) { if (this.snapshotHasPassword) {
data.password = this.snapshotPassword; data.password = this.snapshotPassword;
if (!this.snapshot) {
data.confirm_password = this.confirmSnapshotPassword;
}
} }
if (this.snapshotType === "full") { if (this.snapshotType === "full") {

View File

@ -95,16 +95,25 @@ class HassioCreateSnapshotDialog extends LitElement {
this._creatingSnapshot = true; this._creatingSnapshot = true;
this._error = ""; this._error = "";
if ( if (snapshotDetails.password && !snapshotDetails.password.length) {
this._snapshotContent.snapshotHasPassword &&
!this._snapshotContent.snapshotPassword.length
) {
this._error = this._dialogParams!.supervisor.localize( this._error = this._dialogParams!.supervisor.localize(
"snapshot.enter_password" "snapshot.enter_password"
); );
this._creatingSnapshot = false; this._creatingSnapshot = false;
return; return;
} }
if (
snapshotDetails.password &&
snapshotDetails.password !== snapshotDetails.confirm_password
) {
this._error = this._dialogParams!.supervisor.localize(
"snapshot.passwords_not_matching"
);
this._creatingSnapshot = false;
return;
}
delete snapshotDetails.confirm_password;
try { try {
if (this._snapshotContent.snapshotType === "full") { if (this._snapshotContent.snapshotType === "full") {

View File

@ -41,6 +41,7 @@ export interface HassioSnapshotDetail extends HassioSnapshot {
export interface HassioFullSnapshotCreateParams { export interface HassioFullSnapshotCreateParams {
name: string; name: string;
password?: string; password?: string;
confirm_password?: string;
} }
export interface HassioPartialSnapshotCreateParams export interface HassioPartialSnapshotCreateParams
extends HassioFullSnapshotCreateParams { extends HassioFullSnapshotCreateParams {

View File

@ -3924,9 +3924,11 @@
"addons": "Add-ons", "addons": "Add-ons",
"folders": "Folders", "folders": "Folders",
"password": "Snapshot password", "password": "Snapshot password",
"confirm_password": "Confirm Snapshot password",
"password_protection": "Password protection", "password_protection": "Password protection",
"password_protected": "password protected", "password_protected": "password protected",
"enter_password": "Please enter a password.", "enter_password": "Please enter a password.",
"passwords_not_matching": "The passwords does not match",
"folder": { "folder": {
"homeassistant": "Home Assistant configuration", "homeassistant": "Home Assistant configuration",
"ssl": "SSL", "ssl": "SSL",