How to use processRequest method of org.cerberus.servlet.crud.usermanagement.ForgotPasswordEmailConfirmation class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.usermanagement.ForgotPasswordEmailConfirmation.processRequest

Source:ForgotPasswordEmailConfirmation.java Github

copy

Full Screen

...54 * @param response servlet response55 * @throws ServletException if a servlet-specific error occurs56 * @throws IOException if an I/O error occurs57 */58 protected void processRequest(HttpServletRequest request, HttpServletResponse response)59 throws ServletException, IOException {60 response.setContentType("text/html;charset=UTF-8");61 try (PrintWriter out = response.getWriter()) {62 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());63 IUserService userService = appContext.getBean(UserService.class);64 IParameterService parameterService = appContext.getBean(ParameterService.class);65 String system = "";66 JSONObject jsonResponse = new JSONObject();67 68 StringBuilder jb = new StringBuilder();69 String line = null;70 BufferedReader reader = request.getReader();71 while ((line = reader.readLine()) != null) {72 jb.append(line);73 }74 String[] parameters = jb.toString().split("&");75 JSONObject jo = new JSONObject();76 for (String parameter : parameters){77 String[] param = parameter.split("=");78 jo.put(param[0], param[1]);79 }80 81 String login = jo.getString("login");82 String confirmation = jo.getString("confirmationToken");83 84 /**85 * If email not found in database, send error message86 */87 AnswerItem ai = userService.readByKey(login);88 User user = (User) ai.getItem();89 if (user == null) {90 jsonResponse.put("messageType", "KO");91 jsonResponse.put("message", "Login submitted is unknown !");92 response.getWriter().print(jsonResponse);93 response.getWriter().flush();94 return;95 }96 /**97 * Check the token98 */99 if (!userService.verifyResetPasswordToken(user, confirmation)) {100 jsonResponse.put("messageType", "KO");101 jsonResponse.put("message", "Token submitted is invalid !");102 response.getWriter().print(jsonResponse);103 response.getWriter().flush();104 return;105 }106 /**107 * Build Response Message108 */109 jsonResponse.put("messageType", "OK");110 jsonResponse.put("message", "Please, define your new password.");111 response.getWriter().print(jsonResponse);112 response.getWriter().flush();113 } catch (JSONException ex) {114 LOG.warn(ex);115 }116 }117 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">118 /**119 * Handles the HTTP <code>GET</code> method.120 *121 * @param request servlet request122 * @param response servlet response123 * @throws ServletException if a servlet-specific error occurs124 * @throws IOException if an I/O error occurs125 */126 @Override127 protected void doGet(HttpServletRequest request, HttpServletResponse response)128 throws ServletException, IOException {129 processRequest(request, response);130 }131 /**132 * Handles the HTTP <code>POST</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 doPost(HttpServletRequest request, HttpServletResponse response)141 throws ServletException, IOException {142 processRequest(request, response);143 }144 /**145 * Returns a short description of the servlet.146 *147 * @return a String containing servlet description148 */149 @Override150 public String getServletInfo() {151 return "Short description";152 }// </editor-fold>153}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.usermanagement;2import java.io.IOException;3import java.io.PrintWriter;4import java.sql.Connection;5import java.sql.PreparedStatement;6import java.sql.ResultSet;7import java.sql.SQLException;8import java.sql.Timestamp;9import java.time.LocalDateTime;10import java.util.Properties;11import java.util.Random;12import javax.mail.Authenticator;13import javax.mail.Message;14import javax.mail.MessagingException;15import javax.mail.PasswordAuthentication;16import javax.mail.Session;17import javax.mail.Transport;18import javax.mail.internet.InternetAddress;19import javax.mail.internet.MimeMessage;20import javax.servlet.ServletException;21import javax.servlet.http.HttpServlet;22import javax.servlet.http.HttpServletRequest;23import javax.servlet.http.HttpServletResponse;24import org.apache.logging.log4j.LogManager;25import org.apache.logging.log4j.Logger;26import org.cerberus.crud.entity.User;27import org.cerberus.database.DatabaseSpring;28import org.cerberus.exception.CerberusException;29import org.cerberus.log.MyLogger;30import org.cerberus.service.email.IEmailGeneration;31import org.cerberus.util.ParameterParserUtil;32import org.cerberus.util.answer.AnswerItem;33import org.springframework.beans.factory.annotation.Autowired;34import org.springframework.context.ApplicationContext;35import org.springframework.web.context.support.WebApplicationContextUtils;36public class ForgotPasswordEmailConfirmation extends HttpServlet {37 private static final Logger LOG = LogManager.getLogger(ForgotPasswordEmailConfirmation.class);38 private IEmailGeneration emailGeneration;39 public void init() throws ServletException {40 super.init();41 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());42 emailGeneration = appContext.getBean(IEmailGeneration.class);43 }44 protected void doGet(HttpServletRequest request, HttpServletResponse response)45 throws ServletException, IOException {46 String email = ParameterParserUtil.parseStringParam(request.getParameter("email"), "");47 LOG.debug("Email: " + email);48 String token = ParameterParserUtil.parseStringParam(request.getParameter("token"), "");49 LOG.debug("Token: " + token);50 PrintWriter out = response.getWriter();51 response.setContentType("text/html");52 out.println("<html>");53 out.println("<head>");54 out.println("<title>Cerberus - Forgot Password</title>");55 out.println("</head>");56 out.println("<body>");57 out.println("<h1>Cerberus - Forgot Password</h1>");

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ForgotPasswordEmailConfirmation

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful