* code format cleanup
* load total collections and future/finished ones
This commit is contained in:
		@@ -11,7 +11,7 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.GregorianCalendar;
 | 
			
		||||
import java.util.Scanner;
 | 
			
		||||
 | 
			
		||||
public class Date {
 | 
			
		||||
public class Dateget {
 | 
			
		||||
    private int index = 0;
 | 
			
		||||
    ArrayList<String> list = new ArrayList<>();
 | 
			
		||||
    ArrayList<String> listnew = new ArrayList<>();
 | 
			
		||||
@@ -26,7 +26,7 @@ public class Date {
 | 
			
		||||
 | 
			
		||||
        URL url = null;
 | 
			
		||||
        try {
 | 
			
		||||
            url = new URL("https://www.steyr.at/system/web/kalender.aspx?vdatum="+datum+"&bdatum=19.10.2019&typ=&typid=0&typids=225781950&detailonr=0&menuonr=225781812");
 | 
			
		||||
            url = new URL("https://www.steyr.at/system/web/kalender.aspx?vdatum=" + datum + "&bdatum=19.10.2019&typ=&typid=0&typids=225781950&detailonr=0&menuonr=225781812");
 | 
			
		||||
            Scanner scanner = new Scanner(new InputStreamReader(url.openStream()));
 | 
			
		||||
 | 
			
		||||
            int n = 0;
 | 
			
		||||
@@ -81,22 +81,19 @@ public class Date {
 | 
			
		||||
                    String part1 = parts[0]; // 004
 | 
			
		||||
                    String part2 = parts[1]; // 034556*/
 | 
			
		||||
 | 
			
		||||
                  splitter();
 | 
			
		||||
                    splitter();
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void splitter()
 | 
			
		||||
    {
 | 
			
		||||
        String temp="</ul><h2>";
 | 
			
		||||
    private void splitter() {
 | 
			
		||||
        String temp = "</ul><h2>";
 | 
			
		||||
 | 
			
		||||
        for (int n=0; n<listnew.size();n++)
 | 
			
		||||
        {
 | 
			
		||||
        for (int n = 0; n < listnew.size(); n++) {
 | 
			
		||||
 | 
			
		||||
            if(listnew.get(n).equals(temp))
 | 
			
		||||
            {
 | 
			
		||||
            if (listnew.get(n).equals(temp)) {
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -1,9 +1,10 @@
 | 
			
		||||
package com.wasteinformationserver.db;
 | 
			
		||||
 | 
			
		||||
import com.wasteinformationserver.basicutils.Log;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.sql.*;
 | 
			
		||||
import java.sql.Connection;
 | 
			
		||||
import java.sql.PreparedStatement;
 | 
			
		||||
import java.sql.ResultSet;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 | 
			
		||||
public class JDCB {
 | 
			
		||||
    static Connection conn;
 | 
			
		||||
@@ -21,18 +22,18 @@ public class JDCB {
 | 
			
		||||
        usernamec = username;
 | 
			
		||||
        passwordc = password;
 | 
			
		||||
        dbnamec = dbname;
 | 
			
		||||
        jdcb = new JDCB(username,password,dbname,ip,port);
 | 
			
		||||
        jdcb = new JDCB(username, password, dbname, ip, port);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private JDCB(String username, String password, String dbname, String ip, int port) throws IOException {
 | 
			
		||||
        logintodb(username,password,dbname,ip, port);
 | 
			
		||||
        logintodb(username, password, dbname, ip, port);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static JDCB getInstance() throws IOException {
 | 
			
		||||
        if (loggedin){
 | 
			
		||||
        if (loggedin) {
 | 
			
		||||
            return jdcb;
 | 
			
		||||
        }else {
 | 
			
		||||
            logintodb(usernamec,passwordc,dbnamec,ipc,portc);
 | 
			
		||||
        } else {
 | 
			
		||||
            logintodb(usernamec, passwordc, dbnamec, ipc, portc);
 | 
			
		||||
            return jdcb;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -66,8 +67,8 @@ public class JDCB {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int executeUpdate(String sql) throws SQLException {
 | 
			
		||||
            PreparedStatement stmt = conn.prepareStatement(sql);
 | 
			
		||||
        PreparedStatement stmt = conn.prepareStatement(sql);
 | 
			
		||||
 | 
			
		||||
            return stmt.executeUpdate();
 | 
			
		||||
        return stmt.executeUpdate();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package com.wasteinformationserver;
 | 
			
		||||
 | 
			
		||||
import com.wasteinformationserver.basicutils.Log;
 | 
			
		||||
import com.wasteinformationserver.db.JDCB;
 | 
			
		||||
import com.wasteinformationserver.mqtt.*;
 | 
			
		||||
import com.wasteinformationserver.mqtt.mqtt;
 | 
			
		||||
import com.wasteinformationserver.website.Webserver;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ public class mqtt {
 | 
			
		||||
            client.connect(connOpts);
 | 
			
		||||
 | 
			
		||||
        } catch (MqttException e) {
 | 
			
		||||
            Log.error("Connection to the ESB was failes");
 | 
			
		||||
            Log.error("Connection to the ESB was failed");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mqttreceiver mr = new mqttreceiver(client);
 | 
			
		||||
@@ -92,7 +92,7 @@ public class mqtt {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            Log.error("No data from databank");
 | 
			
		||||
            Log.error("No data from database");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,7 @@
 | 
			
		||||
package com.wasteinformationserver.mqtt;
 | 
			
		||||
 | 
			
		||||
import com.wasteinformationserver.basicutils.Log;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttCallback;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttClient;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttException;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.*;
 | 
			
		||||
 | 
			
		||||
import java.awt.event.ActionEvent;
 | 
			
		||||
import java.awt.event.ActionListener;
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,6 @@ package com.wasteinformationserver.mqtt;
 | 
			
		||||
 | 
			
		||||
import com.wasteinformationserver.basicutils.Log;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttClient;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttException;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
 | 
			
		||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
 | 
			
		||||
 
 | 
			
		||||
@@ -19,40 +19,42 @@ import com.sun.net.httpserver.HttpHandler;
 | 
			
		||||
import com.wasteinformationserver.basicutils.Log;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.login.LoginState;
 | 
			
		||||
 | 
			
		||||
import java.io.*;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
 | 
			
		||||
public class MainPage implements HttpHandler {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void handle(HttpExchange t) throws IOException {
 | 
			
		||||
        String path = t.getRequestURI().getPath();
 | 
			
		||||
 | 
			
		||||
        if (path.equals("/")){
 | 
			
		||||
        if (path.equals("/")) {
 | 
			
		||||
            path += "index.html";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Log.debug("looking for: " +  path);
 | 
			
		||||
        Log.debug("looking for: " + path);
 | 
			
		||||
 | 
			
		||||
        if (path.contains(".html")){
 | 
			
		||||
            if (LoginState.getObject().isLoggedIn() || path.equals("/register.html")){ //pass only register page
 | 
			
		||||
        if (path.contains(".html")) {
 | 
			
		||||
            if (LoginState.getObject().isLoggedIn() || path.equals("/register.html")) { //pass only register page
 | 
			
		||||
                sendPage(path, t);
 | 
			
		||||
            }else {
 | 
			
		||||
            } else {
 | 
			
		||||
                Log.warning("user not logged in --> redirecting to login page");
 | 
			
		||||
                sendPage("/index.html",t);
 | 
			
		||||
                sendPage("/index.html", t);
 | 
			
		||||
            }
 | 
			
		||||
        }else { //only detect login state on html pages
 | 
			
		||||
        } else { //only detect login state on html pages
 | 
			
		||||
            sendPage(path, t);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void sendPage(String path, HttpExchange t) throws IOException {
 | 
			
		||||
        InputStream fs = getClass().getResourceAsStream("/wwwroot"+path);
 | 
			
		||||
        InputStream fs = getClass().getResourceAsStream("/wwwroot" + path);
 | 
			
		||||
 | 
			
		||||
        if (fs== null && path.substring(path.length() - 4).equals("html")) {
 | 
			
		||||
        if (fs == null && path.substring(path.length() - 4).equals("html")) {
 | 
			
		||||
            Log.warning("wrong page sending 404");
 | 
			
		||||
            sendPage("/404Error.html",t);
 | 
			
		||||
        } else if(fs== null){
 | 
			
		||||
            sendPage("/404Error.html", t);
 | 
			
		||||
        } else if (fs == null) {
 | 
			
		||||
 | 
			
		||||
        }else {
 | 
			
		||||
        } else {
 | 
			
		||||
            // Object exists and is a file: accept with response code 200.
 | 
			
		||||
            String mime = "text/html";
 | 
			
		||||
            if (path.substring(path.length() - 3).equals(".js")) mime = "application/javascript";
 | 
			
		||||
 
 | 
			
		||||
@@ -3,11 +3,11 @@ package com.wasteinformationserver.website;
 | 
			
		||||
import com.sun.net.httpserver.HttpServer;
 | 
			
		||||
import com.wasteinformationserver.basicutils.Log;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.AdminRequests;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.NewDateRequest;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.login.CheckLoginState;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.DataRequest;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.login.LoginRequest;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.NewDateRequest;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.RegisterRequest;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.login.CheckLoginState;
 | 
			
		||||
import com.wasteinformationserver.website.datarequests.login.LoginRequest;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.net.InetSocketAddress;
 | 
			
		||||
 
 | 
			
		||||
@@ -37,7 +37,6 @@ public abstract class GetRequest implements HttpHandler {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @param params received get params from com.wasteinformationserver.website
 | 
			
		||||
     * @return json reply to com.wasteinformationserver.website
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ public abstract class PostRequest implements HttpHandler {
 | 
			
		||||
            while ((i = ios.read()) != -1) {
 | 
			
		||||
                sb.append((char) i);
 | 
			
		||||
            }
 | 
			
		||||
            String query =  sb.toString();
 | 
			
		||||
            String query = sb.toString();
 | 
			
		||||
 | 
			
		||||
            HashMap<String, String> params = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
@@ -44,7 +44,6 @@ public abstract class PostRequest implements HttpHandler {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @param params received get params from com.wasteinformationserver.website
 | 
			
		||||
     * @return json reply to com.wasteinformationserver.website
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package com.wasteinformationserver.website.datarequests;
 | 
			
		||||
 | 
			
		||||
import com.wasteinformationserver.basicutils.Log;
 | 
			
		||||
import com.wasteinformationserver.db.JDCB;
 | 
			
		||||
import com.wasteinformationserver.website.basicrequest.PostRequest;
 | 
			
		||||
 | 
			
		||||
import java.io.File;
 | 
			
		||||
@@ -20,7 +18,7 @@ public class AdminRequests extends PostRequest {
 | 
			
		||||
                break;
 | 
			
		||||
            case "restartserver":
 | 
			
		||||
                final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
 | 
			
		||||
                 File currentJar = null;
 | 
			
		||||
                File currentJar = null;
 | 
			
		||||
                try {
 | 
			
		||||
                    currentJar = new File(AdminRequests.class.getProtectionDomain().getCodeSource().getLocation().toURI());
 | 
			
		||||
                } catch (URISyntaxException e) {
 | 
			
		||||
@@ -28,7 +26,7 @@ public class AdminRequests extends PostRequest {
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                /* is it a jar file? */
 | 
			
		||||
                if(!currentJar.getName().endsWith(".jar"))
 | 
			
		||||
                if (!currentJar.getName().endsWith(".jar"))
 | 
			
		||||
                    System.out.println("not jar");
 | 
			
		||||
 | 
			
		||||
                /* Build command: java -jar application.jar */
 | 
			
		||||
 
 | 
			
		||||
@@ -8,12 +8,15 @@ import java.io.IOException;
 | 
			
		||||
import java.sql.ResultSet;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.sql.SQLIntegrityConstraintViolationException;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
public class DataRequest extends PostRequest {
 | 
			
		||||
    @Override
 | 
			
		||||
    public String request(HashMap<String, String> params) {
 | 
			
		||||
        String result = "";
 | 
			
		||||
        StringBuilder sb = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
        JDCB jdcb;
 | 
			
		||||
        try {
 | 
			
		||||
            jdcb = JDCB.getInstance();
 | 
			
		||||
@@ -23,7 +26,6 @@ public class DataRequest extends PostRequest {
 | 
			
		||||
        }
 | 
			
		||||
        switch (params.get("action")) {
 | 
			
		||||
            case "newCity":
 | 
			
		||||
                StringBuilder sb = new StringBuilder();
 | 
			
		||||
                sb.append("{");
 | 
			
		||||
                Log.debug(params.toString());
 | 
			
		||||
 | 
			
		||||
@@ -67,23 +69,19 @@ public class DataRequest extends PostRequest {
 | 
			
		||||
 | 
			
		||||
                sb.append(",\"query\":\"ok\"");
 | 
			
		||||
                sb.append("}");
 | 
			
		||||
 | 
			
		||||
                result = sb.toString();
 | 
			
		||||
                break;
 | 
			
		||||
            case "getAllCities":
 | 
			
		||||
                StringBuilder builder = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
                ResultSet sett = jdcb.executeQuery("select * from cities");
 | 
			
		||||
                Log.debug(sett.toString());
 | 
			
		||||
                builder.append("{\"data\":[");
 | 
			
		||||
                sb.append("{\"data\":[");
 | 
			
		||||
                try {
 | 
			
		||||
                    while (sett.next()) {
 | 
			
		||||
                        builder.append("{\"cityname\":\"" + sett.getString("name") + "\"");
 | 
			
		||||
                        builder.append(",\"wastetype\":\"" + sett.getString("wastetype") + "\"");
 | 
			
		||||
                        builder.append(",\"id\":\"" + sett.getString("id") + "\"");
 | 
			
		||||
                        builder.append(",\"zone\":\"" + sett.getString("zone") + "\"}");
 | 
			
		||||
                        sb.append("{\"cityname\":\"" + sett.getString("name") + "\"");
 | 
			
		||||
                        sb.append(",\"wastetype\":\"" + sett.getString("wastetype") + "\"");
 | 
			
		||||
                        sb.append(",\"id\":\"" + sett.getString("id") + "\"");
 | 
			
		||||
                        sb.append(",\"zone\":\"" + sett.getString("zone") + "\"}");
 | 
			
		||||
                        if (!sett.isLast()) {
 | 
			
		||||
                            builder.append(",");
 | 
			
		||||
                            sb.append(",");
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
//                        System.out.println(sett.getString("name"));
 | 
			
		||||
@@ -91,43 +89,89 @@ public class DataRequest extends PostRequest {
 | 
			
		||||
                } catch (SQLException e) {
 | 
			
		||||
                    e.printStackTrace();
 | 
			
		||||
                }
 | 
			
		||||
                builder.append("]");
 | 
			
		||||
                builder.append(",\"query\":\"ok\"");
 | 
			
		||||
                builder.append("}");
 | 
			
		||||
                result = builder.toString();
 | 
			
		||||
                Log.debug(result);
 | 
			
		||||
                sb.append("]");
 | 
			
		||||
                sb.append(",\"query\":\"ok\"");
 | 
			
		||||
                sb.append("}");
 | 
			
		||||
                break;
 | 
			
		||||
            case "deletecity":
 | 
			
		||||
                //DELETE FROM `cities` WHERE `id`=0
 | 
			
		||||
 | 
			
		||||
                StringBuilder sbb = new StringBuilder(); // TODO: 06.12.19 better naming and sb for all
 | 
			
		||||
                sbb.append("{");
 | 
			
		||||
                sb.append("{");
 | 
			
		||||
                Log.debug(params.get("id"));
 | 
			
		||||
                int status = 0;
 | 
			
		||||
                try{
 | 
			
		||||
                    status= jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id")+"'");
 | 
			
		||||
                    if (status == 1){
 | 
			
		||||
                try {
 | 
			
		||||
                    status = jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'");
 | 
			
		||||
                    if (status == 1) {
 | 
			
		||||
                        //success
 | 
			
		||||
                        sbb.append("\"status\" : \"success\"");
 | 
			
		||||
                    }else {
 | 
			
		||||
                        sbb.append("\"status\" : \"error\"");
 | 
			
		||||
                        sb.append("\"status\" : \"success\"");
 | 
			
		||||
                    } else {
 | 
			
		||||
                        sb.append("\"status\" : \"error\"");
 | 
			
		||||
                    }
 | 
			
		||||
                }catch (SQLIntegrityConstraintViolationException e){
 | 
			
		||||
                } catch (SQLIntegrityConstraintViolationException e) {
 | 
			
		||||
                    Log.warning("dependencies of deletion exist");
 | 
			
		||||
                    sbb.append("\"status\" : \"dependenciesnotdeleted\"");
 | 
			
		||||
                    sb.append("\"status\" : \"dependenciesnotdeleted\"");
 | 
			
		||||
                } catch (SQLException e) {
 | 
			
		||||
                    Log.error("sql exception: "+e.getMessage());
 | 
			
		||||
                    sbb.append("\"status\" : \"error\"");
 | 
			
		||||
                    Log.error("sql exception: " + e.getMessage());
 | 
			
		||||
                    sb.append("\"status\" : \"error\"");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Log.debug(status);
 | 
			
		||||
 | 
			
		||||
                sbb.append(",\"query\":\"ok\"");
 | 
			
		||||
                sbb.append("}");
 | 
			
		||||
                result = sbb.toString();
 | 
			
		||||
                sb.append(",\"query\":\"ok\"");
 | 
			
		||||
                sb.append("}");
 | 
			
		||||
 | 
			
		||||
                break;
 | 
			
		||||
            case "getcollectionnumber": //todo maybe combine all three to one
 | 
			
		||||
                sb.append("{");
 | 
			
		||||
 | 
			
		||||
                try {
 | 
			
		||||
                    ResultSet settt = jdcb.executeQuery("select * from pickupdates");
 | 
			
		||||
                    settt.last();
 | 
			
		||||
                    sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
 | 
			
		||||
                } catch (SQLException e) {
 | 
			
		||||
                    Log.error("sql exception: " + e.getMessage());
 | 
			
		||||
                    sb.append("\"status\" : \"error\"");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                sb.append(",\"query\":\"ok\"");
 | 
			
		||||
                sb.append("}");
 | 
			
		||||
                break;
 | 
			
		||||
            case "getcollectioninfuture":
 | 
			
		||||
                sb.append("{");
 | 
			
		||||
 | 
			
		||||
                try {
 | 
			
		||||
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 | 
			
		||||
                    Date date = new Date();
 | 
			
		||||
                    String time = sdf.format(date);
 | 
			
		||||
                    ResultSet settt = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'");
 | 
			
		||||
                    settt.last();
 | 
			
		||||
                    sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
 | 
			
		||||
                } catch (SQLException e) {
 | 
			
		||||
                    Log.error("sql exception: " + e.getMessage());
 | 
			
		||||
                    sb.append("\"status\" : \"error\"");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                sb.append(",\"query\":\"ok\"");
 | 
			
		||||
                sb.append("}");
 | 
			
		||||
                break;
 | 
			
		||||
            case "getfinishedcollections":
 | 
			
		||||
                sb.append("{");
 | 
			
		||||
 | 
			
		||||
                try {
 | 
			
		||||
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 | 
			
		||||
                    Date date = new Date();
 | 
			
		||||
                    String time = sdf.format(date);
 | 
			
		||||
                    ResultSet settt = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN  '0000-12-27' AND '"+time+"'");
 | 
			
		||||
                    settt.last();
 | 
			
		||||
                    sb.append("\"collectionnumber\":\"" + settt.getRow() + "\"");
 | 
			
		||||
                } catch (SQLException e) {
 | 
			
		||||
                    Log.error("sql exception: " + e.getMessage());
 | 
			
		||||
                    sb.append("\"status\" : \"error\"");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                sb.append(",\"query\":\"ok\"");
 | 
			
		||||
                sb.append("}");
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
        return sb.toString();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ public class RegisterRequest extends PostRequest {
 | 
			
		||||
        }
 | 
			
		||||
        //new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
 | 
			
		||||
        try {
 | 
			
		||||
            int s = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('"+params.get("username")+"', '"+params.get("firstname")+"', '"+params.get("lastname")+"', '"+passhash+"', '"+params.get("email")+"', current_timestamp());");
 | 
			
		||||
            int s = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params.get("username") + "', '" + params.get("firstname") + "', '" + params.get("lastname") + "', '" + passhash + "', '" + params.get("email") + "', current_timestamp());");
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,13 +9,13 @@ public class CheckLoginState extends PostRequest {
 | 
			
		||||
    @Override
 | 
			
		||||
    public String request(HashMap<String, String> params) {
 | 
			
		||||
        Log.message("checking login state");
 | 
			
		||||
        if ((params.get("action")).equals("getloginstate")){
 | 
			
		||||
            if (LoginState.getObject().isLoggedIn()){
 | 
			
		||||
                return "{\"loggedin\":true, \"username\":\""+LoginState.getObject().getUsername()+"\", \"permission\":\""+LoginState.getObject().getPermission()+"\"}";
 | 
			
		||||
            }else {
 | 
			
		||||
        if ((params.get("action")).equals("getloginstate")) {
 | 
			
		||||
            if (LoginState.getObject().isLoggedIn()) {
 | 
			
		||||
                return "{\"loggedin\":true, \"username\":\"" + LoginState.getObject().getUsername() + "\", \"permission\":\"" + LoginState.getObject().getPermission() + "\"}";
 | 
			
		||||
            } else {
 | 
			
		||||
                return "{\"loggedin\":false}";
 | 
			
		||||
            }
 | 
			
		||||
        }else if ((params.get("action")).equals("logout")){
 | 
			
		||||
        } else if ((params.get("action")).equals("logout")) {
 | 
			
		||||
            Log.debug("logging out");
 | 
			
		||||
            LoginState.getObject().logOut();
 | 
			
		||||
            return "{\"loggedin\":false}";
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,8 @@ public class LoginRequest extends PostRequest {
 | 
			
		||||
            return "{\"status\" : \"nodbconn\"}";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ResultSet s = jdcb.executeQuery("select * from user where username ='" + username + "'");;
 | 
			
		||||
        ResultSet s = jdcb.executeQuery("select * from user where username ='" + username + "'");
 | 
			
		||||
        ;
 | 
			
		||||
        //new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'");
 | 
			
		||||
        Log.debug("successfully logged in to db");
 | 
			
		||||
        String response = "{\"accept\": false}";
 | 
			
		||||
@@ -38,7 +39,7 @@ public class LoginRequest extends PostRequest {
 | 
			
		||||
                if (HttpTools.StringToMD5(password).equals(s.getString("password"))) {
 | 
			
		||||
                    Log.debug("login success");
 | 
			
		||||
                    LoginState.getObject().logIn();
 | 
			
		||||
                    LoginState.getObject().setAccountData(username,"","","", s.getInt("permission")); // TODO: 06.12.19
 | 
			
		||||
                    LoginState.getObject().setAccountData(username, "", "", "", s.getInt("permission")); // TODO: 06.12.19
 | 
			
		||||
                    response = "{\"accept\": true}";
 | 
			
		||||
                } else {
 | 
			
		||||
                    Log.debug("wrong password");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,12 @@
 | 
			
		||||
package com.wasteinformationserver.website.datarequests.login;
 | 
			
		||||
 | 
			
		||||
public class LoginState {
 | 
			
		||||
    private LoginState() {}
 | 
			
		||||
    private LoginState() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
   private static LoginState mythis=new LoginState();
 | 
			
		||||
    private static LoginState mythis = new LoginState();
 | 
			
		||||
 | 
			
		||||
    public static LoginState getObject(){
 | 
			
		||||
    public static LoginState getObject() {
 | 
			
		||||
        return mythis;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -17,23 +18,23 @@ public class LoginState {
 | 
			
		||||
 | 
			
		||||
    boolean loggedin = true;
 | 
			
		||||
 | 
			
		||||
    public void logIn(){
 | 
			
		||||
        loggedin=true;
 | 
			
		||||
    public void logIn() {
 | 
			
		||||
        loggedin = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void logOut(){
 | 
			
		||||
        loggedin=false;
 | 
			
		||||
    public void logOut() {
 | 
			
		||||
        loggedin = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAccountData(String username, String firstname, String lastname, String email, int permission){
 | 
			
		||||
        this.username=username;
 | 
			
		||||
        this.firstname=firstname;
 | 
			
		||||
        this.lastname=lastname;
 | 
			
		||||
        this.email=email;
 | 
			
		||||
    public void setAccountData(String username, String firstname, String lastname, String email, int permission) {
 | 
			
		||||
        this.username = username;
 | 
			
		||||
        this.firstname = firstname;
 | 
			
		||||
        this.lastname = lastname;
 | 
			
		||||
        this.email = email;
 | 
			
		||||
        this.permission = permission;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isLoggedIn(){
 | 
			
		||||
    public boolean isLoggedIn() {
 | 
			
		||||
        return loggedin;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -132,9 +132,9 @@
 | 
			
		||||
                        <!-- small box -->
 | 
			
		||||
                        <div class="small-box bg-info">
 | 
			
		||||
                            <div class="inner">
 | 
			
		||||
                                <h3>150</h3>
 | 
			
		||||
                                <h3 id="total-connection-labels">42</h3>
 | 
			
		||||
 | 
			
		||||
                                <p>Totale Abholungen</p>
 | 
			
		||||
                                <p>Total collections</p>
 | 
			
		||||
                            </div>
 | 
			
		||||
                            <div class="icon">
 | 
			
		||||
                                <i class="ion ion-bag"></i>
 | 
			
		||||
@@ -162,9 +162,9 @@
 | 
			
		||||
                        <!-- small box -->
 | 
			
		||||
                        <div class="small-box bg-warning">
 | 
			
		||||
                            <div class="inner">
 | 
			
		||||
                                <h3>44</h3>
 | 
			
		||||
                                <h3 id="planed-collection-label">44</h3>
 | 
			
		||||
 | 
			
		||||
                                <p>Geplante Abholungen</p>
 | 
			
		||||
                                <p>Planned Collections</p>
 | 
			
		||||
                            </div>
 | 
			
		||||
                            <div class="icon">
 | 
			
		||||
                                <i class="ion ion-person-add"></i>
 | 
			
		||||
@@ -177,9 +177,9 @@
 | 
			
		||||
                        <!-- small box -->
 | 
			
		||||
                        <div class="small-box bg-danger">
 | 
			
		||||
                            <div class="inner">
 | 
			
		||||
                                <h3>65</h3>
 | 
			
		||||
                                <h3 id="finished-collection-label">65</h3>
 | 
			
		||||
 | 
			
		||||
                                <p>Abgeschlossene Abholungen</p>
 | 
			
		||||
                                <p>Finished Collections</p>
 | 
			
		||||
                            </div>
 | 
			
		||||
                            <div class="icon">
 | 
			
		||||
                                <i class="ion ion-pie-graph"></i>
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,24 @@ $(document).ready(function () {
 | 
			
		||||
        }
 | 
			
		||||
    }, 'json');
 | 
			
		||||
 | 
			
		||||
    //load total collections
 | 
			
		||||
    $.post('/senddata/wastedata', 'action=getcollectionnumber', function (data) {
 | 
			
		||||
        console.log(data);
 | 
			
		||||
        $("#total-connection-labels").html(data.collectionnumber);
 | 
			
		||||
    }, 'json');
 | 
			
		||||
 | 
			
		||||
    //load future collections
 | 
			
		||||
    $.post('/senddata/wastedata', 'action=getcollectioninfuture', function (data) {
 | 
			
		||||
        console.log(data);
 | 
			
		||||
        $("#planed-collection-label").html(data.collectionnumber);
 | 
			
		||||
    }, 'json');
 | 
			
		||||
 | 
			
		||||
    //load future collections
 | 
			
		||||
    $.post('/senddata/wastedata', 'action=getfinishedcollections', function (data) {
 | 
			
		||||
        console.log(data);
 | 
			
		||||
        $("#finished-collection-label").html(data.collectionnumber);
 | 
			
		||||
    }, 'json');
 | 
			
		||||
 | 
			
		||||
    var citytable;
 | 
			
		||||
 | 
			
		||||
    function reloadtable() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user