mirror of
https://github.com/teamhanko/hanko.git
synced 2025-10-29 23:59:46 +08:00
This pull request introduces the new Flowpilot system along with several new features and various improvements. The key enhancements include configurable authorization, registration, and profile flows, as well as the ability to enable and disable user identifiers (e.g., email addresses and usernames) and login methods. --------- Co-authored-by: Frederic Jahn <frederic.jahn@hanko.io> Co-authored-by: Lennart Fleischmann <lennart.fleischmann@hanko.io> Co-authored-by: lfleischmann <67686424+lfleischmann@users.noreply.github.com> Co-authored-by: merlindru <hello@merlindru.com>
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package persistence
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gobuffalo/pop/v6"
|
|
"github.com/teamhanko/hanko/backend/persistence/models"
|
|
)
|
|
|
|
type PrimaryEmailPersister interface {
|
|
Create(models.PrimaryEmail) error
|
|
Update(models.PrimaryEmail) error
|
|
Delete(models.PrimaryEmail) error
|
|
}
|
|
|
|
type primaryEmailPersister struct {
|
|
db *pop.Connection
|
|
}
|
|
|
|
func NewPrimaryEmailPersister(db *pop.Connection) PrimaryEmailPersister {
|
|
return &primaryEmailPersister{db: db}
|
|
}
|
|
|
|
func (p *primaryEmailPersister) Create(primaryEmail models.PrimaryEmail) error {
|
|
vErr, err := p.db.ValidateAndCreate(&primaryEmail)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if vErr != nil && vErr.HasAny() {
|
|
return fmt.Errorf("primary email object validation failed: %w", vErr)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (p *primaryEmailPersister) Update(primaryEmail models.PrimaryEmail) error {
|
|
vErr, err := p.db.ValidateAndSave(&primaryEmail)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if vErr != nil && vErr.HasAny() {
|
|
return fmt.Errorf("primary email object validation failed: %w", vErr)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (e *primaryEmailPersister) Delete(primaryEmail models.PrimaryEmail) error {
|
|
err := e.db.Destroy(&primaryEmail)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to delete email: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|