// Path: LoginHandler.java
// public class LoginHandler implements Handler {
//     @Override
//     public void handleIt(HashMap<String, Object> dataMap) {
//         String userName = (String)dataMap.get("uname");
//         String password = (String)dataMap.get("pword");
//         StoreModel theModel = (StoreModel)dataMap.get("model");
//         User foundUser = theModel.getUser(userName, password);
//         HashMap<String,Object>responseMap = new HashMap<>();
//         String sessionID = "";
//         if(foundUser != null){
//             UUID sessionUUID = UUID.randomUUID();
//             sessionID = sessionUUID.toString();
//             foundUser.setSession(sessionID);
//             theModel.updateUser(foundUser);
//             responseMap.put("id",sessionID);
//         }
//         responseMap.put("id",sessionID);
//         JSONOutputStream outToClient = (JSONOutputStream)dataMap.get("toClient");
//         try {
//             outToClient.writeObject(responseMap);
//         }
//         catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: LogoutHandler.java
// public class LogoutHandler implements Handler {
//     @Override
//     public void handleIt(HashMap<String, Object> dataMap) {
// 
//         String sessionID = (String)dataMap.get("id");
//         StoreModel theModel = (StoreModel)dataMap.get("model");
//         User foundUser = theModel.getUserBySessionID(sessionID);
//         if(foundUser != null){
//             foundUser.setSession("");
//             theModel.updateUser(foundUser);
//         }
//         HashMap<String,Object> responseMap = new HashMap<>();
//         responseMap.put("id","");
//         JSONOutputStream outToClient = (JSONOutputStream)dataMap.get("toClient");
//         try {
//             outToClient.writeObject(responseMap);
//         }
//         catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: RegistrationHandler.java
// public class RegistrationHandler implements Handler {
//     @Override
//     public void handleIt(HashMap<String, Object> dataMap) {
//         String userName = (String)dataMap.get("uname");
//         String password = (String)dataMap.get("pword");
//         StoreModel theModel = (StoreModel)dataMap.get("model");
//         User foundUser = theModel.getUser(userName, password);
//         HashMap<String,Object>responseMap = new HashMap<>();
//         String sessionID = "";
//         if(foundUser == null){
//             UUID sessionUUID = UUID.randomUUID();
//             sessionID = sessionUUID.toString();
//             User aUser = new User();
//             aUser.setSession(sessionID);
//             aUser.setUname(userName);
//             aUser.setPword(password);
//             theModel.addUser(aUser);
//             responseMap.put("id",sessionID);
//         }
//         responseMap.put("id",sessionID);
//         JSONOutputStream outToClient = (JSONOutputStream)dataMap.get("toClient");
//         try {
//             outToClient.writeObject(responseMap);
//         }
//         catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }


import com.doing.more.java.example.appcontrol.ApplicationController;
import com.doing.more.java.example.handlers.LoginHandler;
import com.doing.more.java.example.handlers.LogoutHandler;
import com.doing.more.java.example.handlers.RegistrationHandler;
import json.JSONInputStream;
import json.JSONOutputStream;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
package com.doing.more.java.example;




@WebServlet(name = "StoreServlet")
public class StoreServlet extends HttpServlet {
    private ApplicationController theAppController = new ApplicationController();
    private StoreModel theModel = new StoreModel();

    public void init(){
        theAppController.mapCommand("register", new RegistrationHandler());
// Path: LoginHandler.java
// public class LoginHandler implements Handler {
//     @Override
//     public void handleIt(HashMap<String, Object> dataMap) {
//         String userName = (String)dataMap.get("uname");
//         String password = (String)dataMap.get("pword");
//         StoreModel theModel = (StoreModel)dataMap.get("model");
//         User foundUser = theModel.getUser(userName, password);
//         HashMap<String,Object>responseMap = new HashMap<>();
//         String sessionID = "";
//         if(foundUser != null){
//             UUID sessionUUID = UUID.randomUUID();
//             sessionID = sessionUUID.toString();
//             foundUser.setSession(sessionID);
//             theModel.updateUser(foundUser);
//             responseMap.put("id",sessionID);
//         }
//         responseMap.put("id",sessionID);
//         JSONOutputStream outToClient = (JSONOutputStream)dataMap.get("toClient");
//         try {
//             outToClient.writeObject(responseMap);
//         }
//         catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: LogoutHandler.java
// public class LogoutHandler implements Handler {
//     @Override
//     public void handleIt(HashMap<String, Object> dataMap) {
// 
//         String sessionID = (String)dataMap.get("id");
//         StoreModel theModel = (StoreModel)dataMap.get("model");
//         User foundUser = theModel.getUserBySessionID(sessionID);
//         if(foundUser != null){
//             foundUser.setSession("");
//             theModel.updateUser(foundUser);
//         }
//         HashMap<String,Object> responseMap = new HashMap<>();
//         responseMap.put("id","");
//         JSONOutputStream outToClient = (JSONOutputStream)dataMap.get("toClient");
//         try {
//             outToClient.writeObject(responseMap);
//         }
//         catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }
// 
// Path: RegistrationHandler.java
// public class RegistrationHandler implements Handler {
//     @Override
//     public void handleIt(HashMap<String, Object> dataMap) {
//         String userName = (String)dataMap.get("uname");
//         String password = (String)dataMap.get("pword");
//         StoreModel theModel = (StoreModel)dataMap.get("model");
//         User foundUser = theModel.getUser(userName, password);
//         HashMap<String,Object>responseMap = new HashMap<>();
//         String sessionID = "";
//         if(foundUser == null){
//             UUID sessionUUID = UUID.randomUUID();
//             sessionID = sessionUUID.toString();
//             User aUser = new User();
//             aUser.setSession(sessionID);
//             aUser.setUname(userName);
//             aUser.setPword(password);
//             theModel.addUser(aUser);
//             responseMap.put("id",sessionID);
//         }
//         responseMap.put("id",sessionID);
//         JSONOutputStream outToClient = (JSONOutputStream)dataMap.get("toClient");
//         try {
//             outToClient.writeObject(responseMap);
//         }
//         catch (Exception e) {
//             e.printStackTrace();
//         }
//     }
// }


// Path: StoreServlet.java
import com.doing.more.java.example.appcontrol.ApplicationController;
import com.doing.more.java.example.handlers.LoginHandler;
import com.doing.more.java.example.handlers.LogoutHandler;
import com.doing.more.java.example.handlers.RegistrationHandler;
import json.JSONInputStream;
import json.JSONOutputStream;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

package com.doing.more.java.example;




@WebServlet(name = "StoreServlet")
public class StoreServlet extends HttpServlet {
    private ApplicationController theAppController = new ApplicationController();
    private StoreModel theModel = new StoreModel();

    public void init(){
        theAppController.mapCommand("register", new RegistrationHandler());
        theAppController.mapCommand("login", new LoginHandler());