2019-11-15 11:23:51 +01:00
|
|
|
package com.wasteinformationserver.website.datarequests.login;
|
2019-09-27 10:58:13 +02:00
|
|
|
|
2019-10-11 16:16:28 +02:00
|
|
|
import com.wasteinformationserver.basicutils.Log;
|
2019-11-08 10:42:22 +01:00
|
|
|
import com.wasteinformationserver.db.JDCB;
|
|
|
|
import com.wasteinformationserver.website.HttpTools;
|
|
|
|
import com.wasteinformationserver.website.basicrequest.PostRequest;
|
2019-09-27 10:58:13 +02:00
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
public class LoginRequest extends PostRequest {
|
|
|
|
@Override
|
|
|
|
public String request(HashMap<String, String> params) {
|
|
|
|
|
2019-11-15 11:23:51 +01:00
|
|
|
Log.message("new login request");
|
|
|
|
|
2019-09-27 10:58:13 +02:00
|
|
|
String password = params.get("password");
|
|
|
|
String username = params.get("username");
|
|
|
|
|
2019-11-08 10:42:22 +01:00
|
|
|
ResultSet s = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'");
|
2019-09-27 10:58:13 +02:00
|
|
|
|
|
|
|
String response = "{\"accept\": false}";
|
|
|
|
try {
|
|
|
|
s.last();
|
|
|
|
if (s.getRow() == 1) {
|
|
|
|
//success
|
|
|
|
if (HttpTools.StringToMD5(password).equals(s.getString("password"))) {
|
2019-10-11 16:16:28 +02:00
|
|
|
Log.debug("login success");
|
2019-09-27 16:37:59 +02:00
|
|
|
LoginState.getObject().logIn();
|
|
|
|
LoginState.getObject().setAccountData(username,"","","");
|
2019-09-27 10:58:13 +02:00
|
|
|
response = "{\"accept\": true}";
|
|
|
|
} else {
|
2019-10-11 16:16:28 +02:00
|
|
|
Log.debug("wrong password");
|
2019-09-27 10:58:13 +02:00
|
|
|
}
|
|
|
|
} else if (s.getRow() == 0) {
|
|
|
|
//user not found
|
2019-10-11 16:16:28 +02:00
|
|
|
Log.debug("user not found");
|
2019-09-27 10:58:13 +02:00
|
|
|
} else {
|
|
|
|
//internal error two users with same name...?
|
|
|
|
}
|
2019-10-11 16:16:28 +02:00
|
|
|
Log.debug("rowcount: " + s.getRow());
|
2019-09-27 10:58:13 +02:00
|
|
|
} catch (SQLException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|