Fixing Jules'problem
This commit is contained in:
parent
987e2648c2
commit
4993cc33ee
4 changed files with 14 additions and 16 deletions
|
@ -4,5 +4,6 @@
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
<classpathentry exported="true" kind="lib" path="json-simple-1.1.1.jar"/>
|
<classpathentry exported="true" kind="lib" path="json-simple-1.1.1.jar"/>
|
||||||
<classpathentry exported="true" kind="lib" path="mysql-connector-java-8.0.28.jar"/>
|
<classpathentry exported="true" kind="lib" path="mysql-connector-java-8.0.28.jar"/>
|
||||||
|
<classpathentry exported="true" kind="lib" path="password4j-1.6.3.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -12,7 +12,7 @@ import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DatabaseRepo {
|
public class DatabaseRepository {
|
||||||
private static final String SPECIFIC_PUZZLE_QUERY = "SELECT * FROM puzzles WHERE id_puzzle = ?";
|
private static final String SPECIFIC_PUZZLE_QUERY = "SELECT * FROM puzzles WHERE id_puzzle = ?";
|
||||||
private static final String SPECIFIC_CHAPTER_QUERY = "SELECT * FROM chapters WHERE id_chapter = ?";
|
private static final String SPECIFIC_CHAPTER_QUERY = "SELECT * FROM chapters WHERE id_chapter = ?";
|
||||||
private static final String PUZZLES_IN_CHAPTER_QUERY = "SELECT * FROM puzzles WHERE fk_chapter = ?";
|
private static final String PUZZLES_IN_CHAPTER_QUERY = "SELECT * FROM puzzles WHERE fk_chapter = ?";
|
||||||
|
|
|
@ -13,9 +13,9 @@ import be.jeffcheasey88.peeratcode.webserver.Response;
|
||||||
|
|
||||||
public class Login implements Response {
|
public class Login implements Response {
|
||||||
|
|
||||||
private final DatabaseRepo databaseRepo;
|
private final DatabaseRepository databaseRepo;
|
||||||
|
|
||||||
public Login(DatabaseRepo databaseRepo) {
|
public Login(DatabaseRepository databaseRepo) {
|
||||||
this.databaseRepo = databaseRepo;
|
this.databaseRepo = databaseRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,13 +26,12 @@ public class Login implements Response {
|
||||||
if (informations != null) {
|
if (informations != null) {
|
||||||
String pseudo = (String) informations.get("pseudo");
|
String pseudo = (String) informations.get("pseudo");
|
||||||
String password = (String) informations.get("passwd");
|
String password = (String) informations.get("passwd");
|
||||||
boolean wellLogged = databaseRepo.login(pseudo, password);
|
if (databaseRepo.login(pseudo, password)) {
|
||||||
if (!wellLogged) {
|
|
||||||
HttpUtil.responseHeaders(writer, 403, "Access-Control-Allow-Origin: *");
|
|
||||||
} else {
|
|
||||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HttpUtil.responseHeaders(writer, 403, "Access-Control-Allow-Origin: *");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,9 +13,9 @@ import be.jeffcheasey88.peeratcode.webserver.Response;
|
||||||
|
|
||||||
public class Register implements Response {
|
public class Register implements Response {
|
||||||
|
|
||||||
private final DatabaseRepo databaseRepo;
|
private final DatabaseRepository databaseRepo;
|
||||||
|
|
||||||
public Register(DatabaseRepo databaseRepo) {
|
public Register(DatabaseRepository databaseRepo) {
|
||||||
this.databaseRepo = databaseRepo;
|
this.databaseRepo = databaseRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,22 +44,20 @@ public class Register implements Response {
|
||||||
boolean pseudoAvailable = databaseRepo.checkPseudoAvailability(pseudo);
|
boolean pseudoAvailable = databaseRepo.checkPseudoAvailability(pseudo);
|
||||||
boolean emailAvailable = databaseRepo.checkEmailAvailability(email);
|
boolean emailAvailable = databaseRepo.checkEmailAvailability(email);
|
||||||
if (pseudoAvailable && emailAvailable) {
|
if (pseudoAvailable && emailAvailable) {
|
||||||
boolean wellRegistered = databaseRepo.register(pseudo, email, password, firstname, lastname, description, group, avatar);
|
if (databaseRepo.register(pseudo, email, password, firstname, lastname, description, group, avatar)){
|
||||||
if (!wellRegistered) {
|
|
||||||
HttpUtil.responseHeaders(writer, 400, "Access-Control-Allow-Origin: *");
|
|
||||||
writer.write("Error while registering");
|
|
||||||
} else {
|
|
||||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
||||||
writer.write("OK");
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HttpUtil.responseHeaders(writer, 200, "Access-Control-Allow-Origin: *");
|
HttpUtil.responseHeaders(writer, 403, "Access-Control-Allow-Origin: *");
|
||||||
JSONObject error = new JSONObject();
|
JSONObject error = new JSONObject();
|
||||||
error.put("username_valid", pseudoAvailable);
|
error.put("username_valid", pseudoAvailable);
|
||||||
error.put("email_valid", emailAvailable);
|
error.put("email_valid", emailAvailable);
|
||||||
writer.write(error.toJSONString());
|
writer.write(error.toJSONString());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HttpUtil.responseHeaders(writer, 403, "Access-Control-Allow-Origin: *");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue