Search in sources :

Example 1 with GenericDelegator

use of org.apache.ofbiz.entity.GenericDelegator in project ofbiz-framework by apache.

the class LoginEvents method forgotPassword.

/**
 * The user forgot his/her password.  This will call showPasswordHint, emailPassword or simply returns "success" in case
 * no operation has been specified.
 *
 * @param request The HTTPRequest object for the current request
 * @param response The HTTPResponse object for the current request
 * @return String specifying the exit status of this event
 */
public static String forgotPassword(HttpServletRequest request, HttpServletResponse response) {
    GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator");
    String questionEnumId = request.getParameter("securityQuestion");
    String securityAnswer = request.getParameter("securityAnswer");
    String userLoginId = request.getParameter("USERNAME");
    String errMsg = null;
    try {
        GenericValue userLoginSecurityQuestion = EntityQuery.use(delegator).from("UserLoginSecurityQuestion").where("questionEnumId", questionEnumId, "userLoginId", userLoginId).cache().queryOne();
        if (userLoginSecurityQuestion != null) {
            if (UtilValidate.isEmpty(securityAnswer)) {
                errMsg = UtilProperties.getMessage(resource, "loginservices.security_answer_empty", UtilHttp.getLocale(request));
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                return "error";
            }
            String ulSecurityAnswer = userLoginSecurityQuestion.getString("securityAnswer");
            if (UtilValidate.isNotEmpty(ulSecurityAnswer) && !securityAnswer.equalsIgnoreCase(ulSecurityAnswer)) {
                errMsg = UtilProperties.getMessage(resource, "loginservices.security_answer_not_match", UtilHttp.getLocale(request));
                request.setAttribute("_ERROR_MESSAGE_", errMsg);
                return "error";
            }
        }
    } catch (GenericEntityException e) {
        errMsg = UtilProperties.getMessage(resource, "loginevents.problem_getting_security_question_record", UtilHttp.getLocale(request));
        Debug.logError(e, errMsg, module);
    }
    if ((UtilValidate.isNotEmpty(request.getParameter("GET_PASSWORD_HINT"))) || (UtilValidate.isNotEmpty(request.getParameter("GET_PASSWORD_HINT.x")))) {
        return showPasswordHint(request, response);
    } else if ((UtilValidate.isNotEmpty(request.getParameter("EMAIL_PASSWORD"))) || (UtilValidate.isNotEmpty(request.getParameter("EMAIL_PASSWORD.x")))) {
        return emailPassword(request, response);
    } else {
        return "success";
    }
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GenericDelegator(org.apache.ofbiz.entity.GenericDelegator)

Aggregations

GenericDelegator (org.apache.ofbiz.entity.GenericDelegator)1 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)1 GenericValue (org.apache.ofbiz.entity.GenericValue)1