diff --git a/src/data/auth.ts b/src/data/auth.ts index cf01f5990e..97d3541238 100644 --- a/src/data/auth.ts +++ b/src/data/auth.ts @@ -61,7 +61,18 @@ export const createAuthForUser = async ( password, }); -export const adminChangePassword = async ( +export const changePassword = ( + hass: HomeAssistant, + current_password: string, + new_password: string +) => + hass.callWS({ + type: "config/auth_provider/homeassistant/change_password", + current_password, + new_password, + }); + +export const adminChangePassword = ( hass: HomeAssistant, userId: string, password: string @@ -71,3 +82,8 @@ export const adminChangePassword = async ( user_id: userId, password, }); + +export const deleteAllRefreshTokens = (hass: HomeAssistant) => + hass.callWS({ + type: "auth/delete_all_refresh_tokens", + }); diff --git a/src/panels/profile/ha-change-password-card.ts b/src/panels/profile/ha-change-password-card.ts index 2c0a132656..0cab1d8903 100644 --- a/src/panels/profile/ha-change-password-card.ts +++ b/src/panels/profile/ha-change-password-card.ts @@ -14,6 +14,12 @@ import "../../components/ha-textfield"; import { haStyle } from "../../resources/styles"; import type { HomeAssistant } from "../../types"; import "../../components/ha-alert"; +import { + showAlertDialog, + showConfirmationDialog, +} from "../../dialogs/generic/show-dialog-box"; +import { RefreshToken } from "../../data/refresh_token"; +import { changePassword, deleteAllRefreshTokens } from "../../data/auth"; @customElement("ha-change-password-card") class HaChangePasswordCard extends LitElement { @@ -31,6 +37,8 @@ class HaChangePasswordCard extends LitElement { @state() private _passwordConfirm = ""; + @property({ attribute: false }) public refreshTokens?: RefreshToken[]; + protected render(): TemplateResult { return html` ` diff --git a/src/translations/en.json b/src/translations/en.json index 71961fca7a..9832871e57 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -5312,7 +5312,10 @@ "submit": "Submit", "error_new_mismatch": "Entered new password values do not match", "error_new_is_old": "New password must be different than current password", - "success": "Password changed successfully" + "success": "Password changed successfully", + "logout_all_sessions": "Do you want to log out from all devices?", + "logout_all_sessions_text": "This will require you to log in again on all devices with your new password, including this one.", + "delete_failed": "Not all devices could be logged out" }, "mfa": { "header": "Multi-factor authentication modules",