Skip to main content

Profile Module

6.Profile (Settings) Module

ProfileController​

Purpose​

The ProfileController manages user profile-related operations.
It allows users to:

  • View profile details
  • View and upload profile image
  • Change password

APIs​

MethodEndpointDescription
GET/profile/user/{id}Get user details
GET/profile/image/{id}Get profile image
POST/profile/imageUpload profile image
POST/profile/change-passwordChange password

1. Get User Details​

Request​

GET /profile/user/1

Response​

{
"id": 1,
"name": "Mrunali",
"email": "user@example.com",
"role": "Admin"
}

2. Get Profile Image​

Request​

GET /profile/image/1

Response​

  • Returns image as byte stream (JPEG)
  • Content-Type: image/jpeg

3. Upload Profile Image​

Request​

POST /profile/image

Form Data:

  • profileImage → Image file

Authentication​

  • Uses logged-in user (CustomUserDetails)
  • User ID extracted from token

Response​

"Image Uploaded Successfully"

Error Response​

"Upload Failed: <error message>"

4. Change Password​

Request​

POST /profile/change-password
{
"currentPassword": "old123",
"newPassword": "new123"
}

Response​

"Password updated"

Error Response​

"Current password incorrect"

ProfileService​

Purpose​

Handles business logic for profile operations such as fetching user data, uploading images, and updating passwords.


Main Methods​

1. getUserById(userId)​

  • Fetches user details

2. getProfileImage(userId)​

  • Retrieves profile image
  • Returns byte array

3. uploadProfileImage(userId, image)​

  • Validates file
  • Stores image in DB

4. changePassword(userId, dto)​

Flow​

  1. Fetch user from DB
  2. Validate current password
  3. Encode new password (BCrypt)
  4. Update in DB

Security (Important 🔐)​

  • Uses PasswordEncoder (BCrypt)
  • Password is never stored in plain text
  • Uses matches() for validation

Validation Rules​

FieldRule
userIdMust be valid
profile imageMust not be empty
currentPasswordMust match DB
newPasswordMust not be empty

Repository Layer (Database Operations)​


Stored Procedures Used​

ProcedurePurpose
sp_GetUserByIdFetch user details
sp_GetProfileImageFetch image
sp_UpdateProfileImageUpdate image
sp_UpdatePasswordUpdate password

Data Handling​

  • Image stored as byte[]
  • Password stored as hashed value
  • Uses SimpleJdbcCall

Profile Page (UI Behavior)​

Purpose​

Allows users to manage their personal account settings.


Features​

1. View Profile​

  • Displays user name, email, role

2. Profile Image​

  • View current profile image
  • Upload new image

3. Change Password​

  • Enter current password
  • Enter new password
  • Update securely