Commit 4030b47e authored by smestry's avatar smestry

Added new EJB and Servlet for reset password.


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@103231 ce508802-f39f-4f6c-b175-0d175dae99d5
parent e0b40ae1
/**
* Purpose: to reset password for all the users, Reuest ID: S16EBAS030
* Author: Sneha Mestry
* Date: 31-08-2016
*/
package ibase.webitm.ejb.wms;
import ibase.system.config.ConnDriver;
import ibase.utility.EMail;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.ejb.Stateless;
@Stateless
public class ResetPasswordEJB extends ValidatorEJB implements ResetPasswordEJBLocal, ResetPasswordEJBRemote
{
public ResetPasswordEJB()
{
}
GenericUtility genericUtility = GenericUtility.getInstance();
public boolean validateUser(String userCode, String password, String passwordStr, String firstLogin)
{
System.out.println(" **** Inside validateUser ****** ");
String sql = "";
ResultSet rs = null;
PreparedStatement pstmt = null, pstmt1 = null;
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
boolean isValidate = false;
int count = 0;
boolean isError = false;
ArrayList<String> mailInfo = new ArrayList<String>();
try
{
conn = getConnection();
conn.setAutoCommit(false);
sql = "SELECT CODE, EMAIL_ID FROM USERS WHERE CODE = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userCode);
rs = pstmt.executeQuery();
isValidate = rs.next();
if (isValidate)
{
mailInfo.add(rs.getString("EMAIL_ID"));
mailInfo.add("Your New Password For User Id: " + userCode);
mailInfo.add("Your password was reset successfully. Your new password is: " + passwordStr);
sql = "UPDATE USERS SET PASS_WD_SHA = ?, LOGIN_FIRST = ?, ACCT_LOCK = ? WHERE CODE = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, password);
pstmt1.setString(2, firstLogin);
pstmt1.setString(3, "N");
pstmt1.setString(4, userCode);
count = pstmt1.executeUpdate();
//System.out.println("count ========>> "+count);
if (count != 0)
{
sendMail(mailInfo);
isValidate = true;
}
if (pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
}
else if(!isValidate)
{
System.out.println(" ***** User not found. Enter Valid User Code *****");
isValidate = false;
}
if(rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch (Exception e)
{
isError = true;
e.printStackTrace();
}
finally
{
try
{
if(isError)
{
conn.rollback();
}
else
{
conn.commit();
}
if(rs != null)
{
rs.close();
rs = null;
}
if (pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(conn != null)
{
conn.close();
conn = null;
}
}
catch (Exception d)
{
d.printStackTrace();
System.out.println("Log In failed: An Exception has occurred! In :validateUser() : " + d.getMessage());
}
}
return isValidate;
}
public void sendMail(ArrayList<String> mailInfo)
{
EMail email = new EMail();
StringBuffer commInfo = new StringBuffer();
try
{
/*System.out.println("mailInfo.get(0)=======>>"+mailInfo.get(0));
System.out.println("mailInfo.get(1)=======>>"+mailInfo.get(1));
System.out.println("mailInfo.get(2)=======>>"+mailInfo.get(2));*/
commInfo.append("<ROOT>");
commInfo.append("<MAILINFO>");
commInfo.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
commInfo.append("<TO_ADD>").append("<![CDATA[" + mailInfo.get(0) + "]]>").append("</TO_ADD>");
commInfo.append("<SUBJECT>").append("<![CDATA[" + mailInfo.get(1) + "]]>").append("</SUBJECT>");
commInfo.append("<BODY_TEXT>").append("<![CDATA[" +mailInfo.get(2) + "]]>").append("</BODY_TEXT>");
commInfo.append("</MAILINFO>");
commInfo.append("</ROOT>");
System.out.println(" calling sendMail method() form for Reset Password. ");
email.sendMail(commInfo.toString(), "ITM", null);
System.out.println(" ******** Email send succesfully for Reset Password. ***********");
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Exception : sendMail " + e.getMessage());
}
finally
{
System.out.println("in Finally block for sendMail ");
}
email = null;
}
}
/**
* Purpose: to reset password for all the users, Reuest ID: S16EBAS030
* Author: Sneha Mestry
* Date: 31-08-2016
*/
package ibase.webitm.ejb.wms;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface ResetPasswordEJBLocal extends ValidatorLocal
{
public boolean validateUser(String userCode, String newPwdSHA256, String passwordStr, String firstLogin);
}
/**
* Purpose: to reset password for all the users, Reuest ID: S16EBAS030
* Author: Sneha Mestry
* Date: 31-08-2016
*/
package ibase.webitm.ejb.wms;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface ResetPasswordEJBRemote extends ValidatorRemote
{
public boolean validateUser(String userCode, String newPwdSHA256, String passwordStr, String firstLogin);
}
/**
* Purpose: to reset password for all the users, Reuest ID: S16EBAS030
* Author: Sneha Mestry
* Date: 31-08-2016
*/
package ibase.webitm.servlet.wms;
import ibase.system.config.AppConnectParm;
import ibase.utility.CommonConstants;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.wms.ResetPasswordEJBLocal;
import ibase.webitm.utility.ITMException;
import java.io.IOException;
import javax.naming.InitialContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class ResetPasswordServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private String user_lang ="en";
private String user_country = "US";
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
System.out.println("******* in ResetPasswordServlet Servlet ******");
InitialContext context = null;
AppConnectParm appConnectParm = new AppConnectParm();
ResetPasswordEJBLocal resetPasswordEJBLocal = null;
String actionName = "", newPwdSHA256 = "", userCode = "", message = "", password = "", firstLogin = "";
//HttpSession session = request.getSession();
HttpSession session = request.getSession(true);
try
{
response.setContentType("text/html");
actionName = request.getParameter("actionName");
newPwdSHA256 = request.getParameter("newPwdSHA256");
userCode = request.getParameter("userCode");
password = request.getParameter("password");
firstLogin = (request.getParameter("firstLogin") != null && request.getParameter("firstLogin").equals("Y")) ? "1" : "0";
/*System.out.println("request.getParameter=====>>"+request.getParameter("firstLogin"));
System.out.println("actionName=========>>" + actionName);
System.out.println("newPwdSHA256=========>>" + newPwdSHA256);
System.out.println("userCode=========>>" + userCode);
System.out.println("password=========>>" + password);
System.out.println("firstLogin=========>>" + firstLogin);*/
context = new InitialContext(appConnectParm.getProperty());
resetPasswordEJBLocal = (ResetPasswordEJBLocal) context.lookup("ibase/ResetPasswordEJB/local");
if(actionName.equalsIgnoreCase("RESET_PASSWORD"))
{
boolean retStr = resetPasswordEJBLocal.validateUser(userCode, newPwdSHA256, password, firstLogin);
System.out.println("retStr from EJB ===>>"+retStr);
if (retStr)
{
response.sendRedirect("/ibase/webitm/jsp/ResetPasswordSuccess.jsp");
}
else
{
message = "User not found. Enter Valid User Code and try again. ";
response.sendRedirect("/ibase/webitm/jsp/ResetPassword.jsp?message="+message);
}
}
}
catch (Exception e)
{
System.out.println("Exception : ResetPasswordServlet :doPost(HttpServletRequest request, HttpServletResponse response) :" + e.getMessage());
try
{
throw new ITMException(e);
}
catch (ITMException e1)
{
e1.printStackTrace();
}
}
finally
{
System.out.println("in Finally block for ResetPasswordServlet ");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment