-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RA-1753:Password Force change not working #81
Open
HerbertYiga
wants to merge
6
commits into
openmrs:master
Choose a base branch
from
HerbertYiga:RA-1753
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
076a908
RA-1753:Password Force change not working
HerbertYiga fe8d3aa
RA-1753:Password Force change not working
HerbertYiga 15b12bd
RA-1753:Password Force change not working
HerbertYiga f6044d7
RA-1753:Password Force change not working
HerbertYiga fdf7226
RA-1753:Password Force change not working
HerbertYiga 6f055bd
RA-1753:Password Force change not working
HerbertYiga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
...java/org/openmrs/module/referenceapplication/page/controller/ResetPasswordController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package org.openmrs.module.referenceapplication.page.controller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import java.util.Map; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.openmrs.PersonName; | ||
import org.openmrs.User; | ||
import org.openmrs.api.AdministrationService; | ||
import org.openmrs.api.UserService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.messagesource.MessageSourceService; | ||
import org.openmrs.util.OpenmrsConstants; | ||
import org.openmrs.util.PrivilegeConstants; | ||
import org.openmrs.web.OptionsForm; | ||
import org.openmrs.web.WebUtil; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.validation.BindException; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.servlet.ModelAndView; | ||
import org.springframework.web.servlet.mvc.SimpleFormController; | ||
import org.springframework.web.servlet.view.RedirectView; | ||
|
||
public class ResetPasswordController extends SimpleFormController{ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/** | ||
* Called prior to form display. Allows for data to be put in the request to be used in the view | ||
* | ||
* @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest) | ||
*/ | ||
|
||
|
||
protected Map<String,Object> referenceData(HttpServletRequest request) throws Exception{ | ||
|
||
HttpSession httpSession=request.getSession(); | ||
Map<String,Object> map=new HashMap<String,Object>(); | ||
|
||
if(Context.isAuthenticated()) { | ||
|
||
Object resetPasswordAttribute=httpSession.getAttribute("resetPassword"); | ||
if(resetPasswordAttribute == null) { | ||
resetPasswordAttribute= ""; | ||
} | ||
else { | ||
httpSession.removeAttribute("resetPassword"); | ||
|
||
} | ||
|
||
map.put("resetPassword",resetPasswordAttribute); | ||
|
||
//generate the password hint depending on the security GP settings | ||
|
||
List <String>hints=new ArrayList<String>(5); | ||
int minChar=1; | ||
AdministrationService as = Context.getAdministrationService(); | ||
|
||
MessageSourceService mss=Context.getMessageSourceService(); | ||
|
||
try { | ||
String minCharStr = as.getGlobalProperty(OpenmrsConstants.GP_PASSWORD_MINIMUM_LENGTH); | ||
if (StringUtils.isNotBlank(minCharStr)) { | ||
minChar = Integer.valueOf(minCharStr); | ||
} | ||
if (minChar < 1) { | ||
minChar = 1; | ||
} | ||
} | ||
catch(NumberFormatException e) { | ||
|
||
} | ||
|
||
hints.add(mss.getMessage("options.login.password.minCharacterCount", new Object[] { minChar }, null)); | ||
addHint(hints, as.getGlobalProperty(OpenmrsConstants.GP_PASSWORD_CANNOT_MATCH_USERNAME_OR_SYSTEMID), | ||
mss.getMessage("options.login.password.cannotMatchUsername")); | ||
addHint(hints, as.getGlobalProperty(OpenmrsConstants.GP_PASSWORD_REQUIRES_UPPER_AND_LOWER_CASE), | ||
mss.getMessage("options.login.password.containUpperCase")); | ||
addHint(hints, as.getGlobalProperty(OpenmrsConstants.GP_PASSWORD_REQUIRES_DIGIT), | ||
mss.getMessage("options.login.password.containNumber")); | ||
addHint(hints, as.getGlobalProperty(OpenmrsConstants.GP_PASSWORD_REQUIRES_NON_DIGIT), | ||
mss.getMessage("options.login.password.containNonNumber")); | ||
|
||
StringBuilder passwordHint = new StringBuilder(""); | ||
for (int i = 0; i < hints.size(); i++) { | ||
if (i == 0) { | ||
passwordHint.append(hints.get(i)); | ||
} else if (i < (hints.size() - 1)) { | ||
passwordHint.append(", ").append(hints.get(i)); | ||
} else { | ||
passwordHint.append(" and ").append(hints.get(i)); | ||
} | ||
} | ||
|
||
map.put("passwordHint", passwordHint.toString()); | ||
|
||
|
||
} | ||
return map; | ||
|
||
} | ||
|
||
|
||
/** | ||
* This is called prior to displaying a form for the first time. It tells Spring the | ||
* form/command object to load into the request | ||
* | ||
* @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest) | ||
*/ | ||
|
||
protected Object formBackingObject(HttpServletRequest request) throws ServletException { | ||
|
||
OptionsForm opts=new OptionsForm(); | ||
if(Context.isAuthenticated()) { | ||
User user=Context.getAuthenticatedUser(); | ||
opts.setUsername(user.getUsername()); | ||
PersonName personName; | ||
if(user.getPersonName() !=null) { | ||
personName=PersonName.newInstance(user.getPersonName()); | ||
personName.setPersonNameId(null); | ||
} | ||
else { | ||
personName=new PersonName(); | ||
} | ||
|
||
opts.setPersonName(personName); | ||
} | ||
|
||
return opts; | ||
} | ||
/** | ||
* Utility method that check if a security property with boolean values is enabled and adds hint | ||
* message for it if it is not blank | ||
* | ||
* @param hints | ||
* @param gpValue the value of the global property | ||
* @param message the localized message to add | ||
*/ | ||
private void addHint(List<String> hints, String gpValue, String message) { | ||
if (Boolean.valueOf(gpValue) && !StringUtils.isBlank(message)) { | ||
hints.add(message); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<% | ||
ui.decorateWith("appui", "standardEmrPage", [ title: ui.message("referenceapplication.home.title") ]) | ||
ui.includeCss("referenceapplication", "home.css") | ||
|
||
def htmlSafeId = { extension -> | ||
"${ extension.id.replace(".", "-") }-${ extension.id.replace(".", "-") }-extension" | ||
} | ||
%> | ||
|
||
<div class="row"> | ||
<div class="col-12 col-sm-12 col-md-12 col-lg-12 homeNotification"> | ||
${ ui.includeFragment("coreapps", "administrativenotification/notifications") } | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-12 col-sm-12 col-md-12 col-lg-12"> | ||
|
||
|
||
<fieldset><legend><openmrs:message code="options.login.legend" /></legend> | ||
<table> | ||
<tr> | ||
<td><openmrs:message code="options.login.username" /></td> | ||
<td> | ||
<spring:bind path="opts.username"> | ||
<input type="text" name="${status.expression}" value="${status.value}" /> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
</td> | ||
</tr> | ||
<spring:nestedPath path="opts.personName"> | ||
<openmrs:portlet url="nameLayout" id="namePortlet" size="full" parameters="layoutMode=edit|layoutShowTable=false|layoutShowExtended=false" /> | ||
</spring:nestedPath> | ||
<tr><td colspan="2"><br/></td></tr> | ||
<tr> | ||
<td><openmrs:message code="options.login.password.old" /></td> | ||
<td> | ||
<spring:bind path="opts.oldPassword"> | ||
<input type="password" name="${status.expression}" value="${status.value}${resetPassword}" /> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><openmrs:message code="options.login.password.new" /></td> | ||
<td> | ||
<spring:bind path="opts.newPassword"> | ||
<input type="password" name="${status.expression}" | ||
value="${status.value}" /> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
<%-- Don't print empty brackets --%> | ||
<c:if test="${passwordHint != ''}"> | ||
(${passwordHint}) | ||
</c:if> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><openmrs:message code="options.login.password.confirm" /></td> | ||
<td> | ||
<spring:bind path="opts.confirmPassword"> | ||
<input type="password" name="${status.expression}" | ||
value="${status.value}" /> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
<openmrs:message code="User.confirm.description" /> | ||
</td> | ||
</tr> | ||
<tr><td colspan="2"><br/></td></tr> | ||
<tr><td colspan="2"><openmrs:message code="options.login.secretQuestion.about" /></td></tr> | ||
<tr> | ||
<td><openmrs:message code="options.login.password.old" /></td> | ||
<td> | ||
<spring:bind path="opts.secretQuestionPassword"> | ||
<input type="password" name="${status.expression}" value="${status.value}" /> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><openmrs:message code="options.login.secretQuestionNew" /></td> | ||
<td> | ||
<spring:bind path="opts.secretQuestionNew"> | ||
<input type="text" name="${status.expression}" | ||
value="${status.value}" size="35"/> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><openmrs:message code="options.login.secretAnswerNew" /></td> | ||
<td> | ||
<spring:bind path="opts.secretAnswerNew"> | ||
<input type="password" name="${status.expression}" | ||
value="${status.value}" size="35" /> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><openmrs:message code="options.login.secretAnswerConfirm" /></td> | ||
<td> | ||
<spring:bind path="opts.secretAnswerConfirm"> | ||
<input type="password" name="${status.expression}" | ||
value="${status.value}" size="35" /> | ||
<c:if test="${status.errorMessage != ''}"> | ||
<span class="error">${status.errorMessage}</span> | ||
</c:if> | ||
</spring:bind> | ||
</td> | ||
</tr> | ||
</table> | ||
|
||
</div> | ||
</div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @ibacher ,while working on this,i am wondering whether its ok to put jsp code in a gsp page cc @dkayiwa @mks-d