mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
42 lines
873 B
Go
42 lines
873 B
Go
package user
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/hanzoai/commerce/util/crypto/sha256"
|
|
"github.com/hanzoai/commerce/util/json"
|
|
"github.com/hanzoai/commerce/util/webhook"
|
|
)
|
|
|
|
// Hooks
|
|
func (u *User) BeforeCreate() error {
|
|
u.Username = strings.ToLower(u.Username)
|
|
u.Email = strings.ToLower(u.Email)
|
|
return nil
|
|
}
|
|
|
|
func (u *User) BeforeUpdate(prev *User) error {
|
|
u.Username = strings.ToLower(u.Username)
|
|
u.Email = strings.ToLower(u.Email)
|
|
u.KYC.Hash = sha256.Hash(string(json.EncodeBytes(&u.KYC.KYCData)))
|
|
|
|
return nil
|
|
}
|
|
|
|
func (u *User) AfterCreate() error {
|
|
webhook.Emit(u.Context(), u.Namespace(), "user.created", u)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (u *User) AfterUpdate(prev *User) error {
|
|
webhook.Emit(u.Context(), u.Namespace(), "user.updated", u)
|
|
return nil
|
|
}
|
|
|
|
func (u *User) AfterDelete() error {
|
|
webhook.Emit(u.Context(), u.Namespace(), "user.deleted", u)
|
|
|
|
return nil
|
|
}
|