if (!this.isLogin(context)) {
return this.handleSuccess(mapping, context, "login");
}
UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
ProfileForm profileForm = (ProfileForm) form;
UserProfile profile = context.getUserProfile();
UserPreference perference = userPersistence.getUserPreference(profile.getId());
if (profileForm.getHandle() == null) {
profileForm.populate(profile, perference);
context.setAttribute("ProfileForm", profileForm);
return this.handleSuccess(mapping, context, "failure");
}
if (userPersistence.login(profileForm.getHandle(), profileForm.getPassword()) == null) {
return this.handleFailure(mapping, context, "password", "ProfileForm.password.invalid");
}
UserProfile newProfile = profileForm.toUserProfile();
newProfile.setId(profile.getId());
newProfile.setRegDate(profile.getRegDate());
if (!profile.getHandle().equals(newProfile.getHandle())) {
return this.handleFailure(mapping, context, "handle", "ProfileForm.handle.changed");
}
if (!profile.getEmail().equals(newProfile.getEmail())) {
UserProfile temp = userPersistence.getUserProfileByEmail(newProfile.getEmail());
if (temp != null && temp.getId() != profile.getId()) {
return this.handleFailure(mapping, context, "email", "ProfileForm.email.used");
}
}
userPersistence.updateUserProfile(newProfile, profile.getId());