login request setup all fields provided by db
updated loginrequest to kotlin
This commit is contained in:
parent
22a9a5b612
commit
daf440e36b
@ -1,3 +1,4 @@
|
||||
@file:JvmName("Main")
|
||||
package com.wasteinformationserver
|
||||
|
||||
import com.wasteinformationserver.basicutils.Info
|
||||
|
@ -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
|
||||
|
@ -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<String, String> 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;
|
||||
}
|
||||
}
|
@ -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, String>): 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
|
||||
}
|
||||
}
|
@ -355,8 +355,6 @@ $(document).ready(function () {
|
||||
datetable = $("#table-pickupdates").DataTable({
|
||||
"order": [[3, "asc"]]
|
||||
});
|
||||
|
||||
//todo picupdates-tablebody
|
||||
}, "json");
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user