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