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 @@ -88,8 +88,6 @@ public String saveProfile(@ModelAttribute("user") User updatedData, Principal pr
existingUser.setLinkStyle(updatedData.getLinkStyle());
existingUser.setTextAlign(updatedData.getTextAlign());
existingUser.setButtonColor(updatedData.getButtonColor());
// Persist custom hex color (if any) - normalize to #rrggbb or null
existingUser.setCustomButtonColor(normalizeHex(updatedData.getCustomButtonColor()));
existingUser.setFontFamily(updatedData.getFontFamily());

// Keep only links that have both a title and a URL
Expand All @@ -110,22 +108,6 @@ public String saveProfile(@ModelAttribute("user") User updatedData, Principal pr
return "redirect:/dashboard?success";
}

// Normalize hex color strings: accepts '#abc', 'abc', '#aabbcc', 'aabbcc' -> returns '#aabbcc' or null if invalid
private String normalizeHex(String input) {
if (input == null) return null;
String v = input.trim();
if (v.isEmpty()) return null;
if (v.charAt(0) == '#') v = v.substring(1);
if (v.length() == 3 && v.matches("[0-9A-Fa-f]{3}")) {
// expand
return "#" + v.charAt(0) + v.charAt(0) + v.charAt(1) + v.charAt(1) + v.charAt(2) + v.charAt(2);
}
if (v.length() == 6 && v.matches("[0-9A-Fa-f]{6}")) {
return "#" + v;
}
return null;
}

@PostMapping("/dashboard/clear-background")
public String clearBackground(Principal principal) {
User user = userRepository.findByUsername(principal.getName()).orElseThrow(() -> new RuntimeException("User not found"));
Expand Down Expand Up @@ -216,17 +198,7 @@ private void addDashboardModelData(Model model, User user) {
model.addAttribute("linkStyles", java.util.Arrays.asList("pill", "box", "underline"));
model.addAttribute("textAlignments", java.util.Arrays.asList("center", "left"));
model.addAttribute("buttonColors", java.util.Arrays.asList("blue", "green", "red", "purple", "orange"));
model.addAttribute("fontFamilies", java.util.Arrays.asList(
"System",
"Georgia",
"Courier",
"Arial",
"Helvetica",
"Verdana",
"Times",
"Trebuchet",
"Palatino"
));
model.addAttribute("fontFamilies", java.util.Arrays.asList("System", "Georgia", "Courier", "Arial"));
model.addAttribute("backgrounds", loadBackgrounds());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,64 +28,18 @@ public String getCurrentUserProfile(Principal principal) {
return "redirect:/dashboard";
}

// Redirect to the explicit ID-based route to avoid ambiguity with username-based route
return "redirect:/profile/id/" + user.getId();
return "redirect:/profile/" + user.getId();
}

@GetMapping("/profile/id/{id}")
@GetMapping("/profile/{id}")
public String getProfileById(@PathVariable Long id, Model model) {
User user = profileService.getUserProfileById(id);

User user = profileService.getUserProfileByUsername(principal.getName());
if (user == null || user.getId() == null) {
return "redirect:/dashboard";
}

model.addAttribute("user", user);
return "profile";
}

@GetMapping("/profile")
public String searchProfile(Principal principal, Model model) {
if (principal == null) {
return "index";
}
return processUserInfoByUsername(principal.getName(), principal, model);
}

@GetMapping("/profile/{userName}")
public String getProfileByUsername(@PathVariable String userName, Principal principal, Model model) {
return processUserInfoByUsername(userName, principal, model);
}

// Helper Methods
private String processUserInfoByUsername(String userName, Principal principal, Model model) {
User user = profileService.getUserProfileByUsername(userName);
return settingMethodAttributes(principal, model, user);
}

private String processUserInfoById(Long id, Principal principal, Model model) {
User user = profileService.getUserProfileById(id);

private String settingMethodAttributes(Principal principal, Model model, User user) {
if (user == null) {
return "index";
}
if (principal == null) {
model.addAttribute("signedIn", false);
model.addAttribute("principalName", null);
} else if (profileService.getUserProfileByUsername(principal.getName()) != null) {
model.addAttribute("signedIn", true);
model.addAttribute("principalName", principal.getName());
}
if (principal != null && user.getUsername() != null && user.getUsername().equals(principal.getName())) {
model.addAttribute("usersProfile", true);
} else {
model.addAttribute("usersProfile", false);
return "error/404";
}

model.addAttribute("user", user);
return "profile";
}

}
2 changes: 0 additions & 2 deletions src/main/java/com/basecamp/HyprLink/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class User {
private String linkStyle;
private String textAlign;
private String buttonColor;
// Optional custom hex color input provided by user (e.g. #ff8800)
private String customButtonColor;
private String fontFamily;

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ public PasswordEncoder passwordEncoder() {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
// Public: home, login, register, static assets and the error page
.requestMatchers("/", "/login", "/register", "/register/check", "/css/**", "/images/**", "/error").permitAll()
// Public: profile pages and templates
.requestMatchers("/profile/**", "/templates").permitAll()
// Everything else requires authentication
.anyRequest().authenticated()
.requestMatchers("/register", "/login", "/css/**", "/images/**", "/profile/**", "/").permitAll() // Public pages
.anyRequest().authenticated() // Everything else requires login
)
.formLogin(form -> form
.loginPage("/login") // Custom login page
Expand Down
Loading
Loading