package action;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import service.ServiceAuthentication;
import exception.AppCertifyException;
import exception.AppFormatException;
/**
* 認証を行うActionクラス
* 顧客IDと顧客パスワードが一致するかどうかをDBに問い合わせて、
* 結果をコントローラーに返すクラス
*
*@author 2013/06/07 14:30 佐藤圭
*
*
*/
public class ActionLogin extends Action {
/**
* @param SENDURL 次の画面に遷移
* @param BACKURL 前の画面に遷移
*/
private static final String SENDURL = "/viewMenu.jsp";
private static final String BACKURL = "/viewLogin.jsp";
@Override
public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
FormatCheck fc = new FormatCheck();
try {
fc.formcheck((String) request.getAttribute("customerID"), (String) request.getAttribute("password"));
} catch (AppFormatException e) {
request.setAttribute("ErrorMessage", "顧客ID(パスワード)が入力されていません");
return BACKURL;
}
ServiceAuthentication sa = new ServiceAuthentication();
try {
if (sa.login((String) request.getAttribute("customerID"), (String) request.getAttribute("password"))) {
HttpSession session = request.getSession(true);
// if (session != null) {
// session = null;
// }
session.setAttribute("customerID", (String) request.getAttribute("customerID"));
session.setAttribute("password", (String) request.getAttribute("password"));
return SENDURL;
} else {
request.setAttribute("ErrorMessage", "入力された顧客IDまたはパスワードが誤っています");
return BACKURL;
}
} catch (AppCertifyException e) {
request.setAttribute("ErrorMessage", "入力された顧客IDまたはパスワードが誤っています");
return BACKURL;
}
}
}
最終更新:2013年06月07日 19:21