Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Metodo login
- public static String login(String userid, String pswrd){
- String username = null;
- String Password = null;
- try {
- Class.forName("org.sqlite.JDBC");
- String dbURL = "jdbc:sqlite:/C:/Users/Alessandro/Desktop/db/HH_database.db";
- Connection conn = DriverManager.getConnection(dbURL);
- if (conn != null) {
- //GetUsername = JOptionPane.showInputDialog("Inserisci l'username");
- //GetPassword= JOptionPane.showInputDialog("Inserisci la password");
- Statement stmt = conn.createStatement();
- ResultSet rs;
- rs = stmt.executeQuery("SELECT Username, Password, Local_User_ID, Name, Surname FROM User_Data WHERE Username='" + userid + "' AND Password= '" + pswrd + "'");
- if(rs.next()){
- int Local_User_ID = rs.getInt("Local_User_ID");
- String Username = rs.getString("Username");
- ArrayList<String> res = new ArrayList<String>();
- ArrayList<Integer> res_1 = new ArrayList<Integer>();
- ArrayList<String> res_2 = new ArrayList<String>();
- String Name = rs.getString("Name");
- String Surname = rs.getString("Surname");
- rs = stmt.executeQuery("SELECT Device_Description, D.Local_Device_ID, Feature_ID_List FROM User_Device_Map U, Devices D WHERE U.Local_Device_ID=D.Local_Device_ID AND Local_User_ID= '" + Local_User_ID + "'");
- while(rs.next()){
- String Device = rs.getString("Device_Description");
- String Features_ID_List = rs.getString("Feature_ID_List");
- int ID = rs.getInt("Local_Device_ID");
- res.add(Device);
- res_1.add(ID);
- res_2.add(Features_ID_List);
- }
- d = new InfoDevice(res_1, res, res_2, Local_User_ID);
- u = new UtenteCurrent(Username, Password, res, res_1);
- return InfoDevice.toJson(Username, Local_User_ID, Name, Surname, res, res_1, res_2);
- }
- conn.close();
- return "Username" + " " + userid + " " + "e" + " " + "Password" + " " + pswrd + " " + "Sbagliate";
- }
- } catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- return "ciao";
- }
- metodo toJson
- public static String toJson(String Username, Integer Local_User_ID, String Name, String Surname, ArrayList <String> a, ArrayList <Integer> b, ArrayList <String> c)
- {
- String result = "{\r ";
- result+="\"Username\": \"" + Username + "\",\r ";
- result+="\"ID\": \"" + Local_User_ID + "\",\r ";
- result+="\"Nome\": \"" + Name + "\",\r ";
- result+="\"Cognome\": \"" + Surname + "\",\r ";
- result+="\"devices\": [\r ";
- for(int i=0;i<a.size();i++){
- result+=" {\r";
- result+=" \"name\": \""+ a.get(i)+ "\",\r";
- result+=" \"id\": \""+ b.get(i)+ "\",\r";
- result+=" \"features\": " + "[ "+c.get(i)+" ]\r";
- result+=" },\r";
- }
- result+=" ]\r}";
- return result;
- }
- metodo POST
- @POST
- @Produces({MediaType.APPLICATION_JSON})
- @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
- public String sayJSONQuery(
- @FormParam("id") String id,
- @FormParam("pswrd") String pswrd,
- @Context HttpServletResponse servletResponse) throws IOException {
- return UtenteCurrent.login(id, pswrd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement