public String doLogoutAndRemoveCookie() {
   removeCookie();
   user.setUuid(null);
   em.merge(user);
   AlterableContext ctx = (AlterableContext) beanManager.getContext(SessionScoped.class);
   Bean<?> myBean = beanManager.getBeans(AccountBean.class).iterator().next();
   ctx.destroy(myBean);
   myBean = beanManager.getBeans(ShoppingCartBean.class).iterator().next();
   ctx.destroy(myBean);
   return "/main";
 }
 public String doSignin() {
   TypedQuery<User> query = em.createNamedQuery(User.FIND_BY_LOGIN_PASSWORD, User.class);
   query.setParameter("login", user.getLogin());
   query.setParameter("password", PasswordUtils.digestPassword(user.getPassword()));
   try {
     user = query.getSingleResult();
     // If the user is an administrator
     if (user.getRole().equals(UserRole.ADMIN)) admin = true;
     // If the user has clicked on remember me
     if (rememberMe) {
       String uuid = UUID.randomUUID().toString();
       user.setUuid(uuid);
       addCookie(uuid);
     } else {
       user.setUuid(null);
       removeCookie();
     }
     // The user is now logged in
     loggedIn = true;
     facesContext.addMessage(
         null,
         new FacesMessage(
             FacesMessage.SEVERITY_INFO,
             "Welcome back " + user.getFirstName(),
             "You can now browse the catalog"));
     return "/main";
   } catch (NoResultException e) {
     facesContext.addMessage(
         null,
         new FacesMessage(
             FacesMessage.SEVERITY_WARN,
             "Wrong user/password",
             "Check your inputs or ask for a new password"));
     return null;
   }
 }