-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathUserPageController.java
More file actions
193 lines (175 loc) · 5.8 KB
/
Copy pathUserPageController.java
File metadata and controls
193 lines (175 loc) · 5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.digitalsanctuary.spring.user.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import com.digitalsanctuary.spring.user.dto.UserDto;
import com.digitalsanctuary.spring.user.persistence.model.User;
import com.digitalsanctuary.spring.user.service.DSUserDetails;
import com.digitalsanctuary.spring.user.web.IncludeUserInModel;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* MVC controller that serves user management HTML pages.
* <p>
* Handles page rendering for login, registration, password reset,
* profile update, and account management views. Each method returns
* a Thymeleaf template name for the corresponding user interface page.
* </p>
*
* @author Devon Hillard
*/
@Slf4j
@RequiredArgsConstructor
@Controller
@IncludeUserInModel
public class UserPageController {
@Value("${user.registration.facebookEnabled}")
private boolean facebookEnabled;
@Value("${user.registration.googleEnabled}")
private boolean googleEnabled;
@Value("${user.registration.keycloakEnabled}")
private boolean keycloakEnabled;
/**
* Login Page.
*
* @param userDetails the user details
* @param session the session
* @param model the model
*
* @return the string
*/
@GetMapping("${user.security.loginPageURI:/user/login.html}")
public String login(@AuthenticationPrincipal DSUserDetails userDetails, HttpSession session, ModelMap model) {
log.debug("UserPageController.login: userDetails: {}", userDetails);
if (session != null && session.getAttribute("error.message") != null) {
model.addAttribute("errormessage", session.getAttribute("error.message"));
session.removeAttribute("error.message");
}
model.addAttribute("googleEnabled", googleEnabled);
model.addAttribute("facebookEnabled", facebookEnabled);
model.addAttribute("keycloakEnabled", keycloakEnabled);
return "user/login";
}
/**
* Register Page.
*
* @param userDetails the user details
* @param session the session
* @param model the model
* @return the string
*/
@GetMapping("${user.security.registrationURI:/user/register.html}")
public String register(@AuthenticationPrincipal DSUserDetails userDetails, HttpSession session, ModelMap model) {
log.debug("UserPageController.register: userDetails: {}", userDetails);
if (session != null && session.getAttribute("error.message") != null) {
model.addAttribute("errormessage", session.getAttribute("error.message"));
session.removeAttribute("error.message");
}
model.addAttribute("googleEnabled", googleEnabled);
model.addAttribute("facebookEnabled", facebookEnabled);
model.addAttribute("keycloakEnabled", keycloakEnabled);
return "user/register";
}
/**
* Registration pending.
*
* @return the string
*/
@GetMapping("${user.security.registrationPendingURI:/user/registration-pending-verification.html}")
public String registrationPending() {
return "user/registration-pending-verification";
}
/**
* Registration complete.
*
* @param userDetails the user details
* @param session the session
* @param model the model
*
* @return the string
*/
@GetMapping("${user.security.registrationSuccessURI:/user/registration-complete.html}")
public String registrationComplete(@AuthenticationPrincipal DSUserDetails userDetails, HttpSession session,
ModelMap model) {
log.debug("UserPageController.registrationComplete: userDetails: {}", userDetails);
return "user/registration-complete";
}
/**
* Request new verification E mail.
*
* @return the string
*/
@GetMapping("${user.security.registrationNewVerificationURI:/user/request-new-verification-email.html}")
public String requestNewVerificationEMail() {
return "user/request-new-verification-email";
}
/**
* Forgot password.
*
* @return the string
*/
@GetMapping("${user.security.forgotPasswordURI:/user/forgot-password.html}")
public String forgotPassword() {
return "user/forgot-password";
}
/**
* Forgot password pending verification.
*
* @return the string
*/
@GetMapping("${user.security.forgotPasswordPendingURI:/user/forgot-password-pending-verification.html}")
public String forgotPasswordPendingVerification() {
return "user/forgot-password-pending-verification";
}
/**
* Forgot password change.
*
* @return the string
*/
@GetMapping("${user.security.forgotPasswordChangeURI:/user/forgot-password-change.html}")
public String forgotPasswordChange() {
return "user/forgot-password-change";
}
/**
* Displays the user profile update page with pre-populated user data.
*
* @param userDetails the user details
* @param request the request
* @param model the model
* @return the view name for the update user page
*/
@GetMapping("${user.security.updateUserURI:/user/update-user.html}")
public String updateUser(@AuthenticationPrincipal DSUserDetails userDetails, final HttpServletRequest request,
final ModelMap model) {
if (userDetails != null) {
User user = userDetails.getUser();
UserDto userDto = new UserDto();
userDto.setFirstName(user.getFirstName());
userDto.setLastName(user.getLastName());
model.addAttribute("user", userDto);
}
return "user/update-user";
}
/**
* Update password.
*
* @return the string
*/
@GetMapping("${user.security.updatePasswordURI:/user/update-password.html}")
public String updatePassword() {
return "user/update-password";
}
/**
* Delete account.
*
* @return the string
*/
@GetMapping("${user.security.deleteAccountURI:/user/delete-account.html}")
public String deleteAccount() {
return "user/delete-account";
}
}