Bungeecord support added x20
This commit is contained in:
parent
cdd9412ea2
commit
9977531e7a
@ -62,6 +62,8 @@ public class SaltNic extends NanoHTTPD {
|
||||
return handleHasJoinedRequest(session);
|
||||
} else if (uri.startsWith("/api/profile/") && method == Method.GET) {
|
||||
return handleProfileRequest(session, uri);
|
||||
} else if (uri.startsWith("/api/login") && method == Method.POST) {
|
||||
return handleLoginRequest(session);
|
||||
} else if (uri.startsWith("/api/register") && method == Method.POST) {
|
||||
return handleProfileRegistration(session);
|
||||
} else if (Method.POST == method && "/api/set_model".equals(uri)) {
|
||||
@ -308,6 +310,40 @@ public class SaltNic extends NanoHTTPD {
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleLoginRequest(IHTTPSession session) {
|
||||
try {
|
||||
Map<String, String> files = new HashMap<>();
|
||||
session.parseBody(files);
|
||||
SignUpRequest loginRequest = JsonIterator.deserialize(files.get("postData"), SignUpRequest.class);
|
||||
|
||||
if (loginRequest == null) {
|
||||
return newFixedLengthResponse(Response.Status.BAD_REQUEST, "text/plain", "Invalid JSON format");
|
||||
}
|
||||
|
||||
String username = loginRequest.getUsername();
|
||||
String password = loginRequest.getPassword();
|
||||
|
||||
if (username == null || password == null) {
|
||||
return newFixedLengthResponse(Response.Status.BAD_REQUEST, "text/plain", "Missing username or password");
|
||||
}
|
||||
|
||||
if( this.storage.getUserPasswordByName(username) == null ) {
|
||||
return newFixedLengthResponse(Response.Status.CONFLICT, "text/plain", "User doesn't exist");
|
||||
}
|
||||
|
||||
boolean validSession = PasswordHasher.checkPassword(password, this.storage.getUserPasswordByName(username));
|
||||
|
||||
if (validSession) {
|
||||
return newFixedLengthResponse(Response.Status.OK, "application/json", "{}");
|
||||
} else {
|
||||
return invalidSession;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Error while processing join request from client: " + e.getMessage());
|
||||
return invalidSession;
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleJoinRequest(IHTTPSession session) {
|
||||
try {
|
||||
Map<String, String> files = new HashMap<>();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.alterdekim.xcraft.auth.database;
|
||||
|
||||
import com.alterdekim.xcraft.auth.UserId;
|
||||
import com.jsoniter.JsonIterator;
|
||||
import com.jsoniter.output.JsonStream;
|
||||
import org.mapdb.DB;
|
||||
@ -7,6 +8,7 @@ import org.mapdb.DBMaker;
|
||||
import org.mapdb.Serializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class UserStorage {
|
||||
@ -42,6 +44,10 @@ public class UserStorage {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUserPasswordByName(String username) throws NoSuchAlgorithmException {
|
||||
return getUserPassword(UserId.generateUserId(username));
|
||||
}
|
||||
|
||||
public void close() {
|
||||
db.close();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user