Reputation: 21
Sorry my english is bad
I have two class profile and EditProfile
in both class i have
protected void addContent(PageParameters pageParameters) {
final String email = pageParameters.get(ListUser.USER_EMAIL).toString();
final User loggedUser = getLoggedUser();
if (email == null) {
redirectToInterceptPage(new ErrorPage404(null));
return;
}
User userByEmail = userService.findByEmail(email);
if (userByEmail == null) {
redirectToInterceptPage(new ForbiddenPage403(null));
return;
}
final UserDetachableModel user = new UserDetachableModel(userByEmail);
// If the user is not active, there is no need to edit your profile.
if (!user.getObject().isActive()) {
redirectToInterceptPage(new ErrorPage404(null));
return;
}
// Only admins can see the profile of other users.
if (!loggedUser.getUserRole().equals(UserRole.ADMIN) && !loggedUser.getEmail().equalsIgnoreCase(email)) {
redirectToInterceptPage(new ForbiddenPage403(null));
return;
}
......PROCESS TO SEE PROFILE OR EDIT PROFILE........
}
I use a CustomMountedPage that i use to hide the serial number of wicket. Example http://HOST/Page/subPage?ID&PARAMS to see http://HOST/Page/subPage?PARAMS and access to another profile
How prevent duplicate code!!
Upvotes: 0
Views: 135