init: Initial commit
This commit is contained in:
39
app/models/users.go
Normal file
39
app/models/users.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.secnex.io/secnex/mgmt-api/utils"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||
FirstName string `gorm:"not null" json:"first_name"`
|
||||
LastName string `gorm:"not null" json:"last_name"`
|
||||
Username string `gorm:"not null;unique" json:"username"`
|
||||
Password string `gorm:"not null" json:"password"`
|
||||
Email string `gorm:"not null;unique" json:"email"`
|
||||
Verified bool `gorm:"not null;default:false" json:"verified"`
|
||||
TenantID *uuid.UUID `gorm:"type:uuid" json:"tenant_id"`
|
||||
ExternalID *uuid.UUID `gorm:"type:uuid" json:"external_id"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
|
||||
|
||||
Tenant *Tenant `gorm:"foreignKey:TenantID" json:"tenant"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "users"
|
||||
}
|
||||
|
||||
func (user *User) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
passwordHash, err := utils.Hash(user.Password)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user.Password = passwordHash
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user