Ability to create account for members
This commit is contained in:
parent
07db65f63f
commit
2e332b8f3e
5 changed files with 138 additions and 16 deletions
|
|
@ -762,7 +762,7 @@ func ContactEdit(c *fiber.Ctx) error {
|
|||
|
||||
if len(data.Email) > 0 {
|
||||
var personEmail []models.Person
|
||||
result := db.Find(&personEmail, "LOWER(email) = LOWER(?)", data.Email)
|
||||
result := db.Find(&personEmail, "LOWER(email) = LOWER(?) AND id <> ?", data.Email, person.ID)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ import (
|
|||
"time"
|
||||
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers/authelia"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/helpers/database"
|
||||
"git.readonly.ch/bouzoure/pop-camarades/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type PersonValidation struct {
|
||||
|
|
@ -636,6 +638,16 @@ func MemberAdd(c *fiber.Ctx) error {
|
|||
}
|
||||
}
|
||||
|
||||
if c.FormValue("account-enabled") == "on" {
|
||||
personAccount := models.PersonAccount{
|
||||
PersonID: person.ID,
|
||||
UUID: uuid.New(),
|
||||
Enabled: true,
|
||||
Groups: strings.Join(authelia.GetPersonGroups(person.ID), "|||"),
|
||||
}
|
||||
db.Create(&personAccount)
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/members/%d",
|
||||
person.ID,
|
||||
|
|
@ -714,6 +726,9 @@ func MemberEdit(c *fiber.Ctx) error {
|
|||
person.ID,
|
||||
)
|
||||
|
||||
var personAccount models.PersonAccount
|
||||
db.Find(&personAccount, "person_id = ?", person.ID)
|
||||
|
||||
var errors []string
|
||||
if c.Method() == "POST" {
|
||||
data := PersonValidation{
|
||||
|
|
@ -765,7 +780,7 @@ func MemberEdit(c *fiber.Ctx) error {
|
|||
|
||||
if len(data.Email) > 0 {
|
||||
var personEmail []models.Person
|
||||
result := db.Find(&personEmail, "LOWER(email) = LOWER(?)", data.Email)
|
||||
result := db.Find(&personEmail, "LOWER(email) = LOWER(?) AND id <> ?", data.Email, person.ID)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
|
@ -906,6 +921,33 @@ func MemberEdit(c *fiber.Ctx) error {
|
|||
return result.Error
|
||||
}
|
||||
|
||||
if c.FormValue("account-enabled") == "on" && personAccount.ID <= 0 {
|
||||
personAccount = models.PersonAccount{
|
||||
PersonID: person.ID,
|
||||
UUID: uuid.New(),
|
||||
Enabled: true,
|
||||
Groups: strings.Join(authelia.GetPersonGroups(person.ID), "|||"),
|
||||
}
|
||||
db.Create(&personAccount)
|
||||
} else if c.FormValue("account-enabled") == "on" && personAccount.ID > 0 {
|
||||
personAccount.Enabled = true
|
||||
personAccount.Groups = strings.Join(authelia.GetPersonGroups(person.ID), "|||")
|
||||
|
||||
if personAccount.AccountCreated {
|
||||
personAccount.UpdateNeeded = true
|
||||
}
|
||||
|
||||
db.Save(&personAccount)
|
||||
} else if c.FormValue("account-enabled") != "on" && personAccount.ID > 0 {
|
||||
personAccount.Enabled = false
|
||||
|
||||
if personAccount.AccountCreated {
|
||||
personAccount.UpdateNeeded = true
|
||||
}
|
||||
|
||||
db.Save(&personAccount)
|
||||
}
|
||||
|
||||
c.Redirect(fmt.Sprintf(
|
||||
"/members/%d",
|
||||
person.ID,
|
||||
|
|
@ -914,12 +956,13 @@ func MemberEdit(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
return c.Render("person_form", fiber.Map{
|
||||
"PageTitle": title,
|
||||
"Person": person,
|
||||
"Sections": sections,
|
||||
"Fields": fields,
|
||||
"FieldValues": fieldValues,
|
||||
"Errors": errors,
|
||||
"PageTitle": title,
|
||||
"Person": person,
|
||||
"Sections": sections,
|
||||
"Fields": fields,
|
||||
"FieldValues": fieldValues,
|
||||
"PersonAccount": personAccount,
|
||||
"Errors": errors,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue