-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kgitbank
authored and
kgitbank
committed
Sep 11, 2018
1 parent
daa9791
commit f8ca14a
Showing
9 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<%@page import="java.sql.Date"%> | ||
<%@page import="java.util.*"%> | ||
<%@page import="beans.AccountDao"%> | ||
<%@ page language="java" contentType="text/html; charset=UTF-8" | ||
pageEncoding="UTF-8"%> | ||
<%@ page errorPage="/error/default.jsp" %> | ||
<% | ||
//1.로그인했던 아이디 ,pw 파라미터값 받아오기 | ||
String login_id = request.getParameter("loginId"); | ||
String login_pw = request.getParameter("loginPw"); | ||
System.out.println("login_id:"+login_id+"/ login_pw :"+login_pw); | ||
//2.객체생성 | ||
AccountDao dao = new AccountDao(); | ||
//3.account 테이블에있는 전체데이터 datas에 담음 | ||
List<Map<String,Object>> datas = dao.getAllDatas(); //null이면 정보없음,로그인비번다름 | ||
//4.db에 account테이블의 id,pw 정보와 내가입력한 id,pw정보 비교후 로그인 | ||
Map info = dao.getLoginData(login_id); //로그인한아이디정보 뽑아서 acc에저장 | ||
if(info==null || !info.get("pass").equals(login_pw)){//★아이디로 맵조회했으니 비밀번호만비교하면됨 | ||
response.sendRedirect(application.getContextPath()+"/login.jsp?mode=fail");//실패시 login.jsp에 넘어감 | ||
}else{//패스워드가같으면(로그인성공) | ||
Set<String> set = (Set)application.getAttribute("users");// 확인(다른브라우저에서도확인할수있으니) | ||
if(set.contains(login_id)){//아이디가 application에 등록되있으면 | ||
throw new RuntimeException(login_id+" 는 이미 로그인되어있습니다."); | ||
}else{ //처음로그인일경우 | ||
set.add(login_id); // set에 login_id추가 | ||
application.setAttribute("users", set);//application에 로그인id담음 | ||
session.setAttribute("login_condition", true); //로그인확인 true | ||
session.setAttribute("login_id", login_id); //접속한 id 세션에저장 | ||
Date date = new Date(System.currentTimeMillis());//현재시간update | ||
dao.addLoginData(login_id, date);//로그에 담음 | ||
//response.sendRedirect(application.getContextPath()+"/");//로그인되면 home으로 이동 | ||
if(session.getAttribute("dest")==null) { | ||
response.sendRedirect(application.getContextPath()+"/");//로그인되면 home으로 이동 | ||
}else { | ||
String dest = (String)session.getAttribute("dest"); | ||
response.sendRedirect(dest); | ||
} | ||
} | ||
} | ||
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package handlers; | ||
|
||
|
||
import java.sql.Date; | ||
import java.util.Map; | ||
|
||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletRequestEvent; | ||
import javax.servlet.ServletRequestListener; | ||
|
||
import javax.servlet.http.Cookie; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import beans.AccountDao; | ||
|
||
public class RequestHandler implements ServletRequestListener { | ||
@Override | ||
public void requestInitialized(ServletRequestEvent sre) { | ||
ServletRequest req = sre.getServletRequest(); | ||
HttpServletRequest request = (HttpServletRequest) req; | ||
//if(request.getSession().isNew()) { // 최초요청인지 | ||
|
||
//} | ||
//----------쿠키로그인유지-------------------- | ||
Cookie[] ar = request.getCookies(); | ||
String value = null; | ||
if (ar != null) { | ||
for (int i = 0; i < ar.length; i++) { | ||
//System.out.println(ar[i].getName()+"/"+ar[i].getValue()); | ||
if (ar[i].getName().equals("freepass")) { | ||
value = ar[i].getValue(); //쿠키벨류값뽑기 | ||
} | ||
} | ||
|
||
} | ||
if (value != null) { | ||
System.out.println("[CookieHandler] this client has a freepass cookie. value is"+ value); | ||
|
||
//----------쿠키로그인유지-------------------- | ||
request.getSession().setAttribute("login_condition", true); // 필터에서true안해주면튕기니깐 | ||
HttpSession session = request.getSession(); | ||
session.setAttribute("login_condition", true); //로그인확인 true | ||
session.setAttribute("login_id", value); //접속한 id 세션에저장 | ||
|
||
AccountDao dao = new AccountDao(); | ||
Map info = dao.getLoginData(value); | ||
Date date = new Date(System.currentTimeMillis());//현재시간update | ||
//if (log != null) { | ||
// session.setAttribute("latest", log.get("time")); | ||
//} | ||
dao.addLoginData(value,date); //시간 | ||
//----------쿠키로그인유지-------------------- | ||
|
||
}else { | ||
System.out.println("[CookieHandler] this client does not hava a freepass cookie"); | ||
} | ||
} | ||
|
||
} |