Compare commits

...

21 Commits

Author SHA1 Message Date
c71b50a041 release version 1.1.1 2020-04-24 15:37:41 +02:00
af9d5662b1 dependencie error popup corrections
table reload after deleting corrections
2020-04-24 15:32:33 +02:00
a71c1a09a6 reconnection to the mqtt server if failed on startup 2020-04-24 14:34:58 +02:00
05cc2f83d6 Update .gitlab-ci.yml 2020-04-18 12:13:51 +00:00
f94fd7d037 add gitlab ci 2020-04-18 12:09:56 +00:00
Lukas Heiligenbrunner
59cb7c3c4f added jar build 2020-04-18 13:49:34 +02:00
Lukas Heiligenbrunner
2ac3cf629f added build argument 2020-04-18 13:46:16 +02:00
Lukas Heiligenbrunner
506c6f9b09 improved action 2020-04-18 13:45:03 +02:00
Lukas Heiligenbrunner
ba5048e119 added github action 2020-04-18 13:40:50 +02:00
Lukas Heiligenbrunner
26279130b7 logintodb nonstatic 2020-04-17 18:36:05 +02:00
Lukas-Heiligenbrunner
30b51f9032
Merge pull request #12 from IngProjDutzlerHeiligenbrunnerMeindl/dbschemacheck
Dbschemacheck
2020-04-17 18:32:33 +02:00
Lukas-Heiligenbrunner
51f6ca8958
Merge branch 'master' into dbschemacheck 2020-04-17 18:32:23 +02:00
Lukas-Heiligenbrunner
f8fd7d1b5e
Merge pull request #13 from IngProjDutzlerHeiligenbrunnerMeindl/dbReconnect
Db reconnect
2020-04-17 18:29:24 +02:00
EmilMeindl
23df933504 finished statement db reconnect 2020-04-17 18:28:10 +02:00
Lukas Heiligenbrunner
3a51b08de8 added some message outputs, edited libs in register html 2020-04-17 18:11:23 +02:00
Lukas Heiligenbrunner
f4fbce7977 improved autocreate of table structure 2020-04-17 18:00:47 +02:00
EmilMeindl
605a2ca33d finished initial db reconnect 2020-04-17 16:52:19 +02:00
Lukas Heiligenbrunner
a633ba42e9 added auto generation of sql structure on db 2020-04-17 16:20:44 +02:00
EmilMeindl
f0e654399a test reconnect logic 2020-04-17 16:10:18 +02:00
Lukas Heiligenbrunner
a98c3eae71 updated sql structure 2020-04-17 15:12:22 +02:00
lukas-heiligenbrunner
3fba0f9933 version 1.1.0
method name convention
2020-04-15 17:03:45 +02:00
11 changed files with 340 additions and 272 deletions

28
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,28 @@
# .github/workflows/gradle-build-pr.yml
name: Run Gradle on pushs
on:
push:
branches:
- '*'
pull_request:
branches:
- '*'
jobs:
gradle:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: 11
- uses: eskatos/gradle-command-action@v1
with:
gradle-version: rc
arguments: build
- uses: eskatos/gradle-command-action@v1
with:
gradle-version: rc
arguments: jar

35
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,35 @@
# This file is a template, and might need editing before it works on your project.
# This is the Gradle build system for JVM applications
# https://gradle.org/
# https://github.com/gradle/gradle
image: gradle:latest
# Disable the Gradle daemon for Continuous Integration servers as correctness
# is usually a priority over speed in CI environments. Using a fresh
# runtime for each build is more reliable since the runtime is completely
# isolated from any previous builds.
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
build:
stage: build
script: gradle --build-cache assemble
cache:
key: "$CI_COMMIT_REF_NAME"
policy: push
paths:
- build
- .gradle
test:
stage: test
script: gradle check
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- build
- .gradle

View File

@ -6,7 +6,7 @@ plugins {
} }
group 'com.wasteinformationserver' group 'com.wasteinformationserver'
version '1.0.1' version '1.1.1'
sourceCompatibility = 1.8 sourceCompatibility = 1.8

156
db.sql
View File

@ -1,156 +0,0 @@
-- phpMyAdmin SQL Dump
-- version 4.9.0.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Erstellungszeit: 06. Dez 2019 um 16:11
-- Server-Version: 10.3.11-MariaDB
-- PHP-Version: 5.6.40
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Datenbank: `wasteinformation`
--
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `cities`
--
CREATE TABLE `cities` (
`id` int(11) NOT NULL,
`userid` int(11) NOT NULL,
`name` varchar(256) NOT NULL,
`wastetype` varchar(64) NOT NULL,
`zone` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `cities`
--
INSERT INTO `cities` (`id`, `userid`, `name`, `wastetype`, `zone`) VALUES
(2, 0, 'Steyr', 'Bio', 2),
(3, 0, 'Steyr', 'Bio', 3),
(4, 0, 'Steyr', 'Bio', 4),
(128, 0, 'Steyr', 'Biowaste', 1),
(130, 0, 'abc', 'Biowaste', 1);
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `pickupdates`
--
CREATE TABLE `pickupdates` (
`id` int(11) NOT NULL,
`citywastezoneid` int(11) NOT NULL,
`pickupdate` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `pickupdates`
--
INSERT INTO `pickupdates` (`id`, `citywastezoneid`, `pickupdate`) VALUES
(6, 4, '2019-12-06'),
(7, 3, '2019-12-06'),
(8, 2, '2019-12-06'),
(9, 130, '2019-12-26');
-- --------------------------------------------------------
--
-- Tabellenstruktur für Tabelle `user`
--
CREATE TABLE `user` (
`id` int(11) NOT NULL,
`username` varchar(150) NOT NULL,
`firstName` varchar(32) NOT NULL,
`secondName` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
`permission` int(11) NOT NULL DEFAULT 0,
`email` varchar(64) NOT NULL,
`logindate` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Daten für Tabelle `user`
--
INSERT INTO `user` (`id`, `username`, `firstName`, `secondName`, `password`, `permission`, `email`, `logindate`) VALUES
(2, 'lheilige', 'lukas', 'heiligenbrunner', 'c6e2ddf577e0dfdc4366f788f1b27102', 0, 'lukas.heiligenbrunner@gmail.com', '2019-09-20 12:19:31'),
(11, 'meindl', 'emil', 'meindl', '81dc9bdb52d04dc20036dbd8313ed055', 0, 'mailmeindl', '2019-09-27 10:23:46'),
(15, 'horni', 'kk', 'kk', 'c4ca4238a0b923820dcc509a6f75849b', 1, 'kk', '2019-09-27 13:19:09');
--
-- Indizes der exportierten Tabellen
--
--
-- Indizes für die Tabelle `cities`
--
ALTER TABLE `cities`
ADD PRIMARY KEY (`id`);
--
-- Indizes für die Tabelle `pickupdates`
--
ALTER TABLE `pickupdates`
ADD PRIMARY KEY (`id`),
ADD KEY `citywastezoneid` (`citywastezoneid`);
--
-- Indizes für die Tabelle `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT für exportierte Tabellen
--
--
-- AUTO_INCREMENT für Tabelle `cities`
--
ALTER TABLE `cities`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=131;
--
-- AUTO_INCREMENT für Tabelle `pickupdates`
--
ALTER TABLE `pickupdates`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
--
-- AUTO_INCREMENT für Tabelle `user`
--
ALTER TABLE `user`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
--
-- Constraints der exportierten Tabellen
--
--
-- Constraints der Tabelle `pickupdates`
--
ALTER TABLE `pickupdates`
ADD CONSTRAINT `pickupdates_ibfk_1` FOREIGN KEY (`citywastezoneid`) REFERENCES `cities` (`id`);
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

View File

@ -1,4 +1,5 @@
@file:JvmName("Main") @file:JvmName("Main")
package com.wasteinformationserver package com.wasteinformationserver
import com.wasteinformationserver.basicutils.Info import com.wasteinformationserver.basicutils.Info
@ -7,7 +8,6 @@ import com.wasteinformationserver.basicutils.Storage
import com.wasteinformationserver.db.JDBC import com.wasteinformationserver.db.JDBC
import com.wasteinformationserver.mqtt.MqttService import com.wasteinformationserver.mqtt.MqttService
import com.wasteinformationserver.website.Webserver import com.wasteinformationserver.website.Webserver
import java.io.IOException
/** /**
* application entry point * application entry point
@ -22,14 +22,9 @@ fun main() {
Log.info("startup of WasteInformationServer") Log.info("startup of WasteInformationServer")
Runtime.getRuntime().addShutdownHook(Thread(Runnable { Runtime.getRuntime().addShutdownHook(Thread(Runnable {
try { // shutdown routine
Thread.sleep(200)
Log.warning("Shutting down ...") Log.warning("Shutting down ...")
JDBC.getInstance().disconnect(); JDBC.getInstance().disconnect();
//shutdown routine
} catch (e: InterruptedException) {
e.printStackTrace()
}
})) }))
Log.info("Server version: " + Info.getVersion()) Log.info("Server version: " + Info.getVersion())
@ -37,14 +32,8 @@ fun main() {
//initial connect to db //initial connect to db
Log.message("initial login to db") Log.message("initial login to db")
try {
val stor = Storage.getInstance(); val stor = Storage.getInstance();
JDBC.init(stor.dbUser, stor.dbPassword, stor.dbName, stor.dbhost, stor.dbPort) JDBC.init(stor.dbUser, stor.dbPassword, stor.dbName, stor.dbhost, stor.dbPort)
//JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306)
//JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
} catch (e: IOException) {
Log.error("no connection to db")
}
//startup web server //startup web server
@ -55,11 +44,7 @@ fun main() {
//startup mqtt service //startup mqtt service
Log.message("starting mqtt service") Log.message("starting mqtt service")
if (JDBC.isConnected()) { val m = MqttService.getInstance()
val m = MqttService(Storage.getInstance().mqttServer, Storage.getInstance().mqttPort.toString()) m.init(Storage.getInstance().mqttServer, Storage.getInstance().mqttPort.toString())
// val m = MqttService("mqtt.heili.eu", "1883")
m.startupService() m.startupService()
}else{
Log.error("could't start mqtt service because of missing db connection!")
}
} }

View File

@ -1,14 +1,18 @@
package com.wasteinformationserver.db; package com.wasteinformationserver.db;
import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.basicutils.Storage;
import com.wasteinformationserver.mqtt.MqttService;
import java.io.IOException; import java.io.IOException;
import java.sql.*; import java.sql.*;
import java.util.Scanner;
/** /**
* basic connection class to a Database * basic connection class to a Database
* *
* @author Lukas Heiligenbrunner * @author Lukas Heiligenbrunner
* @author Emil Meindl
*/ */
public class JDBC { public class JDBC {
private static Connection conn; private static Connection conn;
@ -22,7 +26,7 @@ public class JDBC {
private static String ipc; private static String ipc;
private static int portc; private static int portc;
private JDBC(String username, String password, String dbname, String ip, int port) throws IOException { private JDBC(String username, String password, String dbname, String ip, int port) {
logintodb(username, password, dbname, ip, port); logintodb(username, password, dbname, ip, port);
} }
@ -66,11 +70,7 @@ public class JDBC {
*/ */
public static JDBC getInstance() { public static JDBC getInstance() {
if (!loggedin) { if (!loggedin) {
try { JDBC = new JDBC(usernamec, passwordc, dbnamec, ipc, portc);
logintodb(usernamec, passwordc, dbnamec, ipc, portc);
} catch (IOException e) {
Log.Log.error("no connetion to db - retrying in 5min");
}
} }
return JDBC; return JDBC;
} }
@ -85,18 +85,47 @@ public class JDBC {
* @param port Server port * @param port Server port
* @throws IOException thrown if no connection to db is possible. * @throws IOException thrown if no connection to db is possible.
*/ */
private static void logintodb(String username, String password, String dbname, String ip, int port) throws IOException { private boolean logintodb(String username, String password, String dbname, String ip, int port) {
try { try {
DriverManager.setLoginTimeout(1); DriverManager.setLoginTimeout(1);
conn = DriverManager.getConnection( conn = DriverManager.getConnection(
"jdbc:mysql://" + ip + ":" + port + "/" + dbname + "?useSSL=false&serverTimezone=CET", "jdbc:mysql://" + ip + ":" + port + "/" + dbname + "?useSSL=false&serverTimezone=CET",
username, username,
password); password);
checkDBStructure();
loggedin = true; loggedin = true;
Log.Log.message("Connected to database");
} catch (SQLException e) { } catch (SQLException e) {
throw new IOException("No connection to database"); // reconnect every 10 sec
// todo reconnect every 5mins or something Log.Log.warning("Database-Connection not possible");
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
} }
Log.Log.debug("Reading config");
Storage st = Storage.Companion.getInstance();
st.init();
usernamec = st.getDbName();
passwordc = st.getDbPassword();
dbnamec = st.getDbName();
ipc = st.getDbhost();
portc = st.getDbPort();
Log.Log.info("Retry connection");
loggedin = logintodb(usernamec, passwordc, dbnamec, ipc, portc);
if (loggedin) {
// startup mqtt service if successfully connected
MqttService srvc = MqttService.Companion.getInstance();
srvc.init(st.getMqttServer(), String.valueOf(st.getMqttPort()));
srvc.startupService();
}
}
}).start();
}
return loggedin;
} }
public void disconnect() { public void disconnect() {
@ -115,13 +144,20 @@ public class JDBC {
*/ */
public ResultSet executeQuery(String sql) { public ResultSet executeQuery(String sql) {
try { try {
conn.isValid(5);
PreparedStatement stmt = conn.prepareStatement(sql); PreparedStatement stmt = conn.prepareStatement(sql);
return stmt.executeQuery(); return stmt.executeQuery();
} catch (SQLException e) { } catch (SQLNonTransientConnectionException ee) {
e.printStackTrace(); if (logintodb(usernamec, passwordc, dbnamec, ipc, portc)) {
} return this.executeQuery(sql);
} else {
return null; return null;
} }
} catch (SQLException e) {
return null;
}
}
/** /**
* update db in some way * update db in some way
@ -131,9 +167,17 @@ public class JDBC {
* @throws SQLException * @throws SQLException
*/ */
public int executeUpdate(String sql) throws SQLException { public int executeUpdate(String sql) throws SQLException {
try {
conn.isValid(2);
PreparedStatement stmt = conn.prepareStatement(sql); PreparedStatement stmt = conn.prepareStatement(sql);
return stmt.executeUpdate(); return stmt.executeUpdate();
} catch (SQLNonTransientConnectionException ee) {
if (logintodb(usernamec, passwordc, dbnamec, ipc, portc)) {
return this.executeUpdate(sql);
} else {
throw new SQLNonTransientConnectionException();
}
}
} }
/** /**
@ -144,4 +188,42 @@ public class JDBC {
public static boolean isConnected() { public static boolean isConnected() {
return loggedin; return loggedin;
} }
/**
* validate the correctness of the current sql db structure
*/
public void checkDBStructure() {
try {
ResultSet seti = executeQuery("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '" + dbnamec + "'");
seti.last();
Log.Log.debug("found " + seti.getInt(1) + " tables in db");
if (seti.getInt(1) != 5) {
// structure not valid
Log.Log.info("recreating Database structure!");
Scanner s = new Scanner(getClass().getResourceAsStream("/db.sql"));
s.useDelimiter("(;(\r)?\n)|(--\n)");
Statement st = null;
try {
st = conn.createStatement();
while (s.hasNext()) {
String line = s.next();
if (line.startsWith("/*!") && line.endsWith("*/")) {
int i = line.indexOf(' ');
line = line.substring(i + 1, line.length() - " */".length());
}
if (line.trim().length() > 0) {
executeUpdate(line);
}
}
} finally {
if (st != null) st.close();
}
} else {
Log.Log.message("found valid database structure!");
}
} catch (SQLException e) {
Log.Log.error("a unhandled SQLexception occured at db structure creation.");
}
}
} }

View File

@ -1,5 +1,6 @@
package com.wasteinformationserver.mqtt package com.wasteinformationserver.mqtt
import com.wasteinformationserver.basicutils.Log
import com.wasteinformationserver.basicutils.Log.Log.debug import com.wasteinformationserver.basicutils.Log.Log.debug
import com.wasteinformationserver.basicutils.Log.Log.error import com.wasteinformationserver.basicutils.Log.Log.error
import com.wasteinformationserver.basicutils.Log.Log.info import com.wasteinformationserver.basicutils.Log.Log.info
@ -19,31 +20,38 @@ import java.util.*
* @author Lukas Heiligenbrunner * @author Lukas Heiligenbrunner
* @author Gregor Dutzler * @author Gregor Dutzler
*/ */
class MqttService(serverurl: String, port: String) { class MqttService {
private val serveruri: String = "tcp://$serverurl:$port" private var serveruri: String = "";
private var client: MqttClient = MqttClient(serveruri, "JavaSample42") private lateinit var client: MqttClient;
private var db: JDBC = JDBC.getInstance() private var db: JDBC = JDBC.getInstance()
/** companion object {
* initial login to db private val obj = MqttService()
*/ fun getInstance(): MqttService {
init { return obj;
connectToDb() }
}
fun init(serverurl: String, port: String){
serveruri = "tcp://$serverurl:$port"
} }
/** /**
* startup of the mqtt service * startup of the mqtt service
*/ */
fun startupService() { fun startupService() {
if(JDBC.isConnected()) {
try { try {
client = MqttClient(serveruri, "JavaSample42") client = MqttClient(serveruri, "WasteInformationServerID")
val connOpts = MqttConnectOptions() val connOpts = MqttConnectOptions()
connOpts.isCleanSession = true connOpts.isCleanSession = true
client.connect(connOpts) client.connect(connOpts)
client.setCallback(object : MqttCallback { client.setCallback(object : MqttCallback {
override fun connectionLost(throwable: Throwable) { override fun connectionLost(throwable: Throwable) {
error("connection lost") error("connection lost")
connectToDb() Thread.sleep(500)
// restart service
startupService()
} }
override fun messageArrived(s: String, mqttMessage: MqttMessage) { override fun messageArrived(s: String, mqttMessage: MqttMessage) {
@ -52,11 +60,13 @@ class MqttService(serverurl: String, port: String) {
val res = db.executeQuery("SELECT * from devices WHERE DeviceID=$deviceid") val res = db.executeQuery("SELECT * from devices WHERE DeviceID=$deviceid")
try { try {
res.last() res.last()
if (res.row != 0) { //existing device if (res.row != 0) {
// existing device
res.first() res.first()
val devicecities = db.executeQuery("SELECT * from device_city WHERE DeviceID='$deviceid'") val devicecities = db.executeQuery("SELECT * from device_city WHERE DeviceID='$deviceid'")
devicecities.last() devicecities.last()
if (devicecities.row == 0) { //not configured if (devicecities.row == 0) {
// not configured
tramsmitMessage("$deviceid,-1") tramsmitMessage("$deviceid,-1")
} }
else { else {
@ -69,7 +79,8 @@ class MqttService(serverurl: String, port: String) {
} }
} }
} }
else { //new device else {
// new device
db.executeUpdate("INSERT INTO devices (DeviceID) VALUES ($deviceid)") db.executeUpdate("INSERT INTO devices (DeviceID) VALUES ($deviceid)")
info("new device registered to server") info("new device registered to server")
tramsmitMessage("$deviceid,-1") tramsmitMessage("$deviceid,-1")
@ -85,6 +96,9 @@ class MqttService(serverurl: String, port: String) {
} catch (e: MqttException) { } catch (e: MqttException) {
error("Connection to the Broker failed") error("Connection to the Broker failed")
} }
}else{
Log.error("could't start mqtt service because of missing db connection!")
}
} }
/** /**
@ -98,7 +112,8 @@ class MqttService(serverurl: String, port: String) {
val set2 = db.executeQuery("SELECT * FROM cities WHERE `id`='$citywastezoneid'") val set2 = db.executeQuery("SELECT * FROM cities WHERE `id`='$citywastezoneid'")
try { try {
set2.last() set2.last()
if (set2.row != 1) { //error if (set2.row != 1) {
//error
warning("multiple Rows with same city id found - DB Error") warning("multiple Rows with same city id found - DB Error")
} }
else { else {
@ -111,7 +126,8 @@ class MqttService(serverurl: String, port: String) {
val result = db.executeQuery("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=$citywastezoneid") val result = db.executeQuery("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=$citywastezoneid")
try { try {
result.last() result.last()
if (result.row == 0) { //if not found in db --> send zero if (result.row == 0) {
//if not found in db --> send zero
debug("not found in db") debug("not found in db")
tramsmitMessage("$deviceid,$wastetype,0") tramsmitMessage("$deviceid,$wastetype,0")
} }
@ -130,7 +146,8 @@ class MqttService(serverurl: String, port: String) {
return return
} }
} while (result.next()) } while (result.next())
tramsmitMessage("$deviceid,$wastetype,0") //transmit zero if not returned before tramsmitMessage("$deviceid,$wastetype,0")
//transmit zero if not returned before
} }
} catch (e: SQLException) { } catch (e: SQLException) {
e.printStackTrace() e.printStackTrace()
@ -165,11 +182,4 @@ class MqttService(serverurl: String, port: String) {
else -> 0 else -> 0
} }
} }
/**
* receives connection object and initial connection to db
*/
private fun connectToDb() {
db = JDBC.getInstance()
}
} }

View File

@ -7,7 +7,6 @@ import com.wasteinformationserver.basicutils.Storage
import com.wasteinformationserver.db.JDBC import com.wasteinformationserver.db.JDBC
import com.wasteinformationserver.website.HttpTools.Companion.stringToMD5 import com.wasteinformationserver.website.HttpTools.Companion.stringToMD5
import com.wasteinformationserver.website.basicrequest.PostRequest import com.wasteinformationserver.website.basicrequest.PostRequest
import java.io.IOException
import java.sql.SQLException import java.sql.SQLException
import java.util.* import java.util.*
@ -43,7 +42,7 @@ class LoginRequest : PostRequest() {
s.last() s.last()
if (s.row == 1) { if (s.row == 1) {
//success //success
if (StringToMD5(password!!) == s.getString("password")) { if (stringToMD5(password!!) == s.getString("password")) {
debug("login success") debug("login success")
LoginState.getObject().logIn() LoginState.getObject().logIn()
LoginState.getObject().setAccountData(username, s.getString("firstName"), s.getString("secondName"), s.getString("email"), s.getInt("permission")) LoginState.getObject().setAccountData(username, s.getString("firstName"), s.getString("secondName"), s.getString("email"), s.getInt("permission"))

87
src/resources/db.sql Normal file
View File

@ -0,0 +1,87 @@
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT = @@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS = @@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION = @@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
CREATE TABLE cities
(
id int(11) NOT NULL,
userid int(11) NOT NULL,
name varchar(256) NOT NULL,
wastetype varchar(64) NOT NULL,
zone int(11) NOT NULL
) ENGINE = InnoDB
DEFAULT CHARSET = utf8;
CREATE TABLE devices
(
DeviceID int(11) NOT NULL,
CityID int(11) NOT NULL DEFAULT '-1',
DeviceName varchar(15) DEFAULT NULL,
DeviceLocation varchar(15) DEFAULT NULL
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE device_city
(
DeviceID int(11) NOT NULL,
CityID int(11) NOT NULL
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
CREATE TABLE pickupdates
(
id int(11) NOT NULL,
citywastezoneid int(11) NOT NULL,
pickupdate date NOT NULL
) ENGINE = InnoDB
DEFAULT CHARSET = utf8;
CREATE TABLE `user`
(
id int(11) NOT NULL,
username varchar(150) NOT NULL,
firstName varchar(32) NOT NULL,
secondName varchar(32) NOT NULL,
password varchar(32) NOT NULL,
permission int(11) NOT NULL DEFAULT '0',
email varchar(64) NOT NULL,
logindate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE = InnoDB
DEFAULT CHARSET = utf8;
ALTER TABLE cities
ADD PRIMARY KEY (id);
ALTER TABLE devices
ADD PRIMARY KEY (DeviceID);
ALTER TABLE pickupdates
ADD PRIMARY KEY (id),
ADD KEY citywastezoneid (citywastezoneid);
ALTER TABLE `user`
ADD PRIMARY KEY (id);
ALTER TABLE cities
MODIFY id int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 143;
ALTER TABLE pickupdates
MODIFY id int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 67;
ALTER TABLE `user`
MODIFY id int(11) NOT NULL AUTO_INCREMENT,
AUTO_INCREMENT = 17;
ALTER TABLE pickupdates
ADD CONSTRAINT pickupdates_ibfk_1 FOREIGN KEY (citywastezoneid) REFERENCES cities (id);
/*!40101 SET CHARACTER_SET_CLIENT = @OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS = @OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION = @OLD_COLLATION_CONNECTION */;

View File

@ -269,7 +269,7 @@ class Dashboard {
} }
$(".delbtn").click(function (event) { $(".delbtn").click(function (event) {
var id = event.target.getAttribute("dataid"); const id = event.target.getAttribute("dataid");
console.log("clicked btn data " + id); console.log("clicked btn data " + id);
$.post('/senddata/wastedata', 'action=deletecity&id=' + id, function (data) { $.post('/senddata/wastedata', 'action=deletecity&id=' + id, function (data) {
console.log(data); console.log(data);
@ -283,12 +283,12 @@ class Dashboard {
console.log('Popup closed. ') console.log('Popup closed. ')
}); });
reloadtable(); _this.reloadtable();
} else if (data.status === "dependenciesnotdeleted") { } else if (data.status === "dependenciesnotdeleted") {
Swal.fire({ Swal.fire({
icon: "warning", icon: "warning",
title: 'This city is a dependency of a date', title: 'This city is a dependency of a date',
html: 'Do you want do delete it anyway with all dependencies?', html: 'Please delete all dependencies first!',
}).then((result) => { }).then((result) => {
console.log('Popup closed. ') console.log('Popup closed. ')
@ -353,7 +353,7 @@ class Dashboard {
console.log('Popup closed. ') console.log('Popup closed. ')
}); });
reloadDateTable(); _this.reloadDateTable();
} else if (data.status == "dependenciesnotdeleted") { } else if (data.status == "dependenciesnotdeleted") {
Swal.fire({ Swal.fire({
icon: "warning", icon: "warning",

View File

@ -3,19 +3,17 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Login Page</title> <title>Login Page</title>
<!--Made with love by Mutiullah Samim -->
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="lib/bootstrap.min.css"> <link rel="stylesheet" href="lib/bootstrap.min.css">
<!-- jQuery library --> <!-- jQuery library -->
<script src="lib/jquery.min.js"></script> <script src="lib/AdminLTE/plugins/jquery/jquery.min.js"></script>
<!-- Popper JS --> <!-- Popper JS -->
<script src="lib/popper.min.js"></script> <script src="lib/popper.min.js"></script>
<!-- Latest compiled JavaScript --> <!-- Latest compiled JavaScript -->
<script src="lib/bootstrap.min.js"></script> <script src="lib/AdminLTE/plugins/bootstrap/js/bootstrap.min.js"></script>
<!--Fontawesome CDN--> <!--Fontawesome CDN-->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">