changed checkuser logic

main
Nilo Roberto C Paim 2024-05-15 11:44:47 -03:00
parent 0418ad4466
commit 918f05b649
2 changed files with 48 additions and 20 deletions

View File

@ -178,30 +178,59 @@ func GetUserByEmail(c *fiber.Ctx) error {
func Checkuser(c *fiber.Ctx) error {
type Checkuser struct {
Email string `json:"email"`
Type string `json:"type"`
}
var user models.User
var usertest models.UserTest
var response Checkuser
email := c.Params("email")
response.Email = email
// Check if user exists
database.DB.Where("email = ?", email).First(&user)
// if user.ID == 0 {
// return fiber.ErrNotFound
// }
if user.ID == 0 {
// The user is not found; let's check if it's a test user
database.DB.Where("email = ?", email).First(&usertest)
return c.JSON(user)
}
func Checkusertest(c *fiber.Ctx) error {
var usertest models.UserTest
email := c.Params("email")
database.DB.Where("email = ?", email).First(&usertest)
// if user.ID == 0 {
// return fiber.ErrNotFound
// }
return c.JSON(usertest)
if usertest.ID == 0 {
// The user is not found for eligible tester; let's signalize this
response.Type = "T"
} else {
// The user is found for eligible tester; but let's check if it's test already done
response.Type = "ET" // Eligible tester but the test was not done already
if usertest.Status == "TR" {
// The user is found for eligible tester; and the test is done
response.Type = "ETR"
}
}
} else {
// The user is found; let's signalize this
response.Type = "U" // At first sight it's a user
if user.Channel == "" {
// User needs to complete the registration
response.Type = "RU"
}
if user.Blocked == "S" {
// User is blocked
response.Type = "UB"
}
if user.Cancelled == "S" {
// User is cancelled
response.Type = "UC"
}
}
// TODO: Should we insert the user in the database, if it's a tester?
return c.JSON(response)
}

View File

@ -20,7 +20,6 @@ func Setup(app *fiber.App) {
app.Post("/register", controllers.AddUser)
app.Get("/checkuser/:email", controllers.Checkuser)
app.Get("/checktsertest/:name", controllers.Checkusertest)
// Webhooks
app.Post("/on_server_start", controllers.ServerStart)