@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String url=req.getServletPath();
		HttpSession session=req.getSession();
		pm=PMF.get().getPersistenceManager();
		if(url.endsWith("/login"))
		{
		
		Person p;
		UserService userService = UserServiceFactory.getUserService();
		// Test if the user is logged or not 
		if (userService.getCurrentUser() != null) {
			try{
        	Query q = pm.newQuery(Person.class,"email == '"+userService.getCurrentUser()+"'");
            List<Person> list=(List<Person>) q.execute();
            if(list.isEmpty()){
            	p=new Person();
            	p.setName(userService.getCurrentUser().getNickname());
	        	p.setEmail(userService.getCurrentUser().getEmail());
	        	session.setAttribute("user", pm.makePersistent(p));        	
              }
            else
            {
            	session.setAttribute("user", list.get(0));
            }
        	
        	
			}
			catch (Exception ex)
			{
				ex.printStackTrace();
			}
			
			finally{
				pm.close();
				resp.sendRedirect("/books");
			}
       
        	
        } else {
        	// redirect to login page
        	resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
                                                
        }
		}
		if(url.endsWith("/signout"))
		{
			session.invalidate();
			resp.sendRedirect("index.jsp");
		}
		
	}