diff --git a/ent/account/where.go b/ent/account/where.go index ed36e57..8cef07a 100644 --- a/ent/account/where.go +++ b/ent/account/where.go @@ -226,6 +226,16 @@ func NicknameHasSuffix(v string) predicate.Account { return predicate.Account(sql.FieldHasSuffix(FieldNickname, v)) } +// NicknameIsNil applies the IsNil predicate on the "nickname" field. +func NicknameIsNil() predicate.Account { + return predicate.Account(sql.FieldIsNull(FieldNickname)) +} + +// NicknameNotNil applies the NotNil predicate on the "nickname" field. +func NicknameNotNil() predicate.Account { + return predicate.Account(sql.FieldNotNull(FieldNickname)) +} + // NicknameEqualFold applies the EqualFold predicate on the "nickname" field. func NicknameEqualFold(v string) predicate.Account { return predicate.Account(sql.FieldEqualFold(FieldNickname, v)) @@ -291,6 +301,16 @@ func NameHasSuffix(v string) predicate.Account { return predicate.Account(sql.FieldHasSuffix(FieldName, v)) } +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Account { + return predicate.Account(sql.FieldIsNull(FieldName)) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Account { + return predicate.Account(sql.FieldNotNull(FieldName)) +} + // NameEqualFold applies the EqualFold predicate on the "name" field. func NameEqualFold(v string) predicate.Account { return predicate.Account(sql.FieldEqualFold(FieldName, v)) diff --git a/ent/account_create.go b/ent/account_create.go index 722a238..4fbbb8c 100644 --- a/ent/account_create.go +++ b/ent/account_create.go @@ -56,12 +56,28 @@ func (ac *AccountCreate) SetNickname(s string) *AccountCreate { return ac } +// SetNillableNickname sets the "nickname" field if the given value is not nil. +func (ac *AccountCreate) SetNillableNickname(s *string) *AccountCreate { + if s != nil { + ac.SetNickname(*s) + } + return ac +} + // SetName sets the "name" field. func (ac *AccountCreate) SetName(s string) *AccountCreate { ac.mutation.SetName(s) return ac } +// SetNillableName sets the "name" field if the given value is not nil. +func (ac *AccountCreate) SetNillableName(s *string) *AccountCreate { + if s != nil { + ac.SetName(*s) + } + return ac +} + // SetSecret sets the "secret" field. func (ac *AccountCreate) SetSecret(b []byte) *AccountCreate { ac.mutation.SetSecret(b) @@ -154,12 +170,6 @@ func (ac *AccountCreate) check() error { if _, ok := ac.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Account.updated_at"`)} } - if _, ok := ac.mutation.Nickname(); !ok { - return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "Account.nickname"`)} - } - if _, ok := ac.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Account.name"`)} - } if _, ok := ac.mutation.Secret(); !ok { return &ValidationError{Name: "secret", err: errors.New(`ent: missing required field "Account.secret"`)} } diff --git a/ent/account_update.go b/ent/account_update.go index 3a1fae3..7df201a 100644 --- a/ent/account_update.go +++ b/ent/account_update.go @@ -50,6 +50,12 @@ func (au *AccountUpdate) SetNillableNickname(s *string) *AccountUpdate { return au } +// ClearNickname clears the value of the "nickname" field. +func (au *AccountUpdate) ClearNickname() *AccountUpdate { + au.mutation.ClearNickname() + return au +} + // SetName sets the "name" field. func (au *AccountUpdate) SetName(s string) *AccountUpdate { au.mutation.SetName(s) @@ -64,6 +70,12 @@ func (au *AccountUpdate) SetNillableName(s *string) *AccountUpdate { return au } +// ClearName clears the value of the "name" field. +func (au *AccountUpdate) ClearName() *AccountUpdate { + au.mutation.ClearName() + return au +} + // SetSecret sets the "secret" field. func (au *AccountUpdate) SetSecret(b []byte) *AccountUpdate { au.mutation.SetSecret(b) @@ -187,9 +199,15 @@ func (au *AccountUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := au.mutation.Nickname(); ok { _spec.SetField(account.FieldNickname, field.TypeString, value) } + if au.mutation.NicknameCleared() { + _spec.ClearField(account.FieldNickname, field.TypeString) + } if value, ok := au.mutation.Name(); ok { _spec.SetField(account.FieldName, field.TypeString, value) } + if au.mutation.NameCleared() { + _spec.ClearField(account.FieldName, field.TypeString) + } if value, ok := au.mutation.Secret(); ok { _spec.SetField(account.FieldSecret, field.TypeBytes, value) } @@ -284,6 +302,12 @@ func (auo *AccountUpdateOne) SetNillableNickname(s *string) *AccountUpdateOne { return auo } +// ClearNickname clears the value of the "nickname" field. +func (auo *AccountUpdateOne) ClearNickname() *AccountUpdateOne { + auo.mutation.ClearNickname() + return auo +} + // SetName sets the "name" field. func (auo *AccountUpdateOne) SetName(s string) *AccountUpdateOne { auo.mutation.SetName(s) @@ -298,6 +322,12 @@ func (auo *AccountUpdateOne) SetNillableName(s *string) *AccountUpdateOne { return auo } +// ClearName clears the value of the "name" field. +func (auo *AccountUpdateOne) ClearName() *AccountUpdateOne { + auo.mutation.ClearName() + return auo +} + // SetSecret sets the "secret" field. func (auo *AccountUpdateOne) SetSecret(b []byte) *AccountUpdateOne { auo.mutation.SetSecret(b) @@ -451,9 +481,15 @@ func (auo *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err e if value, ok := auo.mutation.Nickname(); ok { _spec.SetField(account.FieldNickname, field.TypeString, value) } + if auo.mutation.NicknameCleared() { + _spec.ClearField(account.FieldNickname, field.TypeString) + } if value, ok := auo.mutation.Name(); ok { _spec.SetField(account.FieldName, field.TypeString, value) } + if auo.mutation.NameCleared() { + _spec.ClearField(account.FieldName, field.TypeString) + } if value, ok := auo.mutation.Secret(); ok { _spec.SetField(account.FieldSecret, field.TypeBytes, value) } diff --git a/ent/client.go b/ent/client.go index 42bdd62..20f5042 100644 --- a/ent/client.go +++ b/ent/client.go @@ -465,15 +465,15 @@ func (c *EmailClient) GetX(ctx context.Context, id uuid.UUID) *Email { return obj } -// QueryAccounts queries the accounts edge of a Email. -func (c *EmailClient) QueryAccounts(e *Email) *AccountQuery { +// QueryAccount queries the account edge of a Email. +func (c *EmailClient) QueryAccount(e *Email) *AccountQuery { query := (&AccountClient{config: c.config}).Query() query.path = func(context.Context) (fromV *sql.Selector, _ error) { id := e.ID step := sqlgraph.NewStep( sqlgraph.From(email.Table, email.FieldID, id), sqlgraph.To(account.Table, account.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, email.AccountsTable, email.AccountsColumn), + sqlgraph.Edge(sqlgraph.M2O, true, email.AccountTable, email.AccountColumn), ) fromV = sqlgraph.Neighbors(e.driver.Dialect(), step) return fromV, nil diff --git a/ent/email.go b/ent/email.go index f00bd7f..4c585bd 100644 --- a/ent/email.go +++ b/ent/email.go @@ -37,22 +37,22 @@ type Email struct { // EmailEdges holds the relations/edges for other nodes in the graph. type EmailEdges struct { - // Accounts holds the value of the accounts edge. - Accounts *Account `json:"accounts,omitempty"` + // Account holds the value of the account edge. + Account *Account `json:"account,omitempty"` // loadedTypes holds the information for reporting if a // type was loaded (or requested) in eager-loading or not. loadedTypes [1]bool } -// AccountsOrErr returns the Accounts value or an error if the edge +// AccountOrErr returns the Account value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. -func (e EmailEdges) AccountsOrErr() (*Account, error) { - if e.Accounts != nil { - return e.Accounts, nil +func (e EmailEdges) AccountOrErr() (*Account, error) { + if e.Account != nil { + return e.Account, nil } else if e.loadedTypes[0] { return nil, &NotFoundError{label: account.Label} } - return nil, &NotLoadedError{edge: "accounts"} + return nil, &NotLoadedError{edge: "account"} } // scanValues returns the types for scanning values from sql.Rows. @@ -139,9 +139,9 @@ func (e *Email) Value(name string) (ent.Value, error) { return e.selectValues.Get(name) } -// QueryAccounts queries the "accounts" edge of the Email entity. -func (e *Email) QueryAccounts() *AccountQuery { - return NewEmailClient(e.config).QueryAccounts(e) +// QueryAccount queries the "account" edge of the Email entity. +func (e *Email) QueryAccount() *AccountQuery { + return NewEmailClient(e.config).QueryAccount(e) } // Update returns a builder for updating this Email. diff --git a/ent/email/email.go b/ent/email/email.go index 7337e64..4f81720 100644 --- a/ent/email/email.go +++ b/ent/email/email.go @@ -22,17 +22,17 @@ const ( FieldVerificationCode = "verification_code" // FieldResetCode holds the string denoting the reset_code field in the database. FieldResetCode = "reset_code" - // EdgeAccounts holds the string denoting the accounts edge name in mutations. - EdgeAccounts = "accounts" + // EdgeAccount holds the string denoting the account edge name in mutations. + EdgeAccount = "account" // Table holds the table name of the email in the database. Table = "emails" - // AccountsTable is the table that holds the accounts relation/edge. - AccountsTable = "emails" - // AccountsInverseTable is the table name for the Account entity. + // AccountTable is the table that holds the account relation/edge. + AccountTable = "emails" + // AccountInverseTable is the table name for the Account entity. // It exists in this package in order to avoid circular dependency with the "account" package. - AccountsInverseTable = "accounts" - // AccountsColumn is the table column denoting the accounts relation/edge. - AccountsColumn = "account_emails" + AccountInverseTable = "accounts" + // AccountColumn is the table column denoting the account relation/edge. + AccountColumn = "account_emails" ) // Columns holds all SQL columns for email fields. @@ -106,16 +106,16 @@ func ByResetCode(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldResetCode, opts...).ToFunc() } -// ByAccountsField orders the results by accounts field. -func ByAccountsField(field string, opts ...sql.OrderTermOption) OrderOption { +// ByAccountField orders the results by account field. +func ByAccountField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newAccountsStep(), sql.OrderByField(field, opts...)) + sqlgraph.OrderByNeighborTerms(s, newAccountStep(), sql.OrderByField(field, opts...)) } } -func newAccountsStep() *sqlgraph.Step { +func newAccountStep() *sqlgraph.Step { return sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.To(AccountsInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, AccountsTable, AccountsColumn), + sqlgraph.To(AccountInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn), ) } diff --git a/ent/email/where.go b/ent/email/where.go index 762d079..fd66bd4 100644 --- a/ent/email/where.go +++ b/ent/email/where.go @@ -314,21 +314,21 @@ func ResetCodeContainsFold(v string) predicate.Email { return predicate.Email(sql.FieldContainsFold(FieldResetCode, v)) } -// HasAccounts applies the HasEdge predicate on the "accounts" edge. -func HasAccounts() predicate.Email { +// HasAccount applies the HasEdge predicate on the "account" edge. +func HasAccount() predicate.Email { return predicate.Email(func(s *sql.Selector) { step := sqlgraph.NewStep( sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, AccountsTable, AccountsColumn), + sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn), ) sqlgraph.HasNeighbors(s, step) }) } -// HasAccountsWith applies the HasEdge predicate on the "accounts" edge with a given conditions (other predicates). -func HasAccountsWith(preds ...predicate.Account) predicate.Email { +// HasAccountWith applies the HasEdge predicate on the "account" edge with a given conditions (other predicates). +func HasAccountWith(preds ...predicate.Account) predicate.Email { return predicate.Email(func(s *sql.Selector) { - step := newAccountsStep() + step := newAccountStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) diff --git a/ent/email_create.go b/ent/email_create.go index d734876..ea6df71 100644 --- a/ent/email_create.go +++ b/ent/email_create.go @@ -89,23 +89,23 @@ func (ec *EmailCreate) SetID(u uuid.UUID) *EmailCreate { return ec } -// SetAccountsID sets the "accounts" edge to the Account entity by ID. -func (ec *EmailCreate) SetAccountsID(id uuid.UUID) *EmailCreate { - ec.mutation.SetAccountsID(id) +// SetAccountID sets the "account" edge to the Account entity by ID. +func (ec *EmailCreate) SetAccountID(id uuid.UUID) *EmailCreate { + ec.mutation.SetAccountID(id) return ec } -// SetNillableAccountsID sets the "accounts" edge to the Account entity by ID if the given value is not nil. -func (ec *EmailCreate) SetNillableAccountsID(id *uuid.UUID) *EmailCreate { +// SetNillableAccountID sets the "account" edge to the Account entity by ID if the given value is not nil. +func (ec *EmailCreate) SetNillableAccountID(id *uuid.UUID) *EmailCreate { if id != nil { - ec = ec.SetAccountsID(*id) + ec = ec.SetAccountID(*id) } return ec } -// SetAccounts sets the "accounts" edge to the Account entity. -func (ec *EmailCreate) SetAccounts(a *Account) *EmailCreate { - return ec.SetAccountsID(a.ID) +// SetAccount sets the "account" edge to the Account entity. +func (ec *EmailCreate) SetAccount(a *Account) *EmailCreate { + return ec.SetAccountID(a.ID) } // Mutation returns the EmailMutation object of the builder. @@ -219,12 +219,12 @@ func (ec *EmailCreate) createSpec() (*Email, *sqlgraph.CreateSpec) { _spec.SetField(email.FieldResetCode, field.TypeString, value) _node.ResetCode = value } - if nodes := ec.mutation.AccountsIDs(); len(nodes) > 0 { + if nodes := ec.mutation.AccountIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: email.AccountsTable, - Columns: []string{email.AccountsColumn}, + Table: email.AccountTable, + Columns: []string{email.AccountColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID), diff --git a/ent/email_query.go b/ent/email_query.go index 1138d07..72e8e9e 100644 --- a/ent/email_query.go +++ b/ent/email_query.go @@ -20,12 +20,12 @@ import ( // EmailQuery is the builder for querying Email entities. type EmailQuery struct { config - ctx *QueryContext - order []email.OrderOption - inters []Interceptor - predicates []predicate.Email - withAccounts *AccountQuery - withFKs bool + ctx *QueryContext + order []email.OrderOption + inters []Interceptor + predicates []predicate.Email + withAccount *AccountQuery + withFKs bool // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) @@ -62,8 +62,8 @@ func (eq *EmailQuery) Order(o ...email.OrderOption) *EmailQuery { return eq } -// QueryAccounts chains the current query on the "accounts" edge. -func (eq *EmailQuery) QueryAccounts() *AccountQuery { +// QueryAccount chains the current query on the "account" edge. +func (eq *EmailQuery) QueryAccount() *AccountQuery { query := (&AccountClient{config: eq.config}).Query() query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { if err := eq.prepareQuery(ctx); err != nil { @@ -76,7 +76,7 @@ func (eq *EmailQuery) QueryAccounts() *AccountQuery { step := sqlgraph.NewStep( sqlgraph.From(email.Table, email.FieldID, selector), sqlgraph.To(account.Table, account.FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, email.AccountsTable, email.AccountsColumn), + sqlgraph.Edge(sqlgraph.M2O, true, email.AccountTable, email.AccountColumn), ) fromU = sqlgraph.SetNeighbors(eq.driver.Dialect(), step) return fromU, nil @@ -271,26 +271,26 @@ func (eq *EmailQuery) Clone() *EmailQuery { return nil } return &EmailQuery{ - config: eq.config, - ctx: eq.ctx.Clone(), - order: append([]email.OrderOption{}, eq.order...), - inters: append([]Interceptor{}, eq.inters...), - predicates: append([]predicate.Email{}, eq.predicates...), - withAccounts: eq.withAccounts.Clone(), + config: eq.config, + ctx: eq.ctx.Clone(), + order: append([]email.OrderOption{}, eq.order...), + inters: append([]Interceptor{}, eq.inters...), + predicates: append([]predicate.Email{}, eq.predicates...), + withAccount: eq.withAccount.Clone(), // clone intermediate query. sql: eq.sql.Clone(), path: eq.path, } } -// WithAccounts tells the query-builder to eager-load the nodes that are connected to -// the "accounts" edge. The optional arguments are used to configure the query builder of the edge. -func (eq *EmailQuery) WithAccounts(opts ...func(*AccountQuery)) *EmailQuery { +// WithAccount tells the query-builder to eager-load the nodes that are connected to +// the "account" edge. The optional arguments are used to configure the query builder of the edge. +func (eq *EmailQuery) WithAccount(opts ...func(*AccountQuery)) *EmailQuery { query := (&AccountClient{config: eq.config}).Query() for _, opt := range opts { opt(query) } - eq.withAccounts = query + eq.withAccount = query return eq } @@ -374,10 +374,10 @@ func (eq *EmailQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Email, withFKs = eq.withFKs _spec = eq.querySpec() loadedTypes = [1]bool{ - eq.withAccounts != nil, + eq.withAccount != nil, } ) - if eq.withAccounts != nil { + if eq.withAccount != nil { withFKs = true } if withFKs { @@ -401,16 +401,16 @@ func (eq *EmailQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Email, if len(nodes) == 0 { return nodes, nil } - if query := eq.withAccounts; query != nil { - if err := eq.loadAccounts(ctx, query, nodes, nil, - func(n *Email, e *Account) { n.Edges.Accounts = e }); err != nil { + if query := eq.withAccount; query != nil { + if err := eq.loadAccount(ctx, query, nodes, nil, + func(n *Email, e *Account) { n.Edges.Account = e }); err != nil { return nil, err } } return nodes, nil } -func (eq *EmailQuery) loadAccounts(ctx context.Context, query *AccountQuery, nodes []*Email, init func(*Email), assign func(*Email, *Account)) error { +func (eq *EmailQuery) loadAccount(ctx context.Context, query *AccountQuery, nodes []*Email, init func(*Email), assign func(*Email, *Account)) error { ids := make([]uuid.UUID, 0, len(nodes)) nodeids := make(map[uuid.UUID][]*Email) for i := range nodes { diff --git a/ent/email_update.go b/ent/email_update.go index e2e1f47..f112fe4 100644 --- a/ent/email_update.go +++ b/ent/email_update.go @@ -111,23 +111,23 @@ func (eu *EmailUpdate) ClearResetCode() *EmailUpdate { return eu } -// SetAccountsID sets the "accounts" edge to the Account entity by ID. -func (eu *EmailUpdate) SetAccountsID(id uuid.UUID) *EmailUpdate { - eu.mutation.SetAccountsID(id) +// SetAccountID sets the "account" edge to the Account entity by ID. +func (eu *EmailUpdate) SetAccountID(id uuid.UUID) *EmailUpdate { + eu.mutation.SetAccountID(id) return eu } -// SetNillableAccountsID sets the "accounts" edge to the Account entity by ID if the given value is not nil. -func (eu *EmailUpdate) SetNillableAccountsID(id *uuid.UUID) *EmailUpdate { +// SetNillableAccountID sets the "account" edge to the Account entity by ID if the given value is not nil. +func (eu *EmailUpdate) SetNillableAccountID(id *uuid.UUID) *EmailUpdate { if id != nil { - eu = eu.SetAccountsID(*id) + eu = eu.SetAccountID(*id) } return eu } -// SetAccounts sets the "accounts" edge to the Account entity. -func (eu *EmailUpdate) SetAccounts(a *Account) *EmailUpdate { - return eu.SetAccountsID(a.ID) +// SetAccount sets the "account" edge to the Account entity. +func (eu *EmailUpdate) SetAccount(a *Account) *EmailUpdate { + return eu.SetAccountID(a.ID) } // Mutation returns the EmailMutation object of the builder. @@ -135,9 +135,9 @@ func (eu *EmailUpdate) Mutation() *EmailMutation { return eu.mutation } -// ClearAccounts clears the "accounts" edge to the Account entity. -func (eu *EmailUpdate) ClearAccounts() *EmailUpdate { - eu.mutation.ClearAccounts() +// ClearAccount clears the "account" edge to the Account entity. +func (eu *EmailUpdate) ClearAccount() *EmailUpdate { + eu.mutation.ClearAccount() return eu } @@ -198,12 +198,12 @@ func (eu *EmailUpdate) sqlSave(ctx context.Context) (n int, err error) { if eu.mutation.ResetCodeCleared() { _spec.ClearField(email.FieldResetCode, field.TypeString) } - if eu.mutation.AccountsCleared() { + if eu.mutation.AccountCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: email.AccountsTable, - Columns: []string{email.AccountsColumn}, + Table: email.AccountTable, + Columns: []string{email.AccountColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID), @@ -211,12 +211,12 @@ func (eu *EmailUpdate) sqlSave(ctx context.Context) (n int, err error) { } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := eu.mutation.AccountsIDs(); len(nodes) > 0 { + if nodes := eu.mutation.AccountIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: email.AccountsTable, - Columns: []string{email.AccountsColumn}, + Table: email.AccountTable, + Columns: []string{email.AccountColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID), @@ -329,23 +329,23 @@ func (euo *EmailUpdateOne) ClearResetCode() *EmailUpdateOne { return euo } -// SetAccountsID sets the "accounts" edge to the Account entity by ID. -func (euo *EmailUpdateOne) SetAccountsID(id uuid.UUID) *EmailUpdateOne { - euo.mutation.SetAccountsID(id) +// SetAccountID sets the "account" edge to the Account entity by ID. +func (euo *EmailUpdateOne) SetAccountID(id uuid.UUID) *EmailUpdateOne { + euo.mutation.SetAccountID(id) return euo } -// SetNillableAccountsID sets the "accounts" edge to the Account entity by ID if the given value is not nil. -func (euo *EmailUpdateOne) SetNillableAccountsID(id *uuid.UUID) *EmailUpdateOne { +// SetNillableAccountID sets the "account" edge to the Account entity by ID if the given value is not nil. +func (euo *EmailUpdateOne) SetNillableAccountID(id *uuid.UUID) *EmailUpdateOne { if id != nil { - euo = euo.SetAccountsID(*id) + euo = euo.SetAccountID(*id) } return euo } -// SetAccounts sets the "accounts" edge to the Account entity. -func (euo *EmailUpdateOne) SetAccounts(a *Account) *EmailUpdateOne { - return euo.SetAccountsID(a.ID) +// SetAccount sets the "account" edge to the Account entity. +func (euo *EmailUpdateOne) SetAccount(a *Account) *EmailUpdateOne { + return euo.SetAccountID(a.ID) } // Mutation returns the EmailMutation object of the builder. @@ -353,9 +353,9 @@ func (euo *EmailUpdateOne) Mutation() *EmailMutation { return euo.mutation } -// ClearAccounts clears the "accounts" edge to the Account entity. -func (euo *EmailUpdateOne) ClearAccounts() *EmailUpdateOne { - euo.mutation.ClearAccounts() +// ClearAccount clears the "account" edge to the Account entity. +func (euo *EmailUpdateOne) ClearAccount() *EmailUpdateOne { + euo.mutation.ClearAccount() return euo } @@ -446,12 +446,12 @@ func (euo *EmailUpdateOne) sqlSave(ctx context.Context) (_node *Email, err error if euo.mutation.ResetCodeCleared() { _spec.ClearField(email.FieldResetCode, field.TypeString) } - if euo.mutation.AccountsCleared() { + if euo.mutation.AccountCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: email.AccountsTable, - Columns: []string{email.AccountsColumn}, + Table: email.AccountTable, + Columns: []string{email.AccountColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID), @@ -459,12 +459,12 @@ func (euo *EmailUpdateOne) sqlSave(ctx context.Context) (_node *Email, err error } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) } - if nodes := euo.mutation.AccountsIDs(); len(nodes) > 0 { + if nodes := euo.mutation.AccountIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, - Table: email.AccountsTable, - Columns: []string{email.AccountsColumn}, + Table: email.AccountTable, + Columns: []string{email.AccountColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(account.FieldID, field.TypeUUID), diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index 6da17d9..cb98cc2 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -13,8 +13,8 @@ var ( {Name: "id", Type: field.TypeUUID, Unique: true, Default: "gen_random_uuid()"}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime}, - {Name: "nickname", Type: field.TypeString}, - {Name: "name", Type: field.TypeString}, + {Name: "nickname", Type: field.TypeString, Nullable: true}, + {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "secret", Type: field.TypeBytes}, {Name: "aes", Type: field.TypeBytes, Size: 32}, {Name: "x509", Type: field.TypeBytes}, diff --git a/ent/mutation.go b/ent/mutation.go index fa35e23..e39695b 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -259,9 +259,22 @@ func (m *AccountMutation) OldNickname(ctx context.Context) (v string, err error) return oldValue.Nickname, nil } +// ClearNickname clears the value of the "nickname" field. +func (m *AccountMutation) ClearNickname() { + m.nickname = nil + m.clearedFields[account.FieldNickname] = struct{}{} +} + +// NicknameCleared returns if the "nickname" field was cleared in this mutation. +func (m *AccountMutation) NicknameCleared() bool { + _, ok := m.clearedFields[account.FieldNickname] + return ok +} + // ResetNickname resets all changes to the "nickname" field. func (m *AccountMutation) ResetNickname() { m.nickname = nil + delete(m.clearedFields, account.FieldNickname) } // SetName sets the "name" field. @@ -295,9 +308,22 @@ func (m *AccountMutation) OldName(ctx context.Context) (v string, err error) { return oldValue.Name, nil } +// ClearName clears the value of the "name" field. +func (m *AccountMutation) ClearName() { + m.name = nil + m.clearedFields[account.FieldName] = struct{}{} +} + +// NameCleared returns if the "name" field was cleared in this mutation. +func (m *AccountMutation) NameCleared() bool { + _, ok := m.clearedFields[account.FieldName] + return ok +} + // ResetName resets all changes to the "name" field. func (m *AccountMutation) ResetName() { m.name = nil + delete(m.clearedFields, account.FieldName) } // SetSecret sets the "secret" field. @@ -650,7 +676,14 @@ func (m *AccountMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AccountMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(account.FieldNickname) { + fields = append(fields, account.FieldNickname) + } + if m.FieldCleared(account.FieldName) { + fields = append(fields, account.FieldName) + } + return fields } // FieldCleared returns a boolean indicating if a field with the given name was @@ -663,6 +696,14 @@ func (m *AccountMutation) FieldCleared(name string) bool { // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *AccountMutation) ClearField(name string) error { + switch name { + case account.FieldNickname: + m.ClearNickname() + return nil + case account.FieldName: + m.ClearName() + return nil + } return fmt.Errorf("unknown Account nullable field %s", name) } @@ -791,8 +832,8 @@ type EmailMutation struct { verification_code *string reset_code *string clearedFields map[string]struct{} - accounts *uuid.UUID - clearedaccounts bool + account *uuid.UUID + clearedaccount bool done bool oldValue func(context.Context) (*Email, error) predicates []predicate.Email @@ -1108,43 +1149,43 @@ func (m *EmailMutation) ResetResetCode() { delete(m.clearedFields, email.FieldResetCode) } -// SetAccountsID sets the "accounts" edge to the Account entity by id. -func (m *EmailMutation) SetAccountsID(id uuid.UUID) { - m.accounts = &id +// SetAccountID sets the "account" edge to the Account entity by id. +func (m *EmailMutation) SetAccountID(id uuid.UUID) { + m.account = &id } -// ClearAccounts clears the "accounts" edge to the Account entity. -func (m *EmailMutation) ClearAccounts() { - m.clearedaccounts = true +// ClearAccount clears the "account" edge to the Account entity. +func (m *EmailMutation) ClearAccount() { + m.clearedaccount = true } -// AccountsCleared reports if the "accounts" edge to the Account entity was cleared. -func (m *EmailMutation) AccountsCleared() bool { - return m.clearedaccounts +// AccountCleared reports if the "account" edge to the Account entity was cleared. +func (m *EmailMutation) AccountCleared() bool { + return m.clearedaccount } -// AccountsID returns the "accounts" edge ID in the mutation. -func (m *EmailMutation) AccountsID() (id uuid.UUID, exists bool) { - if m.accounts != nil { - return *m.accounts, true +// AccountID returns the "account" edge ID in the mutation. +func (m *EmailMutation) AccountID() (id uuid.UUID, exists bool) { + if m.account != nil { + return *m.account, true } return } -// AccountsIDs returns the "accounts" edge IDs in the mutation. +// AccountIDs returns the "account" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// AccountsID instead. It exists only for internal usage by the builders. -func (m *EmailMutation) AccountsIDs() (ids []uuid.UUID) { - if id := m.accounts; id != nil { +// AccountID instead. It exists only for internal usage by the builders. +func (m *EmailMutation) AccountIDs() (ids []uuid.UUID) { + if id := m.account; id != nil { ids = append(ids, *id) } return } -// ResetAccounts resets all changes to the "accounts" edge. -func (m *EmailMutation) ResetAccounts() { - m.accounts = nil - m.clearedaccounts = false +// ResetAccount resets all changes to the "account" edge. +func (m *EmailMutation) ResetAccount() { + m.account = nil + m.clearedaccount = false } // Where appends a list predicates to the EmailMutation builder. @@ -1364,8 +1405,8 @@ func (m *EmailMutation) ResetField(name string) error { // AddedEdges returns all edge names that were set/added in this mutation. func (m *EmailMutation) AddedEdges() []string { edges := make([]string, 0, 1) - if m.accounts != nil { - edges = append(edges, email.EdgeAccounts) + if m.account != nil { + edges = append(edges, email.EdgeAccount) } return edges } @@ -1374,8 +1415,8 @@ func (m *EmailMutation) AddedEdges() []string { // name in this mutation. func (m *EmailMutation) AddedIDs(name string) []ent.Value { switch name { - case email.EdgeAccounts: - if id := m.accounts; id != nil { + case email.EdgeAccount: + if id := m.account; id != nil { return []ent.Value{*id} } } @@ -1397,8 +1438,8 @@ func (m *EmailMutation) RemovedIDs(name string) []ent.Value { // ClearedEdges returns all edge names that were cleared in this mutation. func (m *EmailMutation) ClearedEdges() []string { edges := make([]string, 0, 1) - if m.clearedaccounts { - edges = append(edges, email.EdgeAccounts) + if m.clearedaccount { + edges = append(edges, email.EdgeAccount) } return edges } @@ -1407,8 +1448,8 @@ func (m *EmailMutation) ClearedEdges() []string { // was cleared in this mutation. func (m *EmailMutation) EdgeCleared(name string) bool { switch name { - case email.EdgeAccounts: - return m.clearedaccounts + case email.EdgeAccount: + return m.clearedaccount } return false } @@ -1417,8 +1458,8 @@ func (m *EmailMutation) EdgeCleared(name string) bool { // if that edge is not defined in the schema. func (m *EmailMutation) ClearEdge(name string) error { switch name { - case email.EdgeAccounts: - m.ClearAccounts() + case email.EdgeAccount: + m.ClearAccount() return nil } return fmt.Errorf("unknown Email unique edge %s", name) @@ -1428,8 +1469,8 @@ func (m *EmailMutation) ClearEdge(name string) error { // It returns an error if the edge is not defined in the schema. func (m *EmailMutation) ResetEdge(name string) error { switch name { - case email.EdgeAccounts: - m.ResetAccounts() + case email.EdgeAccount: + m.ResetAccount() return nil } return fmt.Errorf("unknown Email edge %s", name) diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index 138e903..d2c8695 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in code.icod.de/auth/accountserver/ent/runtime.go const ( - Version = "v0.14.0" // Version of ent codegen. - Sum = "h1:EO3Z9aZ5bXJatJeGqu/EVdnNr6K4mRq3rWe5owt0MC4=" // Sum of ent codegen. + Version = "v0.14.1" // Version of ent codegen. + Sum = "h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s=" // Sum of ent codegen. ) diff --git a/ent/schema/account.go b/ent/schema/account.go index 219b348..7d490f2 100644 --- a/ent/schema/account.go +++ b/ent/schema/account.go @@ -20,8 +20,8 @@ func (Account) Fields() []ent.Field { field.UUID("id", uuid.UUID{}).Unique().Immutable().Annotations(&entsql.Annotation{Default: "gen_random_uuid()"}), field.Time("created_at").Default(time.Now).Immutable(), field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now), - field.String("nickname"), - field.String("name"), + field.String("nickname").Optional(), + field.String("name").Optional(), field.Bytes("secret"), field.Bytes("aes").MinLen(16).MaxLen(32), field.Bytes("x509"), diff --git a/ent/schema/email.go b/ent/schema/email.go index e06ed36..643ac2b 100644 --- a/ent/schema/email.go +++ b/ent/schema/email.go @@ -28,6 +28,6 @@ func (Email) Fields() []ent.Field { // Edges of the Email. func (Email) Edges() []ent.Edge { return []ent.Edge{ - edge.From("accounts", Account.Type).Ref("emails").Unique(), + edge.From("account", Account.Type).Ref("emails").Unique(), } } diff --git a/go.mod b/go.mod index b2bb87c..385e412 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,30 @@ module code.icod.de/auth/accountserver go 1.23.0 require ( - entgo.io/ent v0.14.0 - github.com/google/uuid v1.3.0 + entgo.io/ent v0.14.1 + github.com/google/uuid v1.6.0 github.com/spf13/cobra v1.8.1 ) require ( + ariga.io/atlas v0.27.0 // indirect + github.com/agext/levenshtein v1.2.3 // indirect + github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/go-openapi/inflect v0.21.0 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/hashicorp/hcl/v2 v2.22.0 // indirect github.com/idc77/gomail v0.0.0-20240819113050-ac97008b42eb // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/matthewhartstonge/argon2 v1.0.1-0.20240808062706-62179c3b7f7d // indirect + github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/zclconf/go-cty v1.15.0 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect + golang.org/x/tools v0.24.0 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect ) diff --git a/go.sum b/go.sum index 827e25a..c5327a9 100644 --- a/go.sum +++ b/go.sum @@ -1,30 +1,52 @@ ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrlIISQ4JTH1mRWuE5ZZ14= ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU= +ariga.io/atlas v0.27.0 h1:UHUQMTRx2Vz8/acJxEfcC/zL2wY739/vkZzt7L8HL8I= +ariga.io/atlas v0.27.0/go.mod h1:KPLc7Zj+nzoXfWshrcY1RwlOh94dsATQEy4UPrF2RkM= entgo.io/ent v0.14.0 h1:EO3Z9aZ5bXJatJeGqu/EVdnNr6K4mRq3rWe5owt0MC4= entgo.io/ent v0.14.0/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A= +entgo.io/ent v0.14.1 h1:fUERL506Pqr92EPHJqr8EYxbPioflJo6PudkrEA8a/s= +entgo.io/ent v0.14.1/go.mod h1:MH6XLG0KXpkcDQhKiHfANZSzR55TJyPL5IGNpI8wpco= github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= +github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= +github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= +github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= +github.com/go-openapi/inflect v0.21.0 h1:FoBjBTQEcbg2cJUWX6uwL9OyIW8eqc9k4KhN4lfbeYk= +github.com/go-openapi/inflect v0.21.0/go.mod h1:INezMuUu7SJQc2AyR3WO0DqqYUJSj8Kb4hBd7WtjlAw= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc= github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= +github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= +github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/idc77/gomail v0.0.0-20240819113050-ac97008b42eb h1:eoCCdEgNvIAO3+sb7drW2gV36JOkILxyJllfEUHoo1A= github.com/idc77/gomail v0.0.0-20240819113050-ac97008b42eb/go.mod h1:iRMDvqBOUICvDAsSzKcIBfFLghLJ1EeXBe6tH7Mmv6U= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/matthewhartstonge/argon2 v0.2.1 h1:DFzhPfXcKv4T/ITjoTtEDE/WP1G2eutQBntAzKPtXtc= +github.com/matthewhartstonge/argon2 v0.2.1/go.mod h1:k3jqoN+y0w9Z6uJxIKiJDveAMDUaIBJkC/M2m37q6VM= +github.com/matthewhartstonge/argon2 v1.0.0 h1:e65fkae6O8Na6YTy2HAccUbXR+GQHOnpQxeWGqWCRIw= +github.com/matthewhartstonge/argon2 v1.0.0/go.mod h1:Fm4FHZxdxCM6hg21Jkz3YZVKnU7VnTlqDQ3ghS/Myok= +github.com/matthewhartstonge/argon2 v1.0.1-0.20240808062706-62179c3b7f7d h1:hC2uziFpDurWy5AkRw4rvvwWKtCE8bitk8j1hi46u9Q= +github.com/matthewhartstonge/argon2 v1.0.1-0.20240808062706-62179c3b7f7d/go.mod h1:n7RqvFKNEe5liRkiltnbmRiKGYUzPkNqzg1pBrmnDIs= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= +github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -38,14 +60,30 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/zclconf/go-cty v1.8.0 h1:s4AvqaeQzJIu3ndv4gVIhplVD0krU+bgrcLSVUnaWuA= github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= +github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= +github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= +golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk= gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/service/account.go b/service/account.go index 6bf63b2..11fa209 100644 --- a/service/account.go +++ b/service/account.go @@ -1,8 +1,60 @@ package service -type CreateAccountInput struct{} +import ( + "code.icod.de/auth/accountserver/util" + "context" + "errors" + "github.com/matthewhartstonge/argon2" +) + +type CreateAccountInput struct { + Name string `json:"name,omitempty"` + Nickname string `json:"nickname,omitempty"` + Email string `json:"email"` + Secret string `json:"secret"` +} // CreateAccount creates an account, returns nil if successful or error if not func (s *Service) CreateAccount(in *CreateAccountInput) error { + // hash the secret with argon2 + argon := argon2.DefaultConfig() + encoded, e := argon.HashEncoded([]byte(in.Secret)) + if e != nil { + return errors.New("create account: could not encode secret: " + e.Error()) + } + + // generate aes key + k := util.GenerateRandomKey(32) + + create := s.client.Account.Create() + create = create.SetSecret(encoded) + create = create.SetAes(k) + if in.Name != "" { + create = create.SetName(in.Name) + } + if in.Nickname != "" { + create = create.SetNickname(in.Nickname) + } + a, e := create.Save(context.Background()) + if e != nil { + return errors.New("create account: could not save account to database" + e.Error()) + } + cei := new(CreateEmailInput) + cei.Account = a + cei.Email = in.Email + cei.Primary = true + return s.CreateEmail(cei) +} + +type ReplaceAccountInput struct{} + +// ReplaceAccount updates, replaces an account. +func (s *Service) ReplaceAccount(input *ReplaceAccountInput) error { + panic("implement me") +} + +type DeleteAccountInput struct{} + +func (s *Service) DeleteAccount(input *DeleteAccountInput) error { panic("implement me") } diff --git a/service/email.go b/service/email.go index 6d43c33..2126fee 100644 --- a/service/email.go +++ b/service/email.go @@ -1 +1,25 @@ package service + +import ( + "code.icod.de/auth/accountserver/ent" + "context" + "errors" +) + +type CreateEmailInput struct { + Account *ent.Account + Primary bool + Email string +} + +func (s *Service) CreateEmail(in *CreateEmailInput) error { + create := s.client.Email.Create() + create.SetEmail(in.Email) + create.SetPrimary(in.Primary) + create.SetAccount(in.Account) + _, e := create.Save(context.Background()) + if e != nil { + return errors.New("create email: failed to save to database: " + e.Error()) + } + return nil +} diff --git a/util/random.go b/util/random.go new file mode 100644 index 0000000..6c9debd --- /dev/null +++ b/util/random.go @@ -0,0 +1,14 @@ +package util + +import ( + "crypto/rand" + "io" +) + +func GenerateRandomKey(length int) []byte { + k := make([]byte, length) + if _, err := io.ReadFull(rand.Reader, k); err != nil { + return nil + } + return k +}