Renamed hash field to token.
This commit is contained in:
parent
cb5c3ad127
commit
dae9ea3ae1
14 changed files with 136 additions and 137 deletions
|
|
@ -91,8 +91,8 @@ func (h *Handler) PasswordTokenCreate(ctx echo.Context) error {
|
|||
}
|
||||
|
||||
op := h.client.PasswordToken.Create()
|
||||
if payload.Hash != nil {
|
||||
op.SetHash(*payload.Hash)
|
||||
if payload.Token != nil {
|
||||
op.SetToken(*payload.Token)
|
||||
}
|
||||
op.SetUserID(payload.UserID)
|
||||
if payload.CreatedAt != nil {
|
||||
|
|
@ -114,8 +114,8 @@ func (h *Handler) PasswordTokenUpdate(ctx echo.Context, id int) error {
|
|||
}
|
||||
|
||||
op := entity.Update()
|
||||
if payload.Hash != nil {
|
||||
op.SetHash(*payload.Hash)
|
||||
if payload.Token != nil {
|
||||
op.SetToken(*payload.Token)
|
||||
}
|
||||
op.SetUserID(payload.UserID)
|
||||
if payload.CreatedAt == nil {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ package admin
|
|||
import "time"
|
||||
|
||||
type PasswordToken struct {
|
||||
Hash *string `form:"hash"`
|
||||
Token *string `form:"token"`
|
||||
UserID int `form:"user_id"`
|
||||
CreatedAt *time.Time `form:"created_at"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ var (
|
|||
// PasswordTokensColumns holds the columns for the "password_tokens" table.
|
||||
PasswordTokensColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "hash", Type: field.TypeString},
|
||||
{Name: "token", Type: field.TypeString},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "user_id", Type: field.TypeInt},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ type PasswordTokenMutation struct {
|
|||
op Op
|
||||
typ string
|
||||
id *int
|
||||
hash *string
|
||||
token *string
|
||||
created_at *time.Time
|
||||
clearedFields map[string]struct{}
|
||||
user *int
|
||||
|
|
@ -143,40 +143,40 @@ func (m *PasswordTokenMutation) IDs(ctx context.Context) ([]int, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (m *PasswordTokenMutation) SetHash(s string) {
|
||||
m.hash = &s
|
||||
// SetToken sets the "token" field.
|
||||
func (m *PasswordTokenMutation) SetToken(s string) {
|
||||
m.token = &s
|
||||
}
|
||||
|
||||
// Hash returns the value of the "hash" field in the mutation.
|
||||
func (m *PasswordTokenMutation) Hash() (r string, exists bool) {
|
||||
v := m.hash
|
||||
// Token returns the value of the "token" field in the mutation.
|
||||
func (m *PasswordTokenMutation) Token() (r string, exists bool) {
|
||||
v := m.token
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldHash returns the old "hash" field's value of the PasswordToken entity.
|
||||
// OldToken returns the old "token" field's value of the PasswordToken entity.
|
||||
// If the PasswordToken object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *PasswordTokenMutation) OldHash(ctx context.Context) (v string, err error) {
|
||||
func (m *PasswordTokenMutation) OldToken(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldHash is only allowed on UpdateOne operations")
|
||||
return v, errors.New("OldToken is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldHash requires an ID field in the mutation")
|
||||
return v, errors.New("OldToken requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldHash: %w", err)
|
||||
return v, fmt.Errorf("querying old value for OldToken: %w", err)
|
||||
}
|
||||
return oldValue.Hash, nil
|
||||
return oldValue.Token, nil
|
||||
}
|
||||
|
||||
// ResetHash resets all changes to the "hash" field.
|
||||
func (m *PasswordTokenMutation) ResetHash() {
|
||||
m.hash = nil
|
||||
// ResetToken resets all changes to the "token" field.
|
||||
func (m *PasswordTokenMutation) ResetToken() {
|
||||
m.token = nil
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
|
|
@ -313,8 +313,8 @@ func (m *PasswordTokenMutation) Type() string {
|
|||
// AddedFields().
|
||||
func (m *PasswordTokenMutation) Fields() []string {
|
||||
fields := make([]string, 0, 3)
|
||||
if m.hash != nil {
|
||||
fields = append(fields, passwordtoken.FieldHash)
|
||||
if m.token != nil {
|
||||
fields = append(fields, passwordtoken.FieldToken)
|
||||
}
|
||||
if m.user != nil {
|
||||
fields = append(fields, passwordtoken.FieldUserID)
|
||||
|
|
@ -330,8 +330,8 @@ func (m *PasswordTokenMutation) Fields() []string {
|
|||
// schema.
|
||||
func (m *PasswordTokenMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case passwordtoken.FieldHash:
|
||||
return m.Hash()
|
||||
case passwordtoken.FieldToken:
|
||||
return m.Token()
|
||||
case passwordtoken.FieldUserID:
|
||||
return m.UserID()
|
||||
case passwordtoken.FieldCreatedAt:
|
||||
|
|
@ -345,8 +345,8 @@ func (m *PasswordTokenMutation) Field(name string) (ent.Value, bool) {
|
|||
// database failed.
|
||||
func (m *PasswordTokenMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case passwordtoken.FieldHash:
|
||||
return m.OldHash(ctx)
|
||||
case passwordtoken.FieldToken:
|
||||
return m.OldToken(ctx)
|
||||
case passwordtoken.FieldUserID:
|
||||
return m.OldUserID(ctx)
|
||||
case passwordtoken.FieldCreatedAt:
|
||||
|
|
@ -360,12 +360,12 @@ func (m *PasswordTokenMutation) OldField(ctx context.Context, name string) (ent.
|
|||
// type.
|
||||
func (m *PasswordTokenMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case passwordtoken.FieldHash:
|
||||
case passwordtoken.FieldToken:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetHash(v)
|
||||
m.SetToken(v)
|
||||
return nil
|
||||
case passwordtoken.FieldUserID:
|
||||
v, ok := value.(int)
|
||||
|
|
@ -433,8 +433,8 @@ func (m *PasswordTokenMutation) ClearField(name string) error {
|
|||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *PasswordTokenMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case passwordtoken.FieldHash:
|
||||
m.ResetHash()
|
||||
case passwordtoken.FieldToken:
|
||||
m.ResetToken()
|
||||
return nil
|
||||
case passwordtoken.FieldUserID:
|
||||
m.ResetUserID()
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ type PasswordToken struct {
|
|||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Hash holds the value of the "hash" field.
|
||||
Hash string `json:"-"`
|
||||
// Token holds the value of the "token" field.
|
||||
Token string `json:"-"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID int `json:"user_id,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
|
|
@ -57,7 +57,7 @@ func (*PasswordToken) scanValues(columns []string) ([]any, error) {
|
|||
switch columns[i] {
|
||||
case passwordtoken.FieldID, passwordtoken.FieldUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case passwordtoken.FieldHash:
|
||||
case passwordtoken.FieldToken:
|
||||
values[i] = new(sql.NullString)
|
||||
case passwordtoken.FieldCreatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
|
|
@ -82,11 +82,11 @@ func (pt *PasswordToken) assignValues(columns []string, values []any) error {
|
|||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
pt.ID = int(value.Int64)
|
||||
case passwordtoken.FieldHash:
|
||||
case passwordtoken.FieldToken:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field hash", values[i])
|
||||
return fmt.Errorf("unexpected type %T for field token", values[i])
|
||||
} else if value.Valid {
|
||||
pt.Hash = value.String
|
||||
pt.Token = value.String
|
||||
}
|
||||
case passwordtoken.FieldUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
|
|
@ -141,7 +141,7 @@ func (pt *PasswordToken) String() string {
|
|||
var builder strings.Builder
|
||||
builder.WriteString("PasswordToken(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", pt.ID))
|
||||
builder.WriteString("hash=<sensitive>")
|
||||
builder.WriteString("token=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", pt.UserID))
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ const (
|
|||
Label = "password_token"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldHash holds the string denoting the hash field in the database.
|
||||
FieldHash = "hash"
|
||||
// FieldToken holds the string denoting the token field in the database.
|
||||
FieldToken = "token"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
|
|
@ -37,7 +37,7 @@ const (
|
|||
// Columns holds all SQL columns for passwordtoken fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldHash,
|
||||
FieldToken,
|
||||
FieldUserID,
|
||||
FieldCreatedAt,
|
||||
}
|
||||
|
|
@ -59,8 +59,8 @@ func ValidColumn(column string) bool {
|
|||
// import _ "github.com/mikestefanello/pagoda/ent/runtime"
|
||||
var (
|
||||
Hooks [1]ent.Hook
|
||||
// HashValidator is a validator for the "hash" field. It is called by the builders before save.
|
||||
HashValidator func(string) error
|
||||
// TokenValidator is a validator for the "token" field. It is called by the builders before save.
|
||||
TokenValidator func(string) error
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
)
|
||||
|
|
@ -73,9 +73,9 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
|
|||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHash orders the results by the hash field.
|
||||
func ByHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHash, opts...).ToFunc()
|
||||
// ByToken orders the results by the token field.
|
||||
func ByToken(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldToken, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserID orders the results by the user_id field.
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ func IDLTE(id int) predicate.PasswordToken {
|
|||
return predicate.PasswordToken(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Hash applies equality check predicate on the "hash" field. It's identical to HashEQ.
|
||||
func Hash(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldHash, v))
|
||||
// Token applies equality check predicate on the "token" field. It's identical to TokenEQ.
|
||||
func Token(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldToken, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
|
|
@ -70,69 +70,69 @@ func CreatedAt(v time.Time) predicate.PasswordToken {
|
|||
return predicate.PasswordToken(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// HashEQ applies the EQ predicate on the "hash" field.
|
||||
func HashEQ(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldHash, v))
|
||||
// TokenEQ applies the EQ predicate on the "token" field.
|
||||
func TokenEQ(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldEQ(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashNEQ applies the NEQ predicate on the "hash" field.
|
||||
func HashNEQ(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldNEQ(FieldHash, v))
|
||||
// TokenNEQ applies the NEQ predicate on the "token" field.
|
||||
func TokenNEQ(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldNEQ(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashIn applies the In predicate on the "hash" field.
|
||||
func HashIn(vs ...string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldIn(FieldHash, vs...))
|
||||
// TokenIn applies the In predicate on the "token" field.
|
||||
func TokenIn(vs ...string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldIn(FieldToken, vs...))
|
||||
}
|
||||
|
||||
// HashNotIn applies the NotIn predicate on the "hash" field.
|
||||
func HashNotIn(vs ...string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldNotIn(FieldHash, vs...))
|
||||
// TokenNotIn applies the NotIn predicate on the "token" field.
|
||||
func TokenNotIn(vs ...string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldNotIn(FieldToken, vs...))
|
||||
}
|
||||
|
||||
// HashGT applies the GT predicate on the "hash" field.
|
||||
func HashGT(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldGT(FieldHash, v))
|
||||
// TokenGT applies the GT predicate on the "token" field.
|
||||
func TokenGT(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldGT(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashGTE applies the GTE predicate on the "hash" field.
|
||||
func HashGTE(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldGTE(FieldHash, v))
|
||||
// TokenGTE applies the GTE predicate on the "token" field.
|
||||
func TokenGTE(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldGTE(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashLT applies the LT predicate on the "hash" field.
|
||||
func HashLT(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldLT(FieldHash, v))
|
||||
// TokenLT applies the LT predicate on the "token" field.
|
||||
func TokenLT(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldLT(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashLTE applies the LTE predicate on the "hash" field.
|
||||
func HashLTE(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldLTE(FieldHash, v))
|
||||
// TokenLTE applies the LTE predicate on the "token" field.
|
||||
func TokenLTE(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldLTE(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashContains applies the Contains predicate on the "hash" field.
|
||||
func HashContains(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldContains(FieldHash, v))
|
||||
// TokenContains applies the Contains predicate on the "token" field.
|
||||
func TokenContains(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldContains(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashHasPrefix applies the HasPrefix predicate on the "hash" field.
|
||||
func HashHasPrefix(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldHasPrefix(FieldHash, v))
|
||||
// TokenHasPrefix applies the HasPrefix predicate on the "token" field.
|
||||
func TokenHasPrefix(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldHasPrefix(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashHasSuffix applies the HasSuffix predicate on the "hash" field.
|
||||
func HashHasSuffix(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldHasSuffix(FieldHash, v))
|
||||
// TokenHasSuffix applies the HasSuffix predicate on the "token" field.
|
||||
func TokenHasSuffix(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldHasSuffix(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashEqualFold applies the EqualFold predicate on the "hash" field.
|
||||
func HashEqualFold(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldEqualFold(FieldHash, v))
|
||||
// TokenEqualFold applies the EqualFold predicate on the "token" field.
|
||||
func TokenEqualFold(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldEqualFold(FieldToken, v))
|
||||
}
|
||||
|
||||
// HashContainsFold applies the ContainsFold predicate on the "hash" field.
|
||||
func HashContainsFold(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldContainsFold(FieldHash, v))
|
||||
// TokenContainsFold applies the ContainsFold predicate on the "token" field.
|
||||
func TokenContainsFold(v string) predicate.PasswordToken {
|
||||
return predicate.PasswordToken(sql.FieldContainsFold(FieldToken, v))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ type PasswordTokenCreate struct {
|
|||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (ptc *PasswordTokenCreate) SetHash(s string) *PasswordTokenCreate {
|
||||
ptc.mutation.SetHash(s)
|
||||
// SetToken sets the "token" field.
|
||||
func (ptc *PasswordTokenCreate) SetToken(s string) *PasswordTokenCreate {
|
||||
ptc.mutation.SetToken(s)
|
||||
return ptc
|
||||
}
|
||||
|
||||
|
|
@ -101,12 +101,12 @@ func (ptc *PasswordTokenCreate) defaults() error {
|
|||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ptc *PasswordTokenCreate) check() error {
|
||||
if _, ok := ptc.mutation.Hash(); !ok {
|
||||
return &ValidationError{Name: "hash", err: errors.New(`ent: missing required field "PasswordToken.hash"`)}
|
||||
if _, ok := ptc.mutation.Token(); !ok {
|
||||
return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "PasswordToken.token"`)}
|
||||
}
|
||||
if v, ok := ptc.mutation.Hash(); ok {
|
||||
if err := passwordtoken.HashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "hash", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.hash": %w`, err)}
|
||||
if v, ok := ptc.mutation.Token(); ok {
|
||||
if err := passwordtoken.TokenValidator(v); err != nil {
|
||||
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.token": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := ptc.mutation.UserID(); !ok {
|
||||
|
|
@ -144,9 +144,9 @@ func (ptc *PasswordTokenCreate) createSpec() (*PasswordToken, *sqlgraph.CreateSp
|
|||
_node = &PasswordToken{config: ptc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(passwordtoken.Table, sqlgraph.NewFieldSpec(passwordtoken.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := ptc.mutation.Hash(); ok {
|
||||
_spec.SetField(passwordtoken.FieldHash, field.TypeString, value)
|
||||
_node.Hash = value
|
||||
if value, ok := ptc.mutation.Token(); ok {
|
||||
_spec.SetField(passwordtoken.FieldToken, field.TypeString, value)
|
||||
_node.Token = value
|
||||
}
|
||||
if value, ok := ptc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(passwordtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
|
|
|
|||
|
|
@ -298,12 +298,12 @@ func (ptq *PasswordTokenQuery) WithUser(opts ...func(*UserQuery)) *PasswordToken
|
|||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Hash string `json:"hash,omitempty"`
|
||||
// Token string `json:"token,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.PasswordToken.Query().
|
||||
// GroupBy(passwordtoken.FieldHash).
|
||||
// GroupBy(passwordtoken.FieldToken).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (ptq *PasswordTokenQuery) GroupBy(field string, fields ...string) *PasswordTokenGroupBy {
|
||||
|
|
@ -321,11 +321,11 @@ func (ptq *PasswordTokenQuery) GroupBy(field string, fields ...string) *Password
|
|||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Hash string `json:"hash,omitempty"`
|
||||
// Token string `json:"token,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.PasswordToken.Query().
|
||||
// Select(passwordtoken.FieldHash).
|
||||
// Select(passwordtoken.FieldToken).
|
||||
// Scan(ctx, &v)
|
||||
func (ptq *PasswordTokenQuery) Select(fields ...string) *PasswordTokenSelect {
|
||||
ptq.ctx.Fields = append(ptq.ctx.Fields, fields...)
|
||||
|
|
|
|||
|
|
@ -29,16 +29,16 @@ func (ptu *PasswordTokenUpdate) Where(ps ...predicate.PasswordToken) *PasswordTo
|
|||
return ptu
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (ptu *PasswordTokenUpdate) SetHash(s string) *PasswordTokenUpdate {
|
||||
ptu.mutation.SetHash(s)
|
||||
// SetToken sets the "token" field.
|
||||
func (ptu *PasswordTokenUpdate) SetToken(s string) *PasswordTokenUpdate {
|
||||
ptu.mutation.SetToken(s)
|
||||
return ptu
|
||||
}
|
||||
|
||||
// SetNillableHash sets the "hash" field if the given value is not nil.
|
||||
func (ptu *PasswordTokenUpdate) SetNillableHash(s *string) *PasswordTokenUpdate {
|
||||
// SetNillableToken sets the "token" field if the given value is not nil.
|
||||
func (ptu *PasswordTokenUpdate) SetNillableToken(s *string) *PasswordTokenUpdate {
|
||||
if s != nil {
|
||||
ptu.SetHash(*s)
|
||||
ptu.SetToken(*s)
|
||||
}
|
||||
return ptu
|
||||
}
|
||||
|
|
@ -116,9 +116,9 @@ func (ptu *PasswordTokenUpdate) ExecX(ctx context.Context) {
|
|||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ptu *PasswordTokenUpdate) check() error {
|
||||
if v, ok := ptu.mutation.Hash(); ok {
|
||||
if err := passwordtoken.HashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "hash", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.hash": %w`, err)}
|
||||
if v, ok := ptu.mutation.Token(); ok {
|
||||
if err := passwordtoken.TokenValidator(v); err != nil {
|
||||
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.token": %w`, err)}
|
||||
}
|
||||
}
|
||||
if ptu.mutation.UserCleared() && len(ptu.mutation.UserIDs()) > 0 {
|
||||
|
|
@ -139,8 +139,8 @@ func (ptu *PasswordTokenUpdate) sqlSave(ctx context.Context) (n int, err error)
|
|||
}
|
||||
}
|
||||
}
|
||||
if value, ok := ptu.mutation.Hash(); ok {
|
||||
_spec.SetField(passwordtoken.FieldHash, field.TypeString, value)
|
||||
if value, ok := ptu.mutation.Token(); ok {
|
||||
_spec.SetField(passwordtoken.FieldToken, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ptu.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(passwordtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
|
|
@ -194,16 +194,16 @@ type PasswordTokenUpdateOne struct {
|
|||
mutation *PasswordTokenMutation
|
||||
}
|
||||
|
||||
// SetHash sets the "hash" field.
|
||||
func (ptuo *PasswordTokenUpdateOne) SetHash(s string) *PasswordTokenUpdateOne {
|
||||
ptuo.mutation.SetHash(s)
|
||||
// SetToken sets the "token" field.
|
||||
func (ptuo *PasswordTokenUpdateOne) SetToken(s string) *PasswordTokenUpdateOne {
|
||||
ptuo.mutation.SetToken(s)
|
||||
return ptuo
|
||||
}
|
||||
|
||||
// SetNillableHash sets the "hash" field if the given value is not nil.
|
||||
func (ptuo *PasswordTokenUpdateOne) SetNillableHash(s *string) *PasswordTokenUpdateOne {
|
||||
// SetNillableToken sets the "token" field if the given value is not nil.
|
||||
func (ptuo *PasswordTokenUpdateOne) SetNillableToken(s *string) *PasswordTokenUpdateOne {
|
||||
if s != nil {
|
||||
ptuo.SetHash(*s)
|
||||
ptuo.SetToken(*s)
|
||||
}
|
||||
return ptuo
|
||||
}
|
||||
|
|
@ -294,9 +294,9 @@ func (ptuo *PasswordTokenUpdateOne) ExecX(ctx context.Context) {
|
|||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (ptuo *PasswordTokenUpdateOne) check() error {
|
||||
if v, ok := ptuo.mutation.Hash(); ok {
|
||||
if err := passwordtoken.HashValidator(v); err != nil {
|
||||
return &ValidationError{Name: "hash", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.hash": %w`, err)}
|
||||
if v, ok := ptuo.mutation.Token(); ok {
|
||||
if err := passwordtoken.TokenValidator(v); err != nil {
|
||||
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "PasswordToken.token": %w`, err)}
|
||||
}
|
||||
}
|
||||
if ptuo.mutation.UserCleared() && len(ptuo.mutation.UserIDs()) > 0 {
|
||||
|
|
@ -334,8 +334,8 @@ func (ptuo *PasswordTokenUpdateOne) sqlSave(ctx context.Context) (_node *Passwor
|
|||
}
|
||||
}
|
||||
}
|
||||
if value, ok := ptuo.mutation.Hash(); ok {
|
||||
_spec.SetField(passwordtoken.FieldHash, field.TypeString, value)
|
||||
if value, ok := ptuo.mutation.Token(); ok {
|
||||
_spec.SetField(passwordtoken.FieldToken, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ptuo.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(passwordtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ func init() {
|
|||
passwordtoken.Hooks[0] = passwordtokenHooks[0]
|
||||
passwordtokenFields := schema.PasswordToken{}.Fields()
|
||||
_ = passwordtokenFields
|
||||
// passwordtokenDescHash is the schema descriptor for hash field.
|
||||
passwordtokenDescHash := passwordtokenFields[0].Descriptor()
|
||||
// passwordtoken.HashValidator is a validator for the "hash" field. It is called by the builders before save.
|
||||
passwordtoken.HashValidator = passwordtokenDescHash.Validators[0].(func(string) error)
|
||||
// passwordtokenDescToken is the schema descriptor for token field.
|
||||
passwordtokenDescToken := passwordtokenFields[0].Descriptor()
|
||||
// passwordtoken.TokenValidator is a validator for the "token" field. It is called by the builders before save.
|
||||
passwordtoken.TokenValidator = passwordtokenDescToken.Validators[0].(func(string) error)
|
||||
// passwordtokenDescCreatedAt is the schema descriptor for created_at field.
|
||||
passwordtokenDescCreatedAt := passwordtokenFields[2].Descriptor()
|
||||
// passwordtoken.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ type PasswordToken struct {
|
|||
// Fields of the PasswordToken.
|
||||
func (PasswordToken) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
// TODO rename to Token
|
||||
field.String("hash").
|
||||
field.String("token").
|
||||
Sensitive().
|
||||
NotEmpty(),
|
||||
field.Int("user_id"),
|
||||
|
|
@ -46,12 +45,12 @@ func (PasswordToken) Hooks() []ent.Hook {
|
|||
hook.On(
|
||||
func(next ent.Mutator) ent.Mutator {
|
||||
return hook.PasswordTokenFunc(func(ctx context.Context, m *ge.PasswordTokenMutation) (ent.Value, error) {
|
||||
if v, exists := m.Hash(); exists {
|
||||
if v, exists := m.Token(); exists {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(v), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
m.SetHash(string(hash))
|
||||
m.SetToken(string(hash))
|
||||
}
|
||||
return next.Mutate(ctx, m)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ func (c *AuthClient) GeneratePasswordResetToken(ctx echo.Context, userID int) (s
|
|||
// Create and save the password reset token
|
||||
pt, err := c.orm.PasswordToken.
|
||||
Create().
|
||||
SetHash(token).
|
||||
SetToken(token).
|
||||
SetUserID(userID).
|
||||
Save(ctx.Request().Context())
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ func (c *AuthClient) GetValidPasswordToken(ctx echo.Context, userID, tokenID int
|
|||
case *ent.NotFoundError:
|
||||
case nil:
|
||||
// Check the token for a hash match
|
||||
if err := c.CheckPassword(token, pt.Hash); err == nil {
|
||||
if err := c.CheckPassword(token, pt.Token); err == nil {
|
||||
return pt, nil
|
||||
}
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"entgo.io/ent/schema/field"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/mikestefanello/pagoda/ent/admin"
|
||||
"github.com/mikestefanello/pagoda/pkg/pager"
|
||||
"github.com/mikestefanello/pagoda/pkg/pager" // todo make this easier
|
||||
"github.com/mikestefanello/pagoda/pkg/routenames"
|
||||
"github.com/mikestefanello/pagoda/pkg/ui"
|
||||
. "github.com/mikestefanello/pagoda/pkg/ui/components"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue