This commit is contained in:
Iliyan Angelov
2025-11-16 15:12:43 +02:00
parent 824eec6190
commit 93d4c1df80
54 changed files with 1606 additions and 1612 deletions

View File

@@ -1,34 +1,34 @@
# Chức năng 6: Quên Mật Khẩu (Forgot Password) - Hoàn Thành
# Function 6: Forgot Password - Completed
## 📦 Files Đã Tạo/Cập Nhật
## 📦 Files Created/Updated
### Frontend
1. **`client/src/pages/auth/ForgotPasswordPage.tsx`** - Component form quên mật khẩu
1. **`client/src/pages/auth/ForgotPasswordPage.tsx`** - Forgot password form component
2. **`client/src/pages/auth/index.ts`** - Export ForgotPasswordPage
3. **`client/src/App.tsx`** - Route `/forgot-password`
### Backend
4. **`server/src/controllers/authController.js`** - forgotPassword() & resetPassword()
5. **`server/src/routes/authRoutes.js`** - Routes cho forgot/reset password
5. **`server/src/routes/authRoutes.js`** - Routes for forgot/reset password
## ✨ Tính Năng Chính
## ✨ Main Features
### 1. Form State (Initial)
```
┌─────────────────────────────────────┐
│ 🏨 Hotel Icon (Blue) │
Quên mật khẩu?
Nhập email để nhận link...
Forgot password?
Enter email to receive link... │
├─────────────────────────────────────┤
│ ┌───────────────────────────────┐ │
│ │ Email │ │
│ │ [📧 email@example.com ] │ │
│ ├───────────────────────────────┤ │
│ │ [📤 Gửi link đặt lại MK] │ │
│ │ [📤 Send reset link] │ │
│ ├───────────────────────────────┤ │
│ │ ← Quay lại đăng nhập │ │
│ │ ← Back to login │ │
│ └───────────────────────────────┘ │
Chưa có tài khoản? Đăng ký ngay
Don't have an account? Sign up now
└─────────────────────────────────────┘
```
@@ -37,23 +37,23 @@
┌─────────────────────────────────────┐
│ ✅ Success Icon │
│ │
│ Email đã được gửi!
Chúng tôi đã gửi link đến
│ Email has been sent!
We have sent a link to
│ user@example.com │
├─────────────────────────────────────┤
Lưu ý:
│ • Link có hiệu lực trong 1 giờ
│ • Kiểm tra cả thư mục Spam/Junk
│ • Nếu không nhận được, thử lại
Note:
│ • Link is valid for 1 hour
│ • Check Spam/Junk folder
│ • If not received, try again
├─────────────────────────────────────┤
│ [📧 Gửi lại email] │
│ [← Quay lại đăng nhập]
│ [📧 Resend email]
│ [← Back to login]
└─────────────────────────────────────┘
```
### 3. Two-State Design Pattern
**Form State** - Nhập email
**Success State** - Hiển thị xác nhận & hướng dẫn
**Form State** - Enter email
**Success State** - Display confirmation & instructions
State management:
```typescript
@@ -61,19 +61,19 @@ const [isSuccess, setIsSuccess] = useState(false);
const [submittedEmail, setSubmittedEmail] = useState('');
```
## 🔧 Features Chi Tiết
## 🔧 Detailed Features
### 1. Validation (Yup Schema)
```typescript
email:
- Required: "Email là bắt buộc"
- Valid format: "Email không hợp lệ"
- Required: "Email is required"
- Valid format: "Invalid email format"
- Trim whitespace
```
### 2. Form Field
- **Email input** với Mail icon
- Auto-focus khi load page
- **Email input** with Mail icon
- Auto-focus when page loads
- Validation real-time
- Error message inline
@@ -82,12 +82,12 @@ email:
{isLoading ? (
<>
<Loader2 className="animate-spin" />
Đang xử ...
Processing...
</>
) : (
<>
<Send />
Gửi link đặt lại mật khẩu
Send reset link
</>
)}
```
@@ -104,15 +104,15 @@ email:
- Can resend email
**Action Buttons**
- "Gửi lại email" - Reset to form state
- "Quay lại đăng nhập" - Navigate to /login
- "Resend email" - Reset to form state
- "Back to login" - Navigate to /login
### 5. Help Section
```tsx
<div className="bg-white rounded-lg shadow-sm border">
<h3>Cần trợ giúp?</h3>
<h3>Need help?</h3>
<p>
Liên hệ: support@hotel.com hoặc 1900-xxxx
Contact: support@hotel.com or 1900-xxxx
</p>
</div>
```
@@ -267,7 +267,7 @@ CREATE TABLE password_reset_tokens (
2. Enter email address
3. Click "Gửi link đặt lại mật khẩu"
3. Click "Send reset link"
4. Frontend validation (Yup)
@@ -286,7 +286,7 @@ CREATE TABLE password_reset_tokens (
10. Click link → /reset-password/:token
11. Enter new password (Chức năng 7)
11. Enter new password (Function 7)
```
## 🧪 Test Scenarios
@@ -305,7 +305,7 @@ Expected:
```
Input: email = "notanemail"
Expected:
- Validation error: "Email không hợp lệ"
- Validation error: "Invalid email format"
- Form not submitted
```
@@ -313,7 +313,7 @@ Expected:
```
Input: email = ""
Expected:
- Validation error: "Email là bắt buộc"
- Validation error: "Email is required"
- Form not submitted
```
@@ -323,12 +323,12 @@ Action: Submit form
Expected:
- Button disabled
- Spinner shows
- Text: "Đang xử lý..."
- Text: "Processing..."
```
### Test Case 5: Resend email
```
Action: Click "Gửi lại email" in success state
Action: Click "Resend email" in success state
Expected:
- Return to form state
- Email field cleared
@@ -337,7 +337,7 @@ Expected:
### Test Case 6: Back to login
```
Action: Click "Quay lại đăng nhập"
Action: Click "Back to login"
Expected:
- Navigate to /login
```
@@ -482,7 +482,7 @@ never expose raw reset tokens in logs. To enable email sending:
---
**Status:**Chức năng 6 hoàn thành
**Next:** Chức năng 7 - Reset Password (form to change password with token)
**Status:**Function 6 completed
**Next:** Function 7 - Reset Password (form to change password with token)
**Test URL:** http://localhost:5173/forgot-password
**API:** POST /api/auth/forgot-password