ResultSet res = dbM.userMatches(usr, psw, isDoc);
dbM.releaseConnection();
if (res.first()){
HttpSession session = request.getSession();
User loggedUser = (User) session.getAttribute("loggedUser");
if (loggedUser == null){
loggedUser = new User(res, isDoc);
session.setAttribute("loggedUser", loggedUser);
htmlPage += "<div class=\"jump\">";
htmlPage += "<p class=\"jump\">Benvenuto " + ((loggedUser.getIsDoctor()) ? "Dr. " + loggedUser.getSurname() : loggedUser.getName()) + "<br/>";
htmlPage += "Verrai a breve reindirizzato alla tua pagina personale</p>";
htmlPage += "<p class=\"jump\"><a href=\"" + Macro.BASE + "logged/Welcome\">Oppure clicca qui per continuare...</a></p>";
htmlPage += "</div>";
/*INIZIO SETTAGGIO COOKIE*/
String cookieName = loggedUser.getUsername();
Cookie cookie = null;
Cookie[] cookieArray = request.getCookies();
if (cookieArray!=null){
for(int i=0; i<cookieArray.length; i++) {
if (cookieArray[i].getName().equals(cookieName)) {
cookie = cookieArray[i];
break;
}
}
if(cookie==null){
Calendar cal = Calendar.getInstance();
String cookieValue = cal.getTime().toString();
int cookieExpire = 3600*24*7;//una settimana
loggedUser.setLastLogin(cookieValue);
cookie = new Cookie(cookieName, cookieValue);
cookie.setMaxAge(cookieExpire);
response.addCookie(cookie);
}
else{
String message = cookie.getValue();
loggedUser.setLastLogin(message);
Calendar cal = Calendar.getInstance();
String cookieValue = cal.getTime().toString();
cookie.setValue(cookieValue);
response.addCookie(cookie);