Add email confirmation API func, fix TODOs

This commit is contained in:
2024-02-02 13:27:12 -06:00
parent 2ae78890e9
commit 15def57676
2 changed files with 32 additions and 4 deletions

28
api.go
View File

@@ -276,3 +276,31 @@ func RegisterVehicle(formParams map[string]string, propertyId uint, residentProf
return false, nil
}
// RegisterEmailConfirmation sends a request to the server to send a confirmation email regarding a vehicle's registration.
// Example Parameters: email=xevion@xevion.dev, vehicleId=63283, propertyId=63184
func RegisterEmailConfirmation(email string, vehicleId string, propertyId string) (bool, error) {
params := map[string]string{
"email": email,
"vehicleId": vehicleId,
"propertyId": propertyId,
"propertySource": "parking-snap",
}
req := BuildRequestWithBody("GET", "/register-vehicle-confirmation-process", params, nil)
SetTypicalHeaders(req, nil, nil, false)
res, _ := doRequest(req)
if res.StatusCode != 200 {
return false, fmt.Errorf("unexpected status code: %d", res.StatusCode)
}
html, _ := io.ReadAll(res.Body)
htmlString := string(html)
if htmlString == "ok" {
return true, nil
}
return false, fmt.Errorf("unexpected response: %s", htmlString)
}

View File

@@ -8,7 +8,7 @@ import (
func RegisterModalHandler(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
// TODO: Pull in all parameters from the form
// TOOD: Pull in all hidden parameters form database
// TODO: Pull in all hidden parameters form database
// TODO: Pull in resident ID from database
err := session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
@@ -31,11 +31,11 @@ func RegisterModalHandler(session *discordgo.Session, interaction *discordgo.Int
email := dataByCustomID["email"].(*discordgo.TextInput).Value
log.Infof("Email: %s", email)
// TOOD: Submit registration request to API
// TODO: Submit registration request to API
// TODO: Edit response to indicate success/failure
// TOOD: On success, provide a button to submit email confirmation
// TODO: On success, provide a button to submit email confirmation
// TODO: Validate license plate
// session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
// Type: discordgo.InteractionResponseChannelMessageWithSource,
// Data: &discordgo.InteractionResponseData{