Add Staff Application Form handling
Introduced `StaffAppController` and `StaffAppFormData` to handle staff application form submissions. The controller now stores user data, initiates email verification, and provides appropriate responses based on the verification outcome. Additionally, updated `application.properties` and cleaned up IntelliJ workspace.xml.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.alttd.forms.apply;
|
||||
|
||||
import com.alttd.forms.form.StoreFormQuery;
|
||||
import com.alttd.forms.mail.verification.VerificationResult;
|
||||
import com.alttd.forms.mail.verification.Verify;
|
||||
import jakarta.validation.Valid;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class StaffAppController {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(StaffAppController.class);
|
||||
|
||||
@PostMapping("/staffApplication")
|
||||
public CompletableFuture<ResponseEntity<String>> submitForm(@Valid @RequestBody StaffAppFormData formData) {
|
||||
logger.debug("submitForm");
|
||||
logger.trace(formData.toString());
|
||||
|
||||
CompletableFuture<Integer> storeFormForVerificationCode = new StoreFormQuery().storeFormForVerificationCode(formData.email, formData);
|
||||
return storeFormForVerificationCode.thenCompose(code -> Verify.verifyEmail(formData.email, code).thenApply(verificationResult -> {
|
||||
if (verificationResult == VerificationResult.VERIFICATION_SENT) {
|
||||
//TODO if this is ok tell the user they have x min to verify if they fail to do so they have to remake the form
|
||||
logger.trace("Staff application form stored and requested verification from user");
|
||||
return ResponseEntity.ok("User Data received and email verification sent.");
|
||||
} else {
|
||||
logger.trace("Failed to send verification email");
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body("Failed to send verification email. Reason: " + verificationResult.name());
|
||||
}
|
||||
})).exceptionally(throwable -> {
|
||||
logger.error("Failed to store form", throwable);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to store your form");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.alttd.forms.apply;
|
||||
|
||||
import com.alttd.forms.form.Form;
|
||||
import jakarta.validation.constraints.*;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class StaffAppFormData extends Form {
|
||||
|
||||
public StaffAppFormData(String username, String email, String discord, String pc_requirements, int age, String pronoun, LocalDate join_date, int avg_time, String available_days, String available_time, String staff_experience, String plugin_experience, String why_staff, String expectations_mod, String other) {
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
this.discord = discord;
|
||||
this.pc_requirements = pc_requirements;
|
||||
this.age = age;
|
||||
this.pronoun = pronoun;
|
||||
this.join_date = join_date;
|
||||
this.avg_time = avg_time;
|
||||
this.available_days = available_days;
|
||||
this.available_time = available_time;
|
||||
this.staff_experience = staff_experience;
|
||||
this.plugin_experience = plugin_experience;
|
||||
this.why_staff = why_staff;
|
||||
this.expectations_mod = expectations_mod;
|
||||
this.other = other;
|
||||
}
|
||||
|
||||
@NotEmpty(message = "Username is required")
|
||||
@Length(min = 3, max = 16, message = "Username should be between 3 and 16 characters")
|
||||
@Pattern(regexp = "^[a-zA-Z0-9_]*$", message = "Username should only include alphanumeric characters and underscore")
|
||||
public final String username;
|
||||
|
||||
@NotEmpty(message = "E-mail address is required")
|
||||
@Email(message = "Invalid email")
|
||||
@Length(min = 3, max = 254, message = "Email should be between 3 and 254 characters")
|
||||
public final String email;
|
||||
|
||||
@NotEmpty(message = "Discord name is required")
|
||||
@Length(min = 2, max = 32, message = "Discord name should be between 2 and 32 characters")
|
||||
@Pattern(regexp = "^(?!.*\\..)([a-z0-9._]{2,32})$", message = "Please enter a valid Discord name")
|
||||
public final String discord;
|
||||
|
||||
@NotEmpty(message = "An answer is required")
|
||||
@Length(min = 2, max = 3, message = "Please answer yes or no")
|
||||
@Pattern(regexp = "(yes|no)$", message = "Yes or no")
|
||||
public final String pc_requirements;
|
||||
|
||||
@Min(value = 0, message = "Please enter a valid age")
|
||||
@Max(value = 999, message = "We do not accept players older than 999 years old sorry!")
|
||||
public final int age;
|
||||
|
||||
@Length(max = 16, message = "Pronouns can't be longer than 16 characters")
|
||||
public final String pronoun;
|
||||
|
||||
@NotNull(message = "Your join date is required, if you're not sure enter an estimated date")
|
||||
public final LocalDate join_date;
|
||||
|
||||
@Range(min = 0, max = 168, message = "The only valid values are 0-168")
|
||||
public final int avg_time;
|
||||
|
||||
@NotEmpty(message = "Available days are required")
|
||||
@Length(min = 6, max = 128, message = "Available days should be between 6 and 128 characters")
|
||||
public final String available_days;
|
||||
|
||||
@NotEmpty(message = "Available time is required")
|
||||
@Length(min = 3, max = 256, message = "Available time should be between 3 and 256 characters")
|
||||
public final String available_time;
|
||||
|
||||
@NotEmpty(message = "Staff experience is required")
|
||||
@Length(min = 2, max = 2000, message = "Experience should be between 2 and 2000 characters")
|
||||
public final String staff_experience;
|
||||
|
||||
@NotEmpty(message = "Plugin experience is required")
|
||||
@Length(min = 2, max = 2000, message = "Experience should be between 2 and 2000 characters")
|
||||
public final String plugin_experience;
|
||||
|
||||
@NotEmpty(message = "Reason for wanting to be a moderator is required")
|
||||
@Length(min = 2, max =2000, message = "Reason should be between 2 and 2000 characters")
|
||||
public final String why_staff;
|
||||
|
||||
@NotEmpty(message = "Expectations of a moderator is required")
|
||||
@Length(min = 2, max = 2000, message = "Expectation should be between 2 and 2000 characters")
|
||||
public final String expectations_mod;
|
||||
|
||||
@Length(max = 2000, message = "Text can't be longer than 2000 characters")
|
||||
public final String other;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StaffAppFormData{" +
|
||||
"username='" + username + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", discord='" + discord + '\'' +
|
||||
", pc_requirements='" + pc_requirements + '\'' +
|
||||
", age=" + age +
|
||||
", pronoun='" + pronoun + '\'' +
|
||||
", join_date=" + join_date +
|
||||
", avg_time=" + avg_time +
|
||||
", available_days='" + available_days + '\'' +
|
||||
", available_time='" + available_time + '\'' +
|
||||
", staff_experience='" + staff_experience + '\'' +
|
||||
", plugin_experience='" + plugin_experience + '\'' +
|
||||
", why_staff='" + why_staff + '\'' +
|
||||
", expectations_mod='" + expectations_mod + '\'' +
|
||||
", other='" + other + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toHtml() {
|
||||
String[] fields = {"Username", "Email", "Discord", "PC requirements", "Age", "Pronoun", "Join date", "Avg time", "Available days", "Available time", "Staff experience", "Plugin experience", "Why staff", "Expectations mod", "Other"};
|
||||
String[] values = {username, email, discord, pc_requirements, String.valueOf(age), pronoun, join_date.toString(), String.valueOf(avg_time), available_days, available_time, staff_experience, plugin_experience, why_staff, expectations_mod, other};
|
||||
|
||||
return toHtml(fields, values);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
logging.level.com.alttd.forms=warn
|
||||
server.port=8002
|
||||
server.port=8002
|
||||
spring.jackson.date-format=yyyy-MM-dd
|
||||
Reference in New Issue
Block a user