add configuration error popups

This commit is contained in:
lukas-heiligenbrunner
2020-04-15 15:49:04 +02:00
parent b9058dcdba
commit cf9069e489
4 changed files with 50 additions and 43 deletions

View File

@ -7,7 +7,7 @@ import java.io.IOException
import java.util.*
/**
* Storeage of user information
* Storage of user information
* * database infos
* * mqtt infos
*
@ -99,6 +99,7 @@ class Storage {
/**
* check if all needed properties are set up correctly
* todo real check if connections can be established
*/
fun isEveryThingDefined(): Boolean {
return (mqttServer != "" &&

View File

@ -23,14 +23,8 @@ class MainPage : HttpHandler {
debug("looking for: $path")
if (path.contains(".html")) {
// check if db and mqtt is configured properly
// todo check real connection / not only if filled in
if (!Storage.getInstance().isEveryThingDefined()) {
sendPage("/config.html", t)
return
}
if (LoginState.getObject().isLoggedIn || path == "/register.html" || path == "/index.html") { //pass only register page
// if not logged in allow only register and index page!
if (LoginState.getObject().isLoggedIn || path == "/register.html" || path == "/index.html") {
sendPage(path, t)
}
else {
@ -38,7 +32,8 @@ class MainPage : HttpHandler {
sendPage("/index.html", t)
}
}
else { //only detect login state on html pages
else {
//only detect login state on html pages
sendPage(path, t)
}
}

View File

@ -3,6 +3,7 @@ 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.basicutils.Storage
import com.wasteinformationserver.db.JDBC
import com.wasteinformationserver.website.HttpTools.Companion.StringToMD5
import com.wasteinformationserver.website.basicrequest.PostRequest
@ -11,9 +12,11 @@ import java.sql.SQLException
import java.util.*
/**
* request handler of new login request of user
* request handler of new user login requests
* - checks the truth of username and password
* - replies right error messages or the success login
*
* @author Lukas Heiligenbrunner
*/
class LoginRequest : PostRequest() {
override fun request(params: HashMap<String, String>): String {
@ -26,24 +29,36 @@ class LoginRequest : PostRequest() {
error("no connection to db")
return "{\"status\" : \"nodbconn\"}"
}
if (!Storage.getInstance().isEveryThingDefined()) {
error("config not configured correctly")
return "{\"status\" : \"conferror\"}"
}
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 (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 {
}
else {
debug("wrong password")
}
} else if (s.row == 0) { //user not found
}
else if (s.row == 0) {
//user not found
debug("user not found")
} else { //internal error two users with same name...?
}
else {
//internal error two users with same name...?
error("there seem to be two users with same name")
}
debug("rowcount: " + s.row)