leo
593454d616
All checks were successful
continuous-integration/drone/push Build is passing
* add Email field to User entity (+codegen) * switch to Echo contrib sessions backed by Gorilla sessions * use SessionCookieSecret value from the config * stage mod,sum changes * add clearer signup/signin redirect logic * render error pages on 500/404s and only fall back to returning raw errors when the error is some unexpected kind * add username/email "exists" funcs+tests - handle "not found" and "not unique" errors, return errors otherwise
49 lines
839 B
Go
49 lines
839 B
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/schema/field"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// User holds the schema definition for the User entity.
|
|
type User struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the User.
|
|
func (User) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.UUID("id", uuid.UUID{}).
|
|
Default(uuid.New).
|
|
Unique().
|
|
Immutable(),
|
|
field.String("username").
|
|
NotEmpty().
|
|
Unique(),
|
|
field.String("email").
|
|
NotEmpty().
|
|
Unique(),
|
|
field.String("password").
|
|
Sensitive().
|
|
NotEmpty(),
|
|
field.Bool("is_admin").
|
|
Default(false),
|
|
field.Bool("is_active").
|
|
Default(true),
|
|
field.Time("created_at").
|
|
Default(time.Now).
|
|
Immutable(),
|
|
field.Time("updated_at").
|
|
Default(time.Now).
|
|
UpdateDefault(time.Now),
|
|
}
|
|
}
|
|
|
|
// Edges of the User.
|
|
func (User) Edges() []ent.Edge {
|
|
return nil
|
|
}
|