new ticket page update
This commit is contained in:
@ -0,0 +1,25 @@
|
||||
package com.wasteinformationserver.website.datarequests;
|
||||
|
||||
import com.wasteinformationserver.basicutils.Log;
|
||||
import com.wasteinformationserver.website.basicrequest.PostRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CheckLoginState extends PostRequest {
|
||||
@Override
|
||||
public String request(HashMap<String, String> params) {
|
||||
Log.message("checking login state");
|
||||
if ((params.get("action")).equals("getloginstate")){
|
||||
if (LoginState.getObject().isLoggedIn()){
|
||||
return "{\"loggedin\":true, \"username\":\""+LoginState.getObject().getUsername()+"\"}";
|
||||
}else {
|
||||
return "{\"loggedin\":false}";
|
||||
}
|
||||
}else if ((params.get("action")).equals("logout")){
|
||||
Log.debug("logging out");
|
||||
LoginState.getObject().logOut();
|
||||
return "{\"loggedin\":false}";
|
||||
}
|
||||
return "{\"loggedin\":false}";
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.wasteinformationserver.website.datarequests;
|
||||
|
||||
import com.wasteinformationserver.basicutils.Log;
|
||||
import com.wasteinformationserver.db.JDCB;
|
||||
import com.wasteinformationserver.website.basicrequest.PostRequest;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DataRequest extends PostRequest {
|
||||
@Override
|
||||
public String request(HashMap<String, String> params) {
|
||||
switch (params.get("action")){
|
||||
case "senddata":
|
||||
Log.debug(params.toString());
|
||||
|
||||
// check if wastezone and wasteregion already exists
|
||||
|
||||
JDCB jdcb = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
|
||||
|
||||
ResultSet set = jdcb.executeQuery("select * from cities where name='"+params.get("wasteregion")+"'");
|
||||
try {
|
||||
System.out.println(set.getFetchSize());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// jdcb.executeUpdate("insert into ");
|
||||
|
||||
// TODO: 11.10.19 store data in database
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.wasteinformationserver.website.datarequests;
|
||||
|
||||
import com.wasteinformationserver.basicutils.Log;
|
||||
import com.wasteinformationserver.db.JDCB;
|
||||
import com.wasteinformationserver.website.HttpTools;
|
||||
import com.wasteinformationserver.website.basicrequest.PostRequest;
|
||||
|
||||
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) {
|
||||
|
||||
String password = params.get("password");
|
||||
String username = params.get("username");
|
||||
|
||||
ResultSet s = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'");
|
||||
|
||||
String response = "{\"accept\": false}";
|
||||
try {
|
||||
s.last();
|
||||
if (s.getRow() == 1) {
|
||||
//success
|
||||
if (HttpTools.StringToMD5(password).equals(s.getString("password"))) {
|
||||
Log.debug("login success");
|
||||
LoginState.getObject().logIn();
|
||||
LoginState.getObject().setAccountData(username,"","","");
|
||||
response = "{\"accept\": true}";
|
||||
} else {
|
||||
Log.debug("wrong password");
|
||||
}
|
||||
} else if (s.getRow() == 0) {
|
||||
//user not found
|
||||
Log.debug("user not found");
|
||||
} else {
|
||||
//internal error two users with same name...?
|
||||
}
|
||||
Log.debug("rowcount: " + s.getRow());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.wasteinformationserver.website.datarequests;
|
||||
|
||||
public class LoginState {
|
||||
private LoginState() {}
|
||||
|
||||
private static LoginState mythis=new LoginState();
|
||||
|
||||
public static LoginState getObject(){
|
||||
return mythis;
|
||||
}
|
||||
|
||||
String username;
|
||||
String firstname;
|
||||
String lastname;
|
||||
String email;
|
||||
|
||||
boolean loggedin = false;
|
||||
|
||||
public void logIn(){
|
||||
loggedin=true;
|
||||
}
|
||||
|
||||
public void logOut(){
|
||||
loggedin=false;
|
||||
}
|
||||
|
||||
public void setAccountData(String username, String firstname, String lastname, String email){
|
||||
this.username=username;
|
||||
this.firstname=firstname;
|
||||
this.lastname=lastname;
|
||||
this.email=email;
|
||||
}
|
||||
|
||||
public boolean isLoggedIn(){
|
||||
return loggedin;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.wasteinformationserver.website.datarequests;
|
||||
|
||||
import com.wasteinformationserver.basicutils.Log;
|
||||
import com.wasteinformationserver.db.JDCB;
|
||||
import com.wasteinformationserver.website.HttpTools;
|
||||
import com.wasteinformationserver.website.basicrequest.PostRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RegisterRequest extends PostRequest {
|
||||
@Override
|
||||
public String request(HashMap<String, String> params) {
|
||||
Log.debug(params.toString());
|
||||
|
||||
String passhash = HttpTools.StringToMD5(params.get("password"));
|
||||
|
||||
JDCB myjd = new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation");
|
||||
int s = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('"+params.get("username")+"', '"+params.get("firstname")+"', '"+params.get("lastname")+"', '"+passhash+"', '"+params.get("email")+"', current_timestamp());");
|
||||
|
||||
// TODO: 27.09.19 detect if register process was successful and reply right json
|
||||
return "{\"accept\": true}";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user