Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/api/plane/authentication/adapter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def validate_password(self, email):
results = zxcvbn(self.code)
if results["score"] < 3:
raise AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
error_message="INVALID_PASSWORD",
error_code=AUTHENTICATION_ERROR_CODES["PASSWORD_TOO_WEAK"],
error_message="PASSWORD_TOO_WEAK",
payload={"email": email},
)
return
Expand Down
1 change: 1 addition & 0 deletions apps/api/plane/authentication/adapter/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"USER_ACCOUNT_DEACTIVATED": 5019,
# Password strength
"INVALID_PASSWORD": 5020,
"PASSWORD_TOO_WEAK": 5021,
"SMTP_NOT_CONFIGURED": 5025,
# Sign Up
"USER_ALREADY_EXIST": 5030,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def post(self, request, uidb64, token):
results = zxcvbn(password)
if results["score"] < 3:
exc = AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
error_message="INVALID_PASSWORD",
error_code=AUTHENTICATION_ERROR_CODES["PASSWORD_TOO_WEAK"],
error_message="PASSWORD_TOO_WEAK",
)
url = urljoin(
base_host(request=request, is_app=True),
Expand Down
4 changes: 2 additions & 2 deletions apps/api/plane/authentication/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def post(self, request):
results = zxcvbn(new_password)
if results["score"] < 3:
exc = AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["INVALID_NEW_PASSWORD"],
error_message="INVALID_NEW_PASSWORD",
error_code=AUTHENTICATION_ERROR_CODES["PASSWORD_TOO_WEAK"],
error_message="PASSWORD_TOO_WEAK",
)
return Response(exc.get_error_dict(), status=status.HTTP_400_BAD_REQUEST)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def post(self, request, uidb64, token):
results = zxcvbn(password)
if results["score"] < 3:
exc = AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["INVALID_PASSWORD"],
error_message="INVALID_PASSWORD",
error_code=AUTHENTICATION_ERROR_CODES["PASSWORD_TOO_WEAK"],
error_message="PASSWORD_TOO_WEAK",
)
url = f"{base_host(request=request, is_space=True)}/accounts/reset-password/?{urlencode(exc.get_error_dict())}" # noqa: E501
return HttpResponseRedirect(url)
Expand Down
4 changes: 2 additions & 2 deletions apps/api/plane/license/api/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def post(self, request):
results = zxcvbn(password)
if results["score"] < 3:
exc = AuthenticationException(
error_code=AUTHENTICATION_ERROR_CODES["INVALID_ADMIN_PASSWORD"],
error_message="INVALID_ADMIN_PASSWORD",
error_code=AUTHENTICATION_ERROR_CODES["PASSWORD_TOO_WEAK"],
error_message="PASSWORD_TOO_WEAK",
payload={
"email": email,
"first_name": first_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getPasswordStrength } from "@plane/utils";
import { PageHead } from "@/components/core/page-title";
import { ProfileSettingContentHeader } from "@/components/profile/profile-setting-content-header";
// helpers
import { authErrorHandler } from "@/helpers/authentication.helper";
import { authErrorHandler, passwordErrors } from "@/helpers/authentication.helper";
import type { EAuthenticationErrorCodes } from "@/helpers/authentication.helper";
// hooks
import { useUser } from "@/hooks/store/user";
Expand Down Expand Up @@ -53,6 +53,7 @@ function SecurityPage() {
control,
handleSubmit,
watch,
setError,
formState: { errors, isSubmitting },
reset,
} = useForm<FormValues>({ defaultValues });
Expand Down Expand Up @@ -88,19 +89,23 @@ function SecurityPage() {
message: t("auth.common.password.toast.change_password.success.message"),
});
} catch (error: unknown) {
let errorInfo = undefined;
if (error instanceof Error) {
const err = error as Error & { error_code?: string };
const code = err.error_code?.toString();
errorInfo = code ? authErrorHandler(code as EAuthenticationErrorCodes) : undefined;
}
const err = error as Error & { error_code?: string };
const code = err.error_code?.toString();
const errorInfo = code ? authErrorHandler(code as EAuthenticationErrorCodes) : undefined;

setToast({
type: TOAST_TYPE.ERROR,
title: errorInfo?.title ?? t("auth.common.password.toast.error.title"),
message:
typeof errorInfo?.message === "string" ? errorInfo.message : t("auth.common.password.toast.error.message"),
});

if (code && passwordErrors.includes(code as EAuthenticationErrorCodes)) {
setError("new_password", {
type: "manual",
message: errorInfo?.message?.toString() || t("auth.common.password.toast.error.message"),
});
}
}
};

Expand Down Expand Up @@ -200,6 +205,7 @@ function SecurityPage() {
)}
</div>
{passwordSupport}
{errors.new_password && <span className="text-11 text-danger-primary">{errors.new_password.message}</span>}
{isNewPasswordSameAsOldPassword && !isPasswordInputFocused && (
<span className="text-11 text-danger-primary">
{t("new_password_must_be_different_from_old_password")}
Expand Down
14 changes: 12 additions & 2 deletions apps/web/app/(all)/profile/security/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { PageHead } from "@/components/core/page-title";
import { ProfileSettingContentHeader } from "@/components/profile/profile-setting-content-header";
import { ProfileSettingContentWrapper } from "@/components/profile/profile-setting-content-wrapper";
// helpers
import { authErrorHandler } from "@/helpers/authentication.helper";
import type { EAuthenticationErrorCodes } from "@/helpers/authentication.helper";
import { authErrorHandler, EAuthenticationErrorCodes, passwordErrors } from "@/helpers/authentication.helper";
// hooks
import { useUser } from "@/hooks/store/user";
// services
Expand Down Expand Up @@ -54,6 +53,7 @@ function SecurityPage() {
control,
handleSubmit,
watch,
setError,
formState: { errors, isSubmitting },
reset,
} = useForm<FormValues>({ defaultValues });
Expand Down Expand Up @@ -98,6 +98,13 @@ function SecurityPage() {
message:
typeof errorInfo?.message === "string" ? errorInfo.message : t("auth.common.password.toast.error.message"),
});

if (code && passwordErrors.includes(code as EAuthenticationErrorCodes)) {
setError("new_password", {
type: "manual",
message: errorInfo?.message?.toString() || t("auth.common.password.toast.error.message"),
});
}
}
};

Expand Down Expand Up @@ -198,6 +205,9 @@ function SecurityPage() {
)}
</div>
{passwordSupport}
{errors.new_password && (
<span className="text-11 text-danger-primary">{errors.new_password.message}</span>
)}
{isNewPasswordSameAsOldPassword && !isPasswordInputFocused && (
<span className="text-11 text-danger-primary">
{t("new_password_must_be_different_from_old_password")}
Expand Down
12 changes: 12 additions & 0 deletions apps/web/helpers/authentication.helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export enum EAuthenticationErrorCodes {
USER_ACCOUNT_DEACTIVATED = "5019",
// Password strength
INVALID_PASSWORD = "5020",
PASSWORD_TOO_WEAK = "5021",
SMTP_NOT_CONFIGURED = "5025",
// Sign Up
USER_ALREADY_EXIST = "5030",
Expand Down Expand Up @@ -101,6 +102,7 @@ export type TAuthErrorInfo = {
message: ReactNode;
};

// TODO: move all error messages to translation files
const errorCodeMessages: {
[key in EAuthenticationErrorCodes]: { title: string; message: (email?: string) => ReactNode };
} = {
Expand Down Expand Up @@ -137,6 +139,10 @@ const errorCodeMessages: {
title: `Invalid password`,
message: () => `Invalid password. Please try again.`,
},
[EAuthenticationErrorCodes.PASSWORD_TOO_WEAK]: {
title: `Password too weak`,
message: () => `Password too weak. Please try again.`,
},
[EAuthenticationErrorCodes.SMTP_NOT_CONFIGURED]: {
title: `SMTP not configured`,
message: () => `SMTP not configured. Please contact your administrator.`,
Expand Down Expand Up @@ -412,6 +418,7 @@ export const authErrorHandler = (errorCode: EAuthenticationErrorCodes, email?: s
EAuthenticationErrorCodes.ADMIN_USER_DOES_NOT_EXIST,
EAuthenticationErrorCodes.ADMIN_USER_DEACTIVATED,
EAuthenticationErrorCodes.RATE_LIMIT_EXCEEDED,
EAuthenticationErrorCodes.PASSWORD_TOO_WEAK,
];

if (bannerAlertErrorCodes.includes(errorCode))
Expand All @@ -424,3 +431,8 @@ export const authErrorHandler = (errorCode: EAuthenticationErrorCodes, email?: s

return undefined;
};

export const passwordErrors = [
EAuthenticationErrorCodes.PASSWORD_TOO_WEAK,
EAuthenticationErrorCodes.INVALID_NEW_PASSWORD,
];
1 change: 1 addition & 0 deletions packages/constants/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export enum EAuthErrorCodes {
USER_ACCOUNT_DEACTIVATED = "5019",
// Password strength
INVALID_PASSWORD = "5020",
PASSWORD_TOO_WEAK = "5021",
SMTP_NOT_CONFIGURED = "5025",
// Sign Up
USER_ALREADY_EXIST = "5030",
Expand Down
Loading