Skip to main content

Overview

The Profile Management system allows authenticated users to view and update their personal information, upload custom avatars, and manage their account settings. All profile operations are secured and restricted to the authenticated user.

User Profile Model

The user profile is based on Django’s AbstractUser with custom extensions (models.py:5-16):

Basic Info

Username, email, first name, and last name

Contact

Optional phone number field (max 10 characters)

Avatar

Profile picture uploaded to ‘avatars/’ directory
The email field is unique across all users and serves as a primary identifier for authentication.

Viewing Profile Information

Authenticated users can retrieve their complete profile data.

API Endpoint

URL: POST /api/users/profile/ Authentication: Required (IsAuthenticated) Response:

Implementation

The profile view endpoint (views.py:82-92):
The endpoint automatically uses request.user to retrieve the authenticated user’s profile, ensuring users can only access their own data.

Updating Profile Information

Users can update their profile details including personal information and avatar.

API Endpoint

URL: PUT /api/users/update-profile/<pk>/ Authentication: Required (IsAuthenticated) Content-Type: multipart/form-data (for avatar uploads) Request Body:
With Avatar:
Response:

Implementation

The update profile endpoint (views.py:95-117):
The endpoint includes authorization checks to ensure users can only update their own profiles: if user != request.user: return Response({"error": "Not authorized"}, ...)

Partial Updates

The endpoint supports partial updates (partial=True), allowing users to update specific fields without sending the entire profile:
This means you can update just the phone number:
Or just the avatar:

Avatar Support

The system supports profile picture uploads with specific handling.

Avatar Upload Process

1

File Selection

User selects an image file through the frontend upload component
2

Multipart Upload

File is sent as multipart/form-data in the PUT request
3

Server Processing

Backend receives file via request.FILES['avatar']
4

Storage

Image is saved to avatars/ directory in media storage
5

URL Generation

Django generates a URL path for accessing the uploaded image

Avatar Upload Component

The frontend includes a dedicated avatar uploader (AvatarUploader.jsx):

Supported Image Formats

The ImageField accepts common image formats:
  • JPEG (.jpg, .jpeg)
  • PNG (.png)
  • GIF (.gif)
  • WebP (.webp)
  • BMP (.bmp)
For optimal performance, consider implementing client-side image resizing before upload to reduce bandwidth and storage requirements.

Account Deletion

Users can permanently delete their accounts and all associated data.

API Endpoint

URL: DELETE /api/users/delete/<user_id>/ Authentication: Required (IsAuthenticated) Response:

Implementation

The delete user endpoint (views.py:121-129):
Cascade Deletion: When a user is deleted, all related data is automatically removed due to the on_delete=models.CASCADE setting on foreign keys. This includes:
  • All saved passwords
  • Uploaded avatar
  • Any other user-related data
This action is irreversible.

Confirmation Flow

Best practice is to implement a confirmation dialog:

Profile Features Summary

View Profile

Retrieve complete profile information including avatar URL

Update Info

Modify personal details with partial update support

Upload Avatar

Upload and update profile pictures with multipart support

Delete Account

Permanently remove account and all associated data

Frontend Profile Page

The profile page is implemented with a content component (Content.jsx) that displays and manages profile information:

Authorization Model

Profile management includes multiple layers of authorization:

Endpoint-Level Authorization

Requires valid JWT token in Authorization header.

User-Level Authorization

Ensures users can only modify their own profiles.

Automatic User Filtering

Automatically uses the authenticated user from the request.

Error Handling

Media Configuration

For avatar uploads to work properly, ensure your Django settings include:
settings.py
And in your URLs configuration:
urls.py
In production, serve media files through a CDN or object storage service like AWS S3 rather than directly from Django.

Best Practices

Input Validation

Validate email format, phone number length, and image file types before submission

Image Optimization

Resize images client-side to reduce upload time and storage costs

Error Feedback

Display clear, actionable error messages for validation failures

Confirmation Dialogs

Require confirmation for destructive actions like account deletion
Implement optimistic UI updates for better user experience: update the UI immediately and roll back if the API call fails.