mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Adjust username handling in the cloud panel register and login flows (#22118)
* Use lowercase when registering * Fallback to lowercase username if usernotfound is recieved * Adjust resend * handle reset password * limit with else * return early
This commit is contained in:
parent
c721afa137
commit
468660d235
@ -99,10 +99,11 @@ export class CloudForgotPassword extends LitElement {
|
|||||||
|
|
||||||
this._requestInProgress = true;
|
this._requestInProgress = true;
|
||||||
|
|
||||||
|
const doResetPassword = async (username: string) => {
|
||||||
try {
|
try {
|
||||||
await cloudForgotPassword(this.hass, email);
|
await cloudForgotPassword(this.hass, username);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fireEvent(this, "email-changed", { value: email });
|
fireEvent(this, "email-changed", { value: username });
|
||||||
this._requestInProgress = false;
|
this._requestInProgress = false;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
fireEvent(this, "cloud-done", {
|
fireEvent(this, "cloud-done", {
|
||||||
@ -112,12 +113,19 @@ export class CloudForgotPassword extends LitElement {
|
|||||||
});
|
});
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._requestInProgress = false;
|
this._requestInProgress = false;
|
||||||
|
const errCode = err && err.body && err.body.code;
|
||||||
|
if (errCode === "usernotfound" && username !== username.toLowerCase()) {
|
||||||
|
await doResetPassword(username.toLowerCase());
|
||||||
|
} else {
|
||||||
this._error =
|
this._error =
|
||||||
err && err.body && err.body.message
|
err && err.body && err.body.message
|
||||||
? err.body.message
|
? err.body.message
|
||||||
: "Unknown error";
|
: "Unknown error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
await doResetPassword(email);
|
||||||
|
}
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return [
|
return [
|
||||||
|
@ -227,8 +227,9 @@ export class CloudLogin extends LitElement {
|
|||||||
|
|
||||||
this._requestInProgress = true;
|
this._requestInProgress = true;
|
||||||
|
|
||||||
|
const doLogin = async (username: string) => {
|
||||||
try {
|
try {
|
||||||
const result = await cloudLogin(this.hass, email, password);
|
const result = await cloudLogin(this.hass, username, password);
|
||||||
fireEvent(this, "ha-refresh-cloud-status");
|
fireEvent(this, "ha-refresh-cloud-status");
|
||||||
this.email = "";
|
this.email = "";
|
||||||
this._password = "";
|
this._password = "";
|
||||||
@ -257,6 +258,10 @@ export class CloudLogin extends LitElement {
|
|||||||
navigate("/config/cloud/forgot-password");
|
navigate("/config/cloud/forgot-password");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (errCode === "usernotfound" && username !== username.toLowerCase()) {
|
||||||
|
await doLogin(username.toLowerCase());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._password = "";
|
this._password = "";
|
||||||
this._requestInProgress = false;
|
this._requestInProgress = false;
|
||||||
@ -274,6 +279,9 @@ export class CloudLogin extends LitElement {
|
|||||||
|
|
||||||
emailField.focus();
|
emailField.focus();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await doLogin(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleRegister() {
|
private _handleRegister() {
|
||||||
|
@ -197,9 +197,6 @@ export class CloudRegister extends LitElement {
|
|||||||
const emailField = this._emailField;
|
const emailField = this._emailField;
|
||||||
const passwordField = this._passwordField;
|
const passwordField = this._passwordField;
|
||||||
|
|
||||||
const email = emailField.value;
|
|
||||||
const password = passwordField.value;
|
|
||||||
|
|
||||||
if (!emailField.reportValidity()) {
|
if (!emailField.reportValidity()) {
|
||||||
passwordField.reportValidity();
|
passwordField.reportValidity();
|
||||||
emailField.focus();
|
emailField.focus();
|
||||||
@ -211,6 +208,9 @@ export class CloudRegister extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const email = emailField.value.toLowerCase();
|
||||||
|
const password = passwordField.value;
|
||||||
|
|
||||||
this._requestInProgress = true;
|
this._requestInProgress = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -229,23 +229,32 @@ export class CloudRegister extends LitElement {
|
|||||||
private async _handleResendVerifyEmail() {
|
private async _handleResendVerifyEmail() {
|
||||||
const emailField = this._emailField;
|
const emailField = this._emailField;
|
||||||
|
|
||||||
const email = emailField.value;
|
|
||||||
|
|
||||||
if (!emailField.reportValidity()) {
|
if (!emailField.reportValidity()) {
|
||||||
emailField.focus();
|
emailField.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const email = emailField.value;
|
||||||
|
|
||||||
|
const doResend = async (username: string) => {
|
||||||
try {
|
try {
|
||||||
await cloudResendVerification(this.hass, email);
|
await cloudResendVerification(this.hass, username);
|
||||||
this._verificationEmailSent(email);
|
this._verificationEmailSent(username);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
const errCode = err && err.body && err.body.code;
|
||||||
|
if (errCode === "usernotfound" && username !== username.toLowerCase()) {
|
||||||
|
await doResend(username.toLowerCase());
|
||||||
|
} else {
|
||||||
this._error =
|
this._error =
|
||||||
err && err.body && err.body.message
|
err && err.body && err.body.message
|
||||||
? err.body.message
|
? err.body.message
|
||||||
: "Unknown error";
|
: "Unknown error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await doResend(email);
|
||||||
|
}
|
||||||
|
|
||||||
private _verificationEmailSent(email: string) {
|
private _verificationEmailSent(email: string) {
|
||||||
this._requestInProgress = false;
|
this._requestInProgress = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user