daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Feb 23rd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.isi.tpjava2jpjm.model.actions;
  2.  
  3. import java.io.UnsupportedEncodingException;
  4. import java.net.URLEncoder;
  5. import java.util.ArrayList;
  6.  
  7. import javax.servlet.http.Cookie;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.servlet.http.HttpSession;
  11.  
  12. import com.isi.tpjava2jpjm.model.entities.Client;
  13. import com.isi.tpjava2jpjm.model.managers.ClientManager;
  14. import com.isi.tpjava2jpjm.model.services.ConnecteurBD;
  15.  
  16. public class ClientLoginAction extends Action {
  17.  
  18.     ClientManager cliMan;
  19.     HttpSession session;
  20.    
  21.     public ClientLoginAction(ConnecteurBD cbd, String destinationOk,
  22.             String destinationBad) {
  23.         super(cbd, destinationOk, destinationBad);
  24.         cliMan = new ClientManager(cbd);
  25.     }
  26.  
  27.     @Override
  28.     public boolean doTheJob(HttpServletRequest request,
  29.             HttpServletResponse response) {
  30.         destination = destinationOk;
  31.         boolean ok = true;
  32.         //aller chercher un arrayListe de Categorie
  33.         String s = request.getParameter("email");
  34.         Client c = cliMan.getClientByEmailPW(request.getParameter("email"), request.getParameter("pw"));
  35.         //monter le al dans les attribut du request
  36.    
  37.         if(c==null){
  38.             ok=false;
  39.             destination=destinationBad;
  40.         }
  41.        
  42.        
  43.         if (request.getParameter("cookie") != null){
  44.             Cookie biscuit = null;
  45.             try {
  46.                 biscuit = new Cookie("email", URLEncoder.encode(c.getCourrielClient(), "UTF-8"));
  47.             } catch (UnsupportedEncodingException e) {
  48.                 // TODO Auto-generated catch block
  49.                 e.printStackTrace();
  50.             }
  51.             biscuit.setMaxAge(60*60);
  52.             response.addCookie(biscuit);
  53.         }
  54.        
  55.         System.out.println(c);
  56.         session = request.getSession(true);
  57.         session.setAttribute("client", c);
  58.     ;
  59.         return ok;
  60.     }
  61.  
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top