Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 27 additions & 54 deletions PROJO/src/java/aqpg/LoginDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,31 @@

public class LoginDao {

public static int validate(LoginBean bean) throws SQLException{
ResultSet rs = null;
boolean records=false;
int status=0;
try{
Connection con=ConnectionProvider.getCon();

PreparedStatement ps=con.prepareStatement("Select * from user_2 where login_name=? and pass=? and type=?");

ps.setString(1, bean.getLoginName());
ps.setString(2, bean.getPass());
ps.setString(3, bean.getType());

rs=ps.executeQuery();
}
catch(Exception e){}
if(rs!=null && rs.next()!=false)
status=1;
/*finally {
if (rs != null) {
try {

String loginName;
String pass;
String type;
records=rs.next();

do{
loginName=rs.getString(1);
if(loginName==bean.getLoginName()){
pass=rs.getString(2);
type=rs.getString(3);
System.out.println(loginName+" "+pass+" "+ type +" ");
if(pass==bean.getPass() && type==bean.getType())
{
status=1;

}
break;
}
}while(rs.next());
}
catch (SQLException ex) {
Logger.getLogger(LoginDao.class.getName()).log(Level.SEVERE, null, ex);
}
rs.close();
}

rs = null;
}*/


return status;
/**
* Returns whether a user exist in our system or not
* @param bean
* @return int : a status code indicating presence of the user
*/
public static boolean validate(LoginBean bean) throws SQLException {
private ResultSet rs = null;
private boolean records = false;
private boolean isValidUser = false;
private static final Logger LOGGER = Logger.getLogger(LoginDao.class.getName());

try {
Connection con=ConnectionProvider.getCon();
PreparedStatement ps=con.prepareStatement("Select * from user_2 where login_name=? and pass=? and type=?");
ps.setString(1, bean.getLoginName());
ps.setString(2, bean.getPass());
ps.setString(3, bean.getType());
rs=ps.executeQuery();
} catch(Exception e){
LOGGER.log(Level.SEVERE, "Exception occured", ex);
}

if (rs != null && rs.next() != false) {
isValidUser = true;
}
return isValidUser;
}
}
}
11 changes: 11 additions & 0 deletions PROJO/web/errorLogin.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ERROR PAGE</title>
</head>
<body>
No such user exist !!
</body>
</html>
64 changes: 24 additions & 40 deletions PROJO/web/loginprocess.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,43 @@

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="aqpg.LoginDao"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>lOGIN PROCESSING PAGE</title>
<title>LOGIN PROCESSING PAGE</title>
</head>
<body>
<jsp:useBean id="obj" class="aqpg.LoginBean"/>
<jsp:setProperty property="*" name="obj"/>



<jsp:useBean id="userObject" class="aqpg.LoginBean"/>
<jsp:setProperty property="*" name="userObject"/>
<%
out.println(obj.getLoginName()+" "+ obj.getPass()+ " "+obj.getType() );
int status=LoginDao.validate(obj);
out.println(status);
if(status==1){
out.println("You r successfully logged in");
session.setAttribute("session","TRUE");
String name= request.getParameter("loginName");
session.setAttribute("LoginID", name);
boolean isValidUser = LoginDao.validate(userObject);
if (isValidUser) {
session.setAttribute("SESSION","true");
String loginName = request.getParameter("loginName");
session.setAttribute("USER", loginName);
String userType = request.getParameter("type");

String s=request.getParameter("type");

if(s.equals("A"))
{
// out.println("here");
if(userType.equals("A")) { // user is of Admin Type
%>
<jsp:include page="AdminMainPage.jsp"></jsp:include>
<jsp:include page="AdminMainPage.jsp"></jsp:include>
<%
}
else if(s.equals("I"))
{
}
else if(userType.equals("I")) { // user is of Instructor Type
%>
<jsp:include page="InstructorMainPage.jsp"></jsp:include>
<jsp:include page="InstructorMainPage.jsp"></jsp:include>
<%
}
else {
%>
<jsp:include page="LearnerMainPage.jsp"></jsp:include>
<%
}
}
else
{
%>
<jsp:include page="LearnerMainPage.jsp"></jsp:include>
<%
// out.println("here2");
}
}
else
{
%>
<jsp:include page="index.jsp"></jsp:include>
<%
out.print("Sorry, login or password error");
else {
%>
<jsp:include page="errorLogin.jsp"></jsp:include>
<%
}
%>
</body>
Expand Down