Dự án này là một API quản lý người dùng được xây dựng bằng Laravel, cung cấp các chức năng cơ bản như đăng ký, đăng nhập, quản lý thông tin người dùng và phân quyền.
- Đăng ký tài khoản
- Đăng nhập và xác thực JWT
- Quản lý thông tin người dùng (xem, cập nhật, xóa)
- Phân quyền người dùng (admin, user)
- Đặt lại mật khẩu
- Tính năng "Nhớ mật khẩu"
-
- Yêu cầu hệ thống
- Cài đặt PHP, Composer, MySQL
- Cài đặt các công cụ phát triển
-
- Tạo project
- Cấu hình file .env
- Cài đặt các package cần thiết
-
- Cấu hình kết nối MySQL
- Tạo database
-
- Migration cho users table
- Migration cho password_reset_tokens table
- User model và các relationships
-
- Cài đặt jwt-auth package
- Cấu hình JWT
- Tích hợp JWT với User model
-
- AuthController (register, login, logout)
- UserController (CRUD operations)
- PasswordResetController
-
- API routes cho authentication
- API routes cho user management
- API routes cho password reset
- Route protection và middleware
-
Tạo middlewares cho phân quyền
- JWT Authentication middleware
- Admin Role middleware
- Active User middleware
-
Xây dựng chức năng quên mật khẩu
- Gmail/Email configuration
- Password reset tokens đã tạo trong migrations ở bước 4, tiếp tục triển khai
- Reset password flow
-
- Unit tests
- Feature tests
- API documentation với Postman/Swagger
- Test cases và scenarios
-
- Chuẩn bị môi trường production
- Security checklist
- Deployment process
- Monitoring và logging
POST /api/register- Đăng ký tài khoản mớiPOST /api/login- Đăng nhập và nhận JWT tokenPOST /api/logout- Đăng xuất (yêu cầu xác thực)POST /api/refresh- Làm mới JWT token (yêu cầu xác thực)GET /api/me- Lấy thông tin người dùng hiện tại (yêu cầu xác thực)
GET /api/users- Lấy danh sách người dùng (yêu cầu quyền admin)GET /api/users/{id}- Lấy thông tin chi tiết người dùng (yêu cầu xác thực)PUT /api/users/{id}- Cập nhật thông tin người dùng (yêu cầu xác thực)DELETE /api/users/{id}- Xóa người dùng (yêu cầu quyền admin)
POST /api/password/forgot- Gửi email đặt lại mật khẩuPOST /api/password/reset- Đặt lại mật khẩu
- id (primary key)
- name (string)
- email (string, unique)
- password (string, hashed)
- role (enum: 'admin', 'user')
- is_active (boolean)
- remember_token (string, nullable)
- email_verified_at (timestamp, nullable)
- created_at (timestamp)
- updated_at (timestamp)
- email (primary key)
- token (string)
- created_at (timestamp)
- email (primary key)
- token (string)
- created_at (timestamp)
- Tất cả các API endpoints (ngoại trừ đăng ký, đăng nhập và đặt lại mật khẩu) đều yêu cầu JWT token hợp lệ
- Token có thời hạn 1 giờ và có thể được làm mới
- Mật khẩu được mã hóa bằng thuật toán bcrypt
Dự án này được phân phối dưới giấy phép MIT.
- PHP >= 8.1
- Composer
- Node.js >= 16.x
- MySQL/MariaDB
- Angular CLI
# Clone repository
git clone <repository-url>
cd User_Management1_BE
# Cài đặt dependencies
composer install
# Tạo file .env từ .env.example (nếu có) hoặc tạo file .env mới
cp .env.example .env # hoặc tạo file .env thủ công
# Cấu hình database trong file .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=user_management
DB_USERNAME=your_username
DB_PASSWORD=your_password
# Cấu hình JWT
JWT_SECRET=your_jwt_secret_key
# Generate application key
php artisan key:generate
# Generate JWT secret key
php artisan jwt:secret
# Chạy migrations
php artisan migrate
# (Tùy chọn) Chạy seeders để tạo dữ liệu mẫu
php artisan db:seed
# Khởi động server
php artisan serveBackend sẽ chạy tại: http://localhost:8000
# Di chuyển vào thư mục frontend
cd frontend-cake
# Cài đặt dependencies
npm install
# Khởi động development server
npm start
# hoặc
ng serveFrontend sẽ chạy tại: http://localhost:4200
Đảm bảo trong frontend có cấu hình API endpoint trỏ đến backend:
- Backend API:
http://localhost:8000/api - Frontend:
http://localhost:4200
# Chạy tests
php artisan test
# Clear cache
php artisan cache:clear
php artisan config:clear
php artisan route:clear
# Xem routes
php artisan route:list
# Chạy với port tùy chỉnh
php artisan serve --port=8080# Build cho production
npm run build
# Chạy tests
npm test
# Chạy với port tùy chỉnh
ng serve --port=4300-
- Yêu cầu hệ thống
- Cài đặt PHP, Composer, MySQL
- Cài đặt các công cụ phát triển
-
- Tạo project
- Cấu hình file .env
- Cài đặt các package cần thiết
-
- Cấu hình kết nối MySQL
- Tạo database
-
- Migration cho users table
- Migration cho password_reset_tokens table
- User model và các relationships
-
- Cài đặt jwt-auth package
- Cấu hình JWT
- Tích hợp JWT với User model
-
- AuthController (register, login, logout)
- UserController (CRUD operations)
- PasswordResetController
-
- API routes cho authentication
- API routes cho user management
- API routes cho password reset
- Route protection và middleware
-
Tạo middlewares cho phân quyền
- JWT Authentication middleware
- Admin Role middleware
- Active User middleware
-
Xây dựng chức năng quên mật khẩu
- Gmail/Email configuration
- Password reset tokens đã tạo trong migrations ở bước 4, tiếp tục triển khai
- Reset password flow
-
- Unit tests
- Feature tests
- API documentation với Postman/Swagger
- Test cases và scenarios
-
- Chuẩn bị môi trường production
- Security checklist
- Deployment process
- Monitoring và logging
// ... existing code ...