feat: rebuild auth identity foundation flow
This commit is contained in:
@@ -13,8 +13,10 @@ import (
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||
"github.com/Wei-Shaw/sub2api/ent/authidentity"
|
||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||
"github.com/Wei-Shaw/sub2api/ent/paymentorder"
|
||||
"github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
|
||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||
"github.com/Wei-Shaw/sub2api/ent/redeemcode"
|
||||
"github.com/Wei-Shaw/sub2api/ent/usagelog"
|
||||
@@ -211,6 +213,48 @@ func (_c *UserCreate) SetNillableTotpEnabledAt(v *time.Time) *UserCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSignupSource sets the "signup_source" field.
|
||||
func (_c *UserCreate) SetSignupSource(v string) *UserCreate {
|
||||
_c.mutation.SetSignupSource(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableSignupSource sets the "signup_source" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableSignupSource(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetSignupSource(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetLastLoginAt sets the "last_login_at" field.
|
||||
func (_c *UserCreate) SetLastLoginAt(v time.Time) *UserCreate {
|
||||
_c.mutation.SetLastLoginAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableLastLoginAt sets the "last_login_at" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableLastLoginAt(v *time.Time) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetLastLoginAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetLastActiveAt sets the "last_active_at" field.
|
||||
func (_c *UserCreate) SetLastActiveAt(v time.Time) *UserCreate {
|
||||
_c.mutation.SetLastActiveAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableLastActiveAt sets the "last_active_at" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableLastActiveAt(v *time.Time) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetLastActiveAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||
func (_c *UserCreate) SetBalanceNotifyEnabled(v bool) *UserCreate {
|
||||
_c.mutation.SetBalanceNotifyEnabled(v)
|
||||
@@ -431,6 +475,36 @@ func (_c *UserCreate) AddPaymentOrders(v ...*PaymentOrder) *UserCreate {
|
||||
return _c.AddPaymentOrderIDs(ids...)
|
||||
}
|
||||
|
||||
// AddAuthIdentityIDs adds the "auth_identities" edge to the AuthIdentity entity by IDs.
|
||||
func (_c *UserCreate) AddAuthIdentityIDs(ids ...int64) *UserCreate {
|
||||
_c.mutation.AddAuthIdentityIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddAuthIdentities adds the "auth_identities" edges to the AuthIdentity entity.
|
||||
func (_c *UserCreate) AddAuthIdentities(v ...*AuthIdentity) *UserCreate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddAuthIdentityIDs(ids...)
|
||||
}
|
||||
|
||||
// AddPendingAuthSessionIDs adds the "pending_auth_sessions" edge to the PendingAuthSession entity by IDs.
|
||||
func (_c *UserCreate) AddPendingAuthSessionIDs(ids ...int64) *UserCreate {
|
||||
_c.mutation.AddPendingAuthSessionIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddPendingAuthSessions adds the "pending_auth_sessions" edges to the PendingAuthSession entity.
|
||||
func (_c *UserCreate) AddPendingAuthSessions(v ...*PendingAuthSession) *UserCreate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddPendingAuthSessionIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_c *UserCreate) Mutation() *UserMutation {
|
||||
return _c.mutation
|
||||
@@ -510,6 +584,10 @@ func (_c *UserCreate) defaults() error {
|
||||
v := user.DefaultTotpEnabled
|
||||
_c.mutation.SetTotpEnabled(v)
|
||||
}
|
||||
if _, ok := _c.mutation.SignupSource(); !ok {
|
||||
v := user.DefaultSignupSource
|
||||
_c.mutation.SetSignupSource(v)
|
||||
}
|
||||
if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
|
||||
v := user.DefaultBalanceNotifyEnabled
|
||||
_c.mutation.SetBalanceNotifyEnabled(v)
|
||||
@@ -589,6 +667,14 @@ func (_c *UserCreate) check() error {
|
||||
if _, ok := _c.mutation.TotpEnabled(); !ok {
|
||||
return &ValidationError{Name: "totp_enabled", err: errors.New(`ent: missing required field "User.totp_enabled"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.SignupSource(); !ok {
|
||||
return &ValidationError{Name: "signup_source", err: errors.New(`ent: missing required field "User.signup_source"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.SignupSource(); ok {
|
||||
if err := user.SignupSourceValidator(v); err != nil {
|
||||
return &ValidationError{Name: "signup_source", err: fmt.Errorf(`ent: validator failed for field "User.signup_source": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.BalanceNotifyEnabled(); !ok {
|
||||
return &ValidationError{Name: "balance_notify_enabled", err: errors.New(`ent: missing required field "User.balance_notify_enabled"`)}
|
||||
}
|
||||
@@ -684,6 +770,18 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(user.FieldTotpEnabledAt, field.TypeTime, value)
|
||||
_node.TotpEnabledAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.SignupSource(); ok {
|
||||
_spec.SetField(user.FieldSignupSource, field.TypeString, value)
|
||||
_node.SignupSource = value
|
||||
}
|
||||
if value, ok := _c.mutation.LastLoginAt(); ok {
|
||||
_spec.SetField(user.FieldLastLoginAt, field.TypeTime, value)
|
||||
_node.LastLoginAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.LastActiveAt(); ok {
|
||||
_spec.SetField(user.FieldLastActiveAt, field.TypeTime, value)
|
||||
_node.LastActiveAt = &value
|
||||
}
|
||||
if value, ok := _c.mutation.BalanceNotifyEnabled(); ok {
|
||||
_spec.SetField(user.FieldBalanceNotifyEnabled, field.TypeBool, value)
|
||||
_node.BalanceNotifyEnabled = value
|
||||
@@ -868,6 +966,38 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.AuthIdentitiesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.AuthIdentitiesTable,
|
||||
Columns: []string{user.AuthIdentitiesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.PendingAuthSessionsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.PendingAuthSessionsTable,
|
||||
Columns: []string{user.PendingAuthSessionsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
@@ -1106,6 +1236,54 @@ func (u *UserUpsert) ClearTotpEnabledAt() *UserUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetSignupSource sets the "signup_source" field.
|
||||
func (u *UserUpsert) SetSignupSource(v string) *UserUpsert {
|
||||
u.Set(user.FieldSignupSource, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
|
||||
func (u *UserUpsert) UpdateSignupSource() *UserUpsert {
|
||||
u.SetExcluded(user.FieldSignupSource)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetLastLoginAt sets the "last_login_at" field.
|
||||
func (u *UserUpsert) SetLastLoginAt(v time.Time) *UserUpsert {
|
||||
u.Set(user.FieldLastLoginAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
|
||||
func (u *UserUpsert) UpdateLastLoginAt() *UserUpsert {
|
||||
u.SetExcluded(user.FieldLastLoginAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||
func (u *UserUpsert) ClearLastLoginAt() *UserUpsert {
|
||||
u.SetNull(user.FieldLastLoginAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetLastActiveAt sets the "last_active_at" field.
|
||||
func (u *UserUpsert) SetLastActiveAt(v time.Time) *UserUpsert {
|
||||
u.Set(user.FieldLastActiveAt, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
|
||||
func (u *UserUpsert) UpdateLastActiveAt() *UserUpsert {
|
||||
u.SetExcluded(user.FieldLastActiveAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||
func (u *UserUpsert) ClearLastActiveAt() *UserUpsert {
|
||||
u.SetNull(user.FieldLastActiveAt)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||
func (u *UserUpsert) SetBalanceNotifyEnabled(v bool) *UserUpsert {
|
||||
u.Set(user.FieldBalanceNotifyEnabled, v)
|
||||
@@ -1446,6 +1624,62 @@ func (u *UserUpsertOne) ClearTotpEnabledAt() *UserUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetSignupSource sets the "signup_source" field.
|
||||
func (u *UserUpsertOne) SetSignupSource(v string) *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetSignupSource(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
|
||||
func (u *UserUpsertOne) UpdateSignupSource() *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.UpdateSignupSource()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLastLoginAt sets the "last_login_at" field.
|
||||
func (u *UserUpsertOne) SetLastLoginAt(v time.Time) *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetLastLoginAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
|
||||
func (u *UserUpsertOne) UpdateLastLoginAt() *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.UpdateLastLoginAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||
func (u *UserUpsertOne) ClearLastLoginAt() *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.ClearLastLoginAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLastActiveAt sets the "last_active_at" field.
|
||||
func (u *UserUpsertOne) SetLastActiveAt(v time.Time) *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetLastActiveAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
|
||||
func (u *UserUpsertOne) UpdateLastActiveAt() *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.UpdateLastActiveAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||
func (u *UserUpsertOne) ClearLastActiveAt() *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.ClearLastActiveAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||
func (u *UserUpsertOne) SetBalanceNotifyEnabled(v bool) *UserUpsertOne {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
@@ -1965,6 +2199,62 @@ func (u *UserUpsertBulk) ClearTotpEnabledAt() *UserUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetSignupSource sets the "signup_source" field.
|
||||
func (u *UserUpsertBulk) SetSignupSource(v string) *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetSignupSource(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateSignupSource sets the "signup_source" field to the value that was provided on create.
|
||||
func (u *UserUpsertBulk) UpdateSignupSource() *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.UpdateSignupSource()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLastLoginAt sets the "last_login_at" field.
|
||||
func (u *UserUpsertBulk) SetLastLoginAt(v time.Time) *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetLastLoginAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLastLoginAt sets the "last_login_at" field to the value that was provided on create.
|
||||
func (u *UserUpsertBulk) UpdateLastLoginAt() *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.UpdateLastLoginAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearLastLoginAt clears the value of the "last_login_at" field.
|
||||
func (u *UserUpsertBulk) ClearLastLoginAt() *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.ClearLastLoginAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetLastActiveAt sets the "last_active_at" field.
|
||||
func (u *UserUpsertBulk) SetLastActiveAt(v time.Time) *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.SetLastActiveAt(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateLastActiveAt sets the "last_active_at" field to the value that was provided on create.
|
||||
func (u *UserUpsertBulk) UpdateLastActiveAt() *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.UpdateLastActiveAt()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearLastActiveAt clears the value of the "last_active_at" field.
|
||||
func (u *UserUpsertBulk) ClearLastActiveAt() *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
s.ClearLastActiveAt()
|
||||
})
|
||||
}
|
||||
|
||||
// SetBalanceNotifyEnabled sets the "balance_notify_enabled" field.
|
||||
func (u *UserUpsertBulk) SetBalanceNotifyEnabled(v bool) *UserUpsertBulk {
|
||||
return u.Update(func(s *UserUpsert) {
|
||||
|
||||
Reference in New Issue
Block a user