Adapted authkey check to new website return values and prepared for future username display

This commit is contained in:
CrushedPixel
2015-05-15 02:38:06 +02:00
parent bf03e2e05b
commit 38b900a33b
4 changed files with 30 additions and 13 deletions

View File

@@ -39,14 +39,14 @@ public class ApiClient {
return auth;
}
public boolean checkAuthkey(String auth) {
public AuthConfirmation checkAuthkey(String auth) {
try {
QueryBuilder builder = new QueryBuilder(ApiMethods.check_authkey);
builder.put("auth", auth);
Success succ = invokeAndReturn(builder, Success.class);
return succ.isSuccess();
AuthConfirmation conf = invokeAndReturn(builder, AuthConfirmation.class);
return conf;
} catch(Exception e) {
return false;
return null;
}
}

View File

@@ -0,0 +1,10 @@
package eu.crushedpixel.replaymod.api.client.holders;
public class AuthConfirmation {
private String username;
private int id;
public String getUsername() {
return username;
}
}

View File

@@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.online.authentication;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.api.client.ApiClient;
import eu.crushedpixel.replaymod.api.client.ApiException;
import eu.crushedpixel.replaymod.api.client.holders.AuthConfirmation;
import eu.crushedpixel.replaymod.api.client.holders.AuthKey;
import net.minecraftforge.common.config.Property;
@@ -17,6 +18,7 @@ public class AuthenticationHandler {
private static final ApiClient apiClient = new ApiClient();
private static String authkey = null;
private static String username = null;
public static boolean isAuthenticated() {
return authkey != null;
@@ -25,18 +27,20 @@ public class AuthenticationHandler {
public static String getKey() {
return authkey;
}
public static String getUsername() { return username; }
public static boolean hasDonated(String uuid) throws IOException, ApiException {
return apiClient.hasDonated(uuid);
}
public static void register(String username, String mail, String password) throws IOException, ApiException {
AuthKey auth = apiClient.register(username, mail, password);
public static void register(String usrname, String mail, String password) throws IOException, ApiException {
AuthKey auth = apiClient.register(usrname, mail, password);
username = usrname;
authkey = auth.getAuthkey();
saveAuthkey(authkey);
}
public static boolean loadAuthkeyFromConfig() {
public static void loadAuthkeyFromConfig() {
Property p = ReplayMod.instance.config.get("authkey", "authkey", "null");
String key = null;
@@ -45,20 +49,21 @@ public class AuthenticationHandler {
}
if(key != null) {
boolean succ = apiClient.checkAuthkey(key);
if(succ) {
AuthConfirmation conf = apiClient.checkAuthkey(key);
if(conf != null) {
authkey = key;
username = conf.getUsername();
} else {
saveAuthkey("null");
username = null;
}
return succ;
}
return false;
}
public static int authenticate(String username, String password) {
public static int authenticate(String usrname, String password) {
try {
authkey = ReplayMod.apiClient.getLogin(username, password).getAuthkey();
authkey = ReplayMod.apiClient.getLogin(usrname, password).getAuthkey();
username = usrname;
saveAuthkey(authkey);
return SUCCESS;
} catch(ApiException e) {
@@ -72,6 +77,7 @@ public class AuthenticationHandler {
try {
ReplayMod.apiClient.logout(authkey);
authkey = null;
username = null;
saveAuthkey("null");
return SUCCESS;
} catch(ApiException e) {

View File

@@ -22,6 +22,7 @@ replaymod.api.zippingerror=An error occured while zipping the language files
replaymod.api.usernameexists=This username is already taken
replaymod.api.mailexists=This Email address is already linked to an account
replaymod.api.invalidmail=Invalid Email Address
replaymod.api.nopermissions=You don't have permission to do this
#All of the chat messages