Updated /register route with the new field in the database, updated DatabaseRepo for the same reason
This commit is contained in:
parent
209b0eeeb4
commit
1907173db5
2 changed files with 13 additions and 5 deletions
|
@ -19,7 +19,7 @@ public class DatabaseRepo {
|
||||||
private static final String ALL_CHAPTERS_QUERY = "SELECT * FROM chapter";
|
private static final String ALL_CHAPTERS_QUERY = "SELECT * FROM chapter";
|
||||||
private static final String CHECK_PSEUDO_AVAILABLE_QUERY = "SELECT * FROM user WHERE pseudo = ?";
|
private static final String CHECK_PSEUDO_AVAILABLE_QUERY = "SELECT * FROM user WHERE pseudo = ?";
|
||||||
private static final String CHECK_EMAIL_AVAILABLE_QUERY = "SELECT * FROM user WHERE email = ?";
|
private static final String CHECK_EMAIL_AVAILABLE_QUERY = "SELECT * FROM user WHERE email = ?";
|
||||||
private static final String REGISTER_QUERY = "INSERT INTO user (pseudo, email, passwd, firstname, lastname, description, `group`, avatar) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
private static final String REGISTER_QUERY = "INSERT INTO user (pseudo, email, passwd, firstname, lastname, description, sgroup, avatar) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
private static final String PASSWORD_FOR_EMAIL_QUERY = "SELECT passwd FROM user WHERE pseudo = ?";
|
private static final String PASSWORD_FOR_EMAIL_QUERY = "SELECT passwd FROM user WHERE pseudo = ?";
|
||||||
private final Connection con;
|
private final Connection con;
|
||||||
|
|
||||||
|
@ -152,11 +152,11 @@ public class DatabaseRepo {
|
||||||
* @param firstname The firstname of the user
|
* @param firstname The firstname of the user
|
||||||
* @param lastname The lastname of the user
|
* @param lastname The lastname of the user
|
||||||
* @param description The description of the user
|
* @param description The description of the user
|
||||||
* @param group The group of the user
|
* @param sgroup The group of the user
|
||||||
* @param avatar The avatar of the user
|
* @param avatar The avatar of the user
|
||||||
* @return True if the user was registered, false if an error occurred
|
* @return True if the user was registered, false if an error occurred
|
||||||
*/
|
*/
|
||||||
public boolean register(String pseudo, String email, String password, String firstname, String lastname, String description, String group, String avatar) {
|
public boolean register(String pseudo, String email, String password, String firstname, String lastname, String description, String sgroup, String avatar) {
|
||||||
Hash hash = Password.hash(password).withArgon2();
|
Hash hash = Password.hash(password).withArgon2();
|
||||||
try {
|
try {
|
||||||
PreparedStatement statement = con.prepareStatement(REGISTER_QUERY);
|
PreparedStatement statement = con.prepareStatement(REGISTER_QUERY);
|
||||||
|
@ -166,7 +166,7 @@ public class DatabaseRepo {
|
||||||
statement.setString(4, firstname);
|
statement.setString(4, firstname);
|
||||||
statement.setString(5, lastname);
|
statement.setString(5, lastname);
|
||||||
statement.setString(6, description);
|
statement.setString(6, description);
|
||||||
statement.setString(7, group);
|
statement.setString(7, sgroup);
|
||||||
statement.setString(8, avatar);
|
statement.setString(8, avatar);
|
||||||
return statement.executeUpdate() == 1;
|
return statement.executeUpdate() == 1;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
|
@ -23,13 +23,21 @@ public class Register implements Response {
|
||||||
HttpUtil.skipHeaders(reader);
|
HttpUtil.skipHeaders(reader);
|
||||||
JSONObject informations = (JSONObject) HttpUtil.readJson(reader);
|
JSONObject informations = (JSONObject) HttpUtil.readJson(reader);
|
||||||
if (informations != null) {
|
if (informations != null) {
|
||||||
|
boolean allFieldsFilled = informations.containsKey("pseudo") && informations.containsKey("email")
|
||||||
|
&& informations.containsKey("passwd") && informations.containsKey("firstname")
|
||||||
|
&& informations.containsKey("lastname") && informations.containsKey("description")
|
||||||
|
&& informations.containsKey("sgroup") && informations.containsKey("avatar");
|
||||||
|
if (!allFieldsFilled) {
|
||||||
|
HttpUtil.responseHeaders(writer, 403, "Access-Control-Allow-Origin: *");
|
||||||
|
return;
|
||||||
|
}
|
||||||
String pseudo = (String) informations.get("pseudo");
|
String pseudo = (String) informations.get("pseudo");
|
||||||
String email = (String) informations.get("email");
|
String email = (String) informations.get("email");
|
||||||
String password = (String) informations.get("passwd");
|
String password = (String) informations.get("passwd");
|
||||||
String firstname = (String) informations.get("firstname");
|
String firstname = (String) informations.get("firstname");
|
||||||
String lastname = (String) informations.get("lastname");
|
String lastname = (String) informations.get("lastname");
|
||||||
String description = (String) informations.get("description");
|
String description = (String) informations.get("description");
|
||||||
String group = (String) informations.get("group");
|
String group = (String) informations.get("sgroup");
|
||||||
String avatar = (String) informations.get("avatar");
|
String avatar = (String) informations.get("avatar");
|
||||||
|
|
||||||
boolean pseudoAvailable = databaseRepo.checkPseudoAvailability(pseudo);
|
boolean pseudoAvailable = databaseRepo.checkPseudoAvailability(pseudo);
|
||||||
|
|
Loading…
Add table
Reference in a new issue