Email is unique for people + start work on authelia integration

This commit is contained in:
William Bouzourène 2026-03-13 14:42:40 +01:00
parent 76981f31c8
commit aeb43e4775
Signed by: bouzoure
GPG key ID: 423440D735B56BE2
9 changed files with 82 additions and 4 deletions

View file

@ -495,6 +495,18 @@ func ContactAdd(c *fiber.Ctx) error {
person.PostalCode = data.PostalCode
person.City = data.City
if len(data.Email) > 0 {
var personEmail []models.Person
result := db.Find(&personEmail, "LOWER(email) = LOWER(?)", data.Email)
if result.Error != nil {
return result.Error
}
if result.RowsAffected > 0 {
errors = append(errors, "L'adresse email est déjà utilisée par un membre ou un sympathisant")
}
}
sectionID, err := strconv.ParseUint(data.Section, 10, 0)
if err == nil {
for _, section := range sections {
@ -744,6 +756,18 @@ func ContactEdit(c *fiber.Ctx) error {
person.PostalCode = data.PostalCode
person.City = data.City
if len(data.Email) > 0 {
var personEmail []models.Person
result := db.Find(&personEmail, "LOWER(email) = LOWER(?)", data.Email)
if result.Error != nil {
return result.Error
}
if result.RowsAffected > 0 {
errors = append(errors, "L'adresse email est déjà utilisée par un membre ou un sympathisant")
}
}
sectionID, err := strconv.ParseUint(data.Section, 10, 0)
if err == nil {
for _, section := range sections {

View file

@ -18,7 +18,7 @@ import (
type PersonValidation struct {
LastName string `validate:"max=100"`
FirstName string `validate:"required,min=1,max=100"`
Email string `validate:"max=100"`
Email string `validate:"max=100,email"`
Phone string `validate:"max=100"`
Mobile string `validate:"max=100"`
Address1 string `validate:"max=100"`
@ -498,6 +498,18 @@ func MemberAdd(c *fiber.Ctx) error {
}
}
if len(data.Email) > 0 {
var personEmail []models.Person
result := db.Find(&personEmail, "LOWER(email) = LOWER(?)", data.Email)
if result.Error != nil {
return result.Error
}
if result.RowsAffected > 0 {
errors = append(errors, "L'adresse email est déjà utilisée par un membre ou un sympathisant")
}
}
person.IsContact = false
person.IsMember = true
person.LastName = data.LastName
@ -747,6 +759,18 @@ func MemberEdit(c *fiber.Ctx) error {
}
}
if len(data.Email) > 0 {
var personEmail []models.Person
result := db.Find(&personEmail, "LOWER(email) = LOWER(?)", data.Email)
if result.Error != nil {
return result.Error
}
if result.RowsAffected > 0 {
errors = append(errors, "L'adresse email est déjà utilisée par un membre ou un sympathisant")
}
}
person.IsContact = false
person.IsMember = true
person.LastName = data.LastName