Best Cerberus-source code snippet using org.cerberus.servlet.crud.usermanagement.ForgotPassword.processRequest
Source:ForgotPassword.java
...56 * @param response servlet response57 * @throws ServletException if a servlet-specific error occurs58 * @throws IOException if an I/O error occurs59 */60 protected void processRequest(HttpServletRequest request, HttpServletResponse response)61 throws ServletException, IOException {62 response.setContentType("text/html;charset=UTF-8");63 try (PrintWriter out = response.getWriter()) {64 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());65 IUserService userService = appContext.getBean(UserService.class);66 INotificationService notificationService = appContext.getBean(INotificationService.class);67 IParameterService parameterService = appContext.getBean(ParameterService.class);68 String system = "";69 JSONObject jsonResponse = new JSONObject();70 String login = ParameterParserUtil.parseStringParam(request.getParameter("login"), "");71 /**72 * Check if notification parameter is set to Y. If not, return an73 * error74 */75 String sendNotification = parameterService.findParameterByKey("cerberus_notification_accountcreation_activatenotification", system).getValue();76 if (!sendNotification.equalsIgnoreCase("Y")) {77 jsonResponse.put("messageType", "Error");78 jsonResponse.put("message", "This functionality is not activated. Please contact your Cerberus Administrator.");79 response.getWriter().print(jsonResponse);80 response.getWriter().flush();81 return;82 }83 /**84 * If email not found in database, send error message85 */86 AnswerItem ai = userService.readByKey(login);87 User user = (User) ai.getItem();88 if (user == null) {89 jsonResponse.put("messageType", "Error");90 jsonResponse.put("message", "Login submitted is unknown !");91 response.getWriter().print(jsonResponse);92 response.getWriter().flush();93 return;94 }95 /**96 * Update user setting a new value in requestresetpassword97 */98 userService.requestResetPassword(user);99 /**100 * Send an email with the hash as a parameter101 */102 Answer mailSent = new Answer(notificationService.generateAndSendForgotPasswordEmail(user));103 if (!mailSent.isCodeStringEquals("OK")) {104 jsonResponse.put("messageType", "Error");105 jsonResponse.put("message", "An error occured sending the notification. Detail : " + mailSent.getMessageDescription());106 response.getWriter().print(jsonResponse);107 response.getWriter().flush();108 return;109 }110 /**111 * Adding Log entry.112 */113 ILogEventService logEventService = appContext.getBean(ILogEventService.class);114 logEventService.createForPrivateCalls("/ForgotPassword", "CREATE", "User : " + login + " asked for password recovery", request);115 /**116 * Build Response Message117 */118 jsonResponse.put("messageType", "OK");119 jsonResponse.put("message", "An e-mail has been sent to the mailbox " + user.getEmail() + ".");120 response.getWriter().print(jsonResponse);121 response.getWriter().flush();122 } catch (CerberusException myexception) {123 response.getWriter().print(myexception.getMessageError().getDescription());124 } catch (JSONException ex) {125 LOG.warn(ex);126 response.setContentType("application/json");127 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());128 }129 }130 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">131 /**132 * Handles the HTTP <code>GET</code> method.133 *134 * @param request servlet request135 * @param response servlet response136 * @throws ServletException if a servlet-specific error occurs137 * @throws IOException if an I/O error occurs138 */139 @Override140 protected void doGet(HttpServletRequest request, HttpServletResponse response)141 throws ServletException, IOException {142 processRequest(request, response);143 }144 /**145 * Handles the HTTP <code>POST</code> method.146 *147 * @param request servlet request148 * @param response servlet response149 * @throws ServletException if a servlet-specific error occurs150 * @throws IOException if an I/O error occurs151 */152 @Override153 protected void doPost(HttpServletRequest request, HttpServletResponse response)154 throws ServletException, IOException {155 processRequest(request, response);156 }157 /**158 * Returns a short description of the servlet.159 *160 * @return a String containing servlet description161 */162 @Override163 public String getServletInfo() {164 return "Short description";165 }// </editor-fold>166}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!