Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public ResponseEntity<Void> submitReview(
return ResponseEntity.ok().build();
}

@PreAuthorize("hasRole('USER')")
@GetMapping
public ResponseEntity<ReviewResponse> getMyReview(
@AuthenticationPrincipal CustomUserDetails userDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class SessionCreateRequest {
private double price;
private String whatsappGroupLink;

// Frontend sends OffsetDateTime with +05:30
// Frontend sends OffsetDateTime with +05:30
private OffsetDateTime startTime;
private OffsetDateTime endTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,28 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/api/v1/user/review/**"
).permitAll()

// User APIs
// PUBLIC: session browsing & reviews (NO LOGIN)
.requestMatchers(
HttpMethod.GET,
"/api/v1/sessions/**",
"/api/v1/user/review/**",
"/api/v1/blogs/**"
).permitAll()

// User APIs (LOGIN REQUIRED)
.requestMatchers(
"/api/v1/user/**",
"/api/v1/installments/**",
"/api/v1/payments/**"
).hasRole("USER")

// Public session browsing
.requestMatchers(HttpMethod.GET, "/api/v1/sessions/**").permitAll()

// Admin APIs
.requestMatchers("/api/v1/admin/**").hasRole("ADMIN")

.anyRequest().authenticated()
)


// THIS PREVENTS GOOGLE REDIRECTS
// .exceptionHandling(ex -> ex
// .authenticationEntryPoint((request, response, authException) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
public class AuthService {

private final UserRepository userRepository;
private final OtpRepository otpRepository; // ✅ ADD THIS
private final OtpRepository otpRepository;
private final PasswordEncoder passwordEncoder;
private final JwtUtil jwtUtil;

// ✅ UPDATE CONSTRUCTOR
public AuthService(
UserRepository userRepository,
OtpRepository otpRepository,
Expand All @@ -43,22 +42,27 @@ public void register(RegisterRequest request) {
throw new RuntimeException("Email is already in use");
}

if (!request.getContactNumber().matches("^[6-9]\\d{9}$")) {
String phone = request.getContactNumber().replaceAll("\\D", "");

if (phone.startsWith("91") && phone.length() == 12) {
phone = phone.substring(2);
}

if (!phone.matches("^[6-9]\\d{9}$")) {
throw new RuntimeException("Invalid contact number");
}

User user = User.builder()
.username(request.getUsername())
.email(request.getEmail())
.password(passwordEncoder.encode(request.getPassword()))
.contactNumber(request.getContactNumber())
.contactNumber(phone)
.role(Role.USER)
.isActive(true)
.build();

userRepository.save(user);
}

// ================= LOGIN =================
public String login(LoginRequest request) {

Expand Down