Merge pull request 'issue-31' (#57) from issue-31 into main
Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/57 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
1358a015cf
65
src/App.tsx
65
src/App.tsx
|
|
@ -6,7 +6,7 @@ import { getCountryRuleByName } from './constants/countries';
|
||||||
import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types';
|
import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types';
|
||||||
import { API_BASE } from './services/api';
|
import { API_BASE } from './services/api';
|
||||||
import { loadRazorpayScript } from './services/razorpay';
|
import { loadRazorpayScript } from './services/razorpay';
|
||||||
import { cleanPhoneInput, validatePhoneNumber } from './utils/validation';
|
import { cleanPhoneInput, validatePhoneNumber, validatePassword } from './utils/validation';
|
||||||
|
|
||||||
// Modular Subcomponents
|
// Modular Subcomponents
|
||||||
import { StoreHeader } from './components/layout/StoreHeader';
|
import { StoreHeader } from './components/layout/StoreHeader';
|
||||||
|
|
@ -430,32 +430,12 @@ export default function App() {
|
||||||
const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register';
|
const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register';
|
||||||
|
|
||||||
if (authMode === 'register') {
|
if (authMode === 'register') {
|
||||||
if (authPassword.length < 8) {
|
const pwdError = validatePassword(authPassword, 'Password');
|
||||||
setAuthError('Password must be at least 8 characters long.');
|
if (pwdError) {
|
||||||
|
setAuthError(pwdError);
|
||||||
setAuthLoading(false);
|
setAuthLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!/[A-Z]/.test(authPassword)) {
|
|
||||||
setAuthError('Password must contain at least one uppercase letter.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[0-9]/.test(authPassword)) {
|
|
||||||
setAuthError('Password must contain at least one number.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (/\p{Extended_Pictographic}/u.test(authPassword)) {
|
|
||||||
setAuthError('Password must not contain emojis.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?`~]/.test(authPassword)) {
|
|
||||||
setAuthError('Password must contain at least one special character.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
|
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
|
||||||
|
|
@ -499,20 +479,9 @@ export default function App() {
|
||||||
setChangePasswordError('Please enter your current password.');
|
setChangePasswordError('Please enter your current password.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (changeNewPassword.length < 8) {
|
const pwdError = validatePassword(changeNewPassword, 'New password');
|
||||||
setChangePasswordError('New password must be at least 8 characters long.');
|
if (pwdError) {
|
||||||
return;
|
setChangePasswordError(pwdError);
|
||||||
}
|
|
||||||
if (!/[A-Z]/.test(changeNewPassword)) {
|
|
||||||
setChangePasswordError('New password must contain at least one uppercase letter.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[0-9]/.test(changeNewPassword)) {
|
|
||||||
setChangePasswordError('New password must contain at least one number.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[^A-Za-z0-9\s]/.test(changeNewPassword)) {
|
|
||||||
setChangePasswordError('New password must contain at least one special character.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (changeNewPassword !== changeConfirmPassword) {
|
if (changeNewPassword !== changeConfirmPassword) {
|
||||||
|
|
@ -581,23 +550,9 @@ export default function App() {
|
||||||
setAuthLoading(true);
|
setAuthLoading(true);
|
||||||
setAuthError(null);
|
setAuthError(null);
|
||||||
|
|
||||||
if (resetNewPassword.length < 8) {
|
const pwdError = validatePassword(resetNewPassword, 'New password');
|
||||||
setAuthError('New password must be at least 8 characters long.');
|
if (pwdError) {
|
||||||
setAuthLoading(false);
|
setAuthError(pwdError);
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[A-Z]/.test(resetNewPassword)) {
|
|
||||||
setAuthError('New password must contain at least one uppercase letter.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[0-9]/.test(resetNewPassword)) {
|
|
||||||
setAuthError('New password must contain at least one number.');
|
|
||||||
setAuthLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!/[^A-Za-z0-9\s]/.test(resetNewPassword)) {
|
|
||||||
setAuthError('New password must contain at least one special character.');
|
|
||||||
setAuthLoading(false);
|
setAuthLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import type { UserProfile, ModuleItem, Currency } from '../../types';
|
import type { UserProfile, ModuleItem, Currency } from '../../types';
|
||||||
import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries';
|
import { COUNTRY_CODES, getCountryRuleByName } from '../../constants/countries';
|
||||||
import { cleanPhoneInput } from '../../utils/validation';
|
import { cleanPhoneInput, SPECIAL_CHAR_REGEX } from '../../utils/validation';
|
||||||
|
|
||||||
interface ProfileDrawerProps {
|
interface ProfileDrawerProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
|
@ -289,9 +289,12 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
|
||||||
<span className={/[0-9]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
|
<span className={/[0-9]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
|
||||||
• 1 number
|
• 1 number
|
||||||
</span>
|
</span>
|
||||||
<span className={/[^A-Za-z0-9\s]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
|
<span className={SPECIAL_CHAR_REGEX.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
|
||||||
• 1 special char
|
• 1 special char
|
||||||
</span>
|
</span>
|
||||||
|
<span className={changeNewPassword.length > 0 && !/\s/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
|
||||||
|
• No spaces
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
|
|
@ -74,3 +74,40 @@ export const isValidPhoneNumber = (
|
||||||
): boolean => {
|
): boolean => {
|
||||||
return validatePhoneNumber(val, dialCode, country) === null;
|
return validatePhoneNumber(val, dialCode, country) === null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const SPECIAL_CHAR_REGEX = /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?`~]/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates password strength consistently across registration, profile change, and password reset:
|
||||||
|
* - Minimum 8 characters
|
||||||
|
* - No spaces (whitespace strictly disallowed)
|
||||||
|
* - At least one uppercase letter
|
||||||
|
* - At least one number
|
||||||
|
* - No emojis
|
||||||
|
* - At least one special character from standard symbol set
|
||||||
|
*/
|
||||||
|
export const validatePassword = (password: string, fieldName = 'Password'): string | null => {
|
||||||
|
if (!password) {
|
||||||
|
return `${fieldName} is required.`;
|
||||||
|
}
|
||||||
|
if (password.length < 8) {
|
||||||
|
return `${fieldName} must be at least 8 characters long.`;
|
||||||
|
}
|
||||||
|
if (/\s/.test(password)) {
|
||||||
|
return `${fieldName} must not contain spaces.`;
|
||||||
|
}
|
||||||
|
if (!/[A-Z]/.test(password)) {
|
||||||
|
return `${fieldName} must contain at least one uppercase letter.`;
|
||||||
|
}
|
||||||
|
if (!/[0-9]/.test(password)) {
|
||||||
|
return `${fieldName} must contain at least one number.`;
|
||||||
|
}
|
||||||
|
if (/\p{Extended_Pictographic}/u.test(password)) {
|
||||||
|
return `${fieldName} must not contain emojis.`;
|
||||||
|
}
|
||||||
|
if (!SPECIAL_CHAR_REGEX.test(password)) {
|
||||||
|
return `${fieldName} must contain at least one special character.`;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue