Skip to content

Commit

Permalink
#294 remove change password
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausRicharz committed Feb 8, 2024
1 parent 89999a6 commit c4a0757
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 164 deletions.
70 changes: 1 addition & 69 deletions src/main/java/org/tb/user/ShowSettingsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
import lombok.RequiredArgsConstructor;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.springframework.stereotype.Component;
import org.tb.common.GlobalConstants;
import org.tb.common.struts.LoginRequiredAction;
import org.tb.common.util.SecureHashUtils;
import org.tb.employee.domain.Employee;
import org.tb.employee.persistence.EmployeeDAO;

@Component
Expand All @@ -27,71 +22,8 @@ protected ActionForward executeAuthenticated(ActionMapping mapping,
ShowSettingsForm settingsForm, HttpServletRequest request,
HttpServletResponse response) throws Exception {

request.setAttribute("passwordchanged", false);
request.setAttribute("userAccessTokens", userAccessTokenService.getTokens(authorizedUser.getEmployeeId()));

if ("changePassword".equalsIgnoreCase(request.getParameter("task"))) {
ActionMessages errorMessages = validatePassword(request, settingsForm);
if (!errorMessages.isEmpty()) {
return mapping.getInputForward();
}

// get employee
Employee loginEmployee = (Employee) request.getSession().getAttribute("loginEmployee");

// set new password and save
if(userService.changePassword(loginEmployee.getId(), settingsForm.getNewpassword())) {
request.setAttribute("passwordchanged", true);
return mapping.findForward("success");
} else {
ActionMessages messages = new ActionMessages();
messages.add("newpassword", new ActionMessage("form.settings.error.newpassword.violates.rules"));
saveErrors(request, messages);
return mapping.getInputForward();
}
} else {
// task == null -> standard procedure
return mapping.findForward("success");
}
}

private ActionMessages validatePassword(HttpServletRequest request,
ShowSettingsForm settingsForm) {

ActionMessages errors = getErrors(request);
if (errors == null) errors = new ActionMessages();

String oldPassword = settingsForm.getOldpassword();
String newPassword = settingsForm.getNewpassword();
String confirmPassword = settingsForm.getConfirmpassword();

//old password
Employee loginEmployee = (Employee) request.getSession().getAttribute("loginEmployee");
String passwordFromDB = employeeDAO.getEmployeeById(loginEmployee.getId()).getPassword();
if (oldPassword == null || !SecureHashUtils.passwordMatches(oldPassword, passwordFromDB)) {
errors.add("oldpassword", new ActionMessage("form.settings.error.oldpassword.false"));
}

// new password
if (newPassword == null || newPassword.length() < GlobalConstants.EMPLOYEE_PASSWORD_MIN_LENGTH) {
// new password is missing or too short
errors.add("newpassword", new ActionMessage("form.settings.error.newpassword.tooshort"));
} else if (newPassword.length() > GlobalConstants.EMPLOYEE_PASSWORD_MAX_LENGTH) {
// new password is too long
errors.add("newpassword", new ActionMessage("form.settings.error.newpassword.toolong"));
}

// confirm new password
if (confirmPassword == null) {
// confirm password is missing
errors.add("confirmpassword", new ActionMessage("form.settings.error.confirmpassword.missing"));
} else if (!confirmPassword.equals(newPassword)) {
// confirm password does not match with new password
errors.add("confirmpassword", new ActionMessage("form.settings.error.confirmpassword.false"));
}

saveErrors(request, errors);
return errors;
return mapping.findForward("success");
}

@Override
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/org/tb/user/ShowSettingsForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,4 @@
@Setter
public class ShowSettingsForm extends ActionForm {
private static final long serialVersionUID = 1L; // 4564667507077065751L;

private String oldpassword;
private String newpassword;
private String confirmpassword;

@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
oldpassword = "";
newpassword = "";
confirmpassword = "";
}

}
84 changes: 1 addition & 83 deletions src/main/webapp/user/showSettings.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
<html>
<head>
<title><bean:message key="main.general.application.title" /> -
<bean:message key="main.general.mainmenu.settings.title.text" /></title>
<bean:message key="main.general.mainmenu.settings.titl‚e.text" /></title>
<jsp:include flush="true" page="/head-includes.jsp" />
<script type="text/javascript" language="JavaScript">
function setStoreAction(form, actionVal) {
form.action = "/do/ShowSettings?task=" + actionVal;
form.submit();
}
</script>
</head>
<body>
<jsp:include flush="true" page="/menu.jsp">
Expand All @@ -23,82 +17,6 @@
<bean:message key="main.general.mainmenu.settings.title.text" />:<br>
</span>
<br>
<html:form action="/ShowSettings">
<table border="0" cellspacing="0" cellpadding="2"
class="center backgroundcolor">

<tr>
<td colspan="2" align="left" class="noBborderStyle">
<h3><bean:message key="main.settings.changepassword.text" /></h3>
</td>
<td class="noBborderStyle"></td>
</tr>
<tr>
<td colspan="2" align="left" class="noBborderStyle"><span
style="font-size:10pt;font-weight:bold;"><bean:message
key="main.settings.rule.text" /></span><br>
<bean:message key="main.settings.rule1.text" /><br>
<bean:message key="main.settings.rule3.text" /><br>
<bean:message key="main.settings.rule4.text" /><br>
&nbsp;&nbsp;<bean:message key="main.settings.rule41.text" /><br>
&nbsp;&nbsp;<bean:message key="main.settings.rule42.text" /><br>
&nbsp;&nbsp;<bean:message key="main.settings.rule43.text" /><br>
&nbsp;&nbsp;<bean:message key="main.settings.rule44.text" /><br>
</td>
<td class="noBborderStyle"></td>
</tr>
<tr>
<td colspan="2" align="left" class="noBborderStyle">&nbsp;</td>
</tr>
<tr>
<td align="left" class="noBborderStyle"><b><bean:message
key="main.settings.password.old.text" />:</b></td>
<td align="left" class="noBborderStyle"><html:password
property="oldpassword" size="30" /> <span style="color:red"><html:errors
property="oldpassword" /></span></td>
</tr>
<tr>
<td align="left" class="noBborderStyle"><b><bean:message
key="main.settings.password.new.text" />:</b></td>
<td align="left" class="noBborderStyle"><html:password
property="newpassword" size="30"
maxlength="<%=String.valueOf(org.tb.common.GlobalConstants.EMPLOYEE_PASSWORD_MAX_LENGTH) %>" />
<span style="color:red"><html:errors property="newpassword" /></span></td>
</tr>
<tr>
<td align="left" class="noBborderStyle"><b><bean:message
key="main.settings.password.confirm.text" />:</b></td>
<td align="left" class="noBborderStyle"><html:password
property="confirmpassword" size="30"
maxlength="<%=String.valueOf(org.tb.common.GlobalConstants.EMPLOYEE_PASSWORD_MAX_LENGTH) %>" />
<span style="color:red"><html:errors
property="confirmpassword" /></span></td>
</tr>

<c:if test="${passwordchanged}">
<tr>
<td class="noBborderStyle"><br>
</td>
</tr>

<tr>
<td align="left" class="noBborderStyle"><i><bean:message
key="main.settings.password.change.succesful.text" /></i></td>
</tr>
</c:if>

</table>
<br>
<table class="center">
<tr>
<td class="noBborderStyle"><html:submit
onclick="setStoreAction(this.form, 'changePassword');return false"
styleId="button">
<bean:message key="main.general.button.save.text" />
</html:submit></td>
</tr>
</table>
</html:form>

<c:if test="${generatedToken != null}">
<table class="center backgroundcolor">
Expand Down

0 comments on commit c4a0757

Please sign in to comment.