From daf440e36b4ac4156d0b09d11db01131eeff3679 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Fri, 31 Jan 2020 10:28:39 +0100 Subject: [PATCH] login request setup all fields provided by db updated loginrequest to kotlin --- src/java/com/wasteinformationserver/Main.kt | 1 + .../mqtt/MqttService.kt | 2 +- .../datarequests/login/LoginRequest.java | 64 ------------------- .../datarequests/login/LoginRequest.kt | 55 ++++++++++++++++ src/resources/wwwroot/js/dashboard.js | 2 - 5 files changed, 57 insertions(+), 67 deletions(-) delete mode 100644 src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java create mode 100644 src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.kt diff --git a/src/java/com/wasteinformationserver/Main.kt b/src/java/com/wasteinformationserver/Main.kt index b741f9c..2a4d57b 100644 --- a/src/java/com/wasteinformationserver/Main.kt +++ b/src/java/com/wasteinformationserver/Main.kt @@ -1,3 +1,4 @@ +@file:JvmName("Main") package com.wasteinformationserver import com.wasteinformationserver.basicutils.Info diff --git a/src/java/com/wasteinformationserver/mqtt/MqttService.kt b/src/java/com/wasteinformationserver/mqtt/MqttService.kt index ab4cc76..da793c1 100644 --- a/src/java/com/wasteinformationserver/mqtt/MqttService.kt +++ b/src/java/com/wasteinformationserver/mqtt/MqttService.kt @@ -14,7 +14,7 @@ import java.util.* /** * Mqtt Service to receive and send back messages to the Hardware - * todo + * check values from db send right feedback to hardware. * * @author Lukas Heiligenbrunner * @author Gregor Dutzler diff --git a/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java b/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java deleted file mode 100644 index 6977d75..0000000 --- a/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.wasteinformationserver.website.datarequests.login; - -import com.wasteinformationserver.basicutils.Log; -import com.wasteinformationserver.db.JDBC; -import com.wasteinformationserver.website.HttpTools; -import com.wasteinformationserver.website.basicrequest.PostRequest; - -import java.io.IOException; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; - -/** - * request handler of new login request of user - * - checks the truth of username and password - * - replies right error messages or the success login - */ -public class LoginRequest extends PostRequest { - @Override - public String request(HashMap params) { - - Log.Log.message("new login request"); - - String password = params.get("password"); - String username = params.get("username"); - - JDBC jdbc; - try { - jdbc = JDBC.getInstance(); - } catch (IOException e) { - Log.Log.error("no connection to db"); - return "{\"status\" : \"nodbconn\"}"; - } - - ResultSet s = jdbc.executeQuery("select * from user where username ='" + username + "'"); - - //new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'"); - Log.Log.debug("successfully logged in to db"); - String response = "{\"accept\": false}"; - try { - s.last(); - if (s.getRow() == 1) { - //success - if (HttpTools.Companion.StringToMD5(password).equals(s.getString("password"))) { - Log.Log.debug("login success"); - LoginState.getObject().logIn(); - LoginState.getObject().setAccountData(username, "", "", "", s.getInt("permission")); // TODO: 06.12.19 - response = "{\"accept\": true}"; - } else { - Log.Log.debug("wrong password"); - } - } else if (s.getRow() == 0) { - //user not found - Log.Log.debug("user not found"); - } else { - //internal error two users with same name...? - } - Log.Log.debug("rowcount: " + s.getRow()); - } catch (SQLException e) { - e.printStackTrace(); - } - return response; - } -} diff --git a/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.kt b/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.kt new file mode 100644 index 0000000..47c1b27 --- /dev/null +++ b/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.kt @@ -0,0 +1,55 @@ +package com.wasteinformationserver.website.datarequests.login + +import com.wasteinformationserver.basicutils.Log.Log.debug +import com.wasteinformationserver.basicutils.Log.Log.error +import com.wasteinformationserver.basicutils.Log.Log.message +import com.wasteinformationserver.db.JDBC +import com.wasteinformationserver.website.HttpTools.Companion.StringToMD5 +import com.wasteinformationserver.website.basicrequest.PostRequest +import java.io.IOException +import java.sql.SQLException +import java.util.* + +/** + * request handler of new login request of user + * - checks the truth of username and password + * - replies right error messages or the success login + */ +class LoginRequest : PostRequest() { + override fun request(params: HashMap): String { + message("new login request") + val password = params["password"] + val username = params["username"] + val jdbc: JDBC = try { + JDBC.getInstance() + } catch (e: IOException) { + error("no connection to db") + return "{\"status\" : \"nodbconn\"}" + } + val s = jdbc.executeQuery("select * from user where username ='$username'") + + debug("successfully logged in to db") + var response = "{\"accept\": false}" + try { + s.last() + if (s.row == 1) { //success + if (StringToMD5(password!!) == s.getString("password")) { + debug("login success") + LoginState.getObject().logIn() + LoginState.getObject().setAccountData(username, s.getString("firstName"), s.getString("secondName"), s.getString("email"), s.getInt("permission")) + response = "{\"accept\": true}" + } else { + debug("wrong password") + } + } else if (s.row == 0) { //user not found + debug("user not found") + } else { //internal error two users with same name...? + error("there seem to be two users with same name") + } + debug("rowcount: " + s.row) + } catch (e: SQLException) { + e.printStackTrace() + } + return response + } +} \ No newline at end of file diff --git a/src/resources/wwwroot/js/dashboard.js b/src/resources/wwwroot/js/dashboard.js index d705a24..21d2fe7 100644 --- a/src/resources/wwwroot/js/dashboard.js +++ b/src/resources/wwwroot/js/dashboard.js @@ -355,8 +355,6 @@ $(document).ready(function () { datetable = $("#table-pickupdates").DataTable({ "order": [[3, "asc"]] }); - - //todo picupdates-tablebody }, "json"); } });