Added email field to user.
This commit is contained in:
parent
dee7a13cba
commit
6ec1b77684
16 changed files with 410 additions and 139 deletions
8
Makefile
8
Makefile
|
|
@ -1,9 +1,9 @@
|
||||||
.PHONY: pg
|
.PHONY: db
|
||||||
pg:
|
db:
|
||||||
psql postgresql://admin:admin@localhost:5432/app
|
psql postgresql://admin:admin@localhost:5432/app
|
||||||
|
|
||||||
.PHONY: pg-test
|
.PHONY: db-test
|
||||||
pg-test:
|
db-test:
|
||||||
psql postgresql://admin:admin@localhost:5432/app_test
|
psql postgresql://admin:admin@localhost:5432/app_test
|
||||||
|
|
||||||
.PHONY: ent-gen
|
.PHONY: ent-gen
|
||||||
|
|
|
||||||
|
|
@ -173,11 +173,15 @@ func (t *Controller) SetValidationErrorMessages(c echo.Context, err error, data
|
||||||
switch ve.Tag() {
|
switch ve.Tag() {
|
||||||
case "required":
|
case "required":
|
||||||
message = "%s is required."
|
message = "%s is required."
|
||||||
|
case "email":
|
||||||
|
message = "%s must be a valid email address."
|
||||||
|
case "eqfield":
|
||||||
|
message = "%s must match."
|
||||||
default:
|
default:
|
||||||
message = "%s is not a valid value."
|
message = "%s is not a valid value."
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Danger(c, fmt.Sprintf(message, label))
|
msg.Danger(c, fmt.Sprintf(message, "<strong>"+label+"</strong>"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ var (
|
||||||
// UsersColumns holds the columns for the "users" table.
|
// UsersColumns holds the columns for the "users" table.
|
||||||
UsersColumns = []*schema.Column{
|
UsersColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
{Name: "username", Type: field.TypeString, Unique: true},
|
{Name: "name", Type: field.TypeString},
|
||||||
|
{Name: "email", Type: field.TypeString, Unique: true},
|
||||||
{Name: "password", Type: field.TypeString},
|
{Name: "password", Type: field.TypeString},
|
||||||
{Name: "created_at", Type: field.TypeTime},
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
108
ent/mutation.go
108
ent/mutation.go
|
|
@ -31,7 +31,8 @@ type UserMutation struct {
|
||||||
op Op
|
op Op
|
||||||
typ string
|
typ string
|
||||||
id *int
|
id *int
|
||||||
username *string
|
name *string
|
||||||
|
email *string
|
||||||
password *string
|
password *string
|
||||||
created_at *time.Time
|
created_at *time.Time
|
||||||
clearedFields map[string]struct{}
|
clearedFields map[string]struct{}
|
||||||
|
|
@ -119,40 +120,76 @@ func (m *UserMutation) ID() (id int, exists bool) {
|
||||||
return *m.id, true
|
return *m.id, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUsername sets the "username" field.
|
// SetName sets the "name" field.
|
||||||
func (m *UserMutation) SetUsername(s string) {
|
func (m *UserMutation) SetName(s string) {
|
||||||
m.username = &s
|
m.name = &s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Username returns the value of the "username" field in the mutation.
|
// Name returns the value of the "name" field in the mutation.
|
||||||
func (m *UserMutation) Username() (r string, exists bool) {
|
func (m *UserMutation) Name() (r string, exists bool) {
|
||||||
v := m.username
|
v := m.name
|
||||||
if v == nil {
|
if v == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return *v, true
|
return *v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// OldUsername returns the old "username" field's value of the User entity.
|
// OldName returns the old "name" field's value of the User entity.
|
||||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
// If the User 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 *UserMutation) OldUsername(ctx context.Context) (v string, err error) {
|
func (m *UserMutation) OldName(ctx context.Context) (v string, err error) {
|
||||||
if !m.op.Is(OpUpdateOne) {
|
if !m.op.Is(OpUpdateOne) {
|
||||||
return v, fmt.Errorf("OldUsername is only allowed on UpdateOne operations")
|
return v, fmt.Errorf("OldName is only allowed on UpdateOne operations")
|
||||||
}
|
}
|
||||||
if m.id == nil || m.oldValue == nil {
|
if m.id == nil || m.oldValue == nil {
|
||||||
return v, fmt.Errorf("OldUsername requires an ID field in the mutation")
|
return v, fmt.Errorf("OldName 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 OldUsername: %w", err)
|
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
||||||
}
|
}
|
||||||
return oldValue.Username, nil
|
return oldValue.Name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetUsername resets all changes to the "username" field.
|
// ResetName resets all changes to the "name" field.
|
||||||
func (m *UserMutation) ResetUsername() {
|
func (m *UserMutation) ResetName() {
|
||||||
m.username = nil
|
m.name = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEmail sets the "email" field.
|
||||||
|
func (m *UserMutation) SetEmail(s string) {
|
||||||
|
m.email = &s
|
||||||
|
}
|
||||||
|
|
||||||
|
// Email returns the value of the "email" field in the mutation.
|
||||||
|
func (m *UserMutation) Email() (r string, exists bool) {
|
||||||
|
v := m.email
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return *v, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// OldEmail returns the old "email" field's value of the User entity.
|
||||||
|
// If the User 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 *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
|
||||||
|
if !m.op.Is(OpUpdateOne) {
|
||||||
|
return v, fmt.Errorf("OldEmail is only allowed on UpdateOne operations")
|
||||||
|
}
|
||||||
|
if m.id == nil || m.oldValue == nil {
|
||||||
|
return v, fmt.Errorf("OldEmail requires an ID field in the mutation")
|
||||||
|
}
|
||||||
|
oldValue, err := m.oldValue(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return v, fmt.Errorf("querying old value for OldEmail: %w", err)
|
||||||
|
}
|
||||||
|
return oldValue.Email, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetEmail resets all changes to the "email" field.
|
||||||
|
func (m *UserMutation) ResetEmail() {
|
||||||
|
m.email = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPassword sets the "password" field.
|
// SetPassword sets the "password" field.
|
||||||
|
|
@ -246,9 +283,12 @@ func (m *UserMutation) Type() string {
|
||||||
// order to get all numeric fields that were incremented/decremented, call
|
// order to get all numeric fields that were incremented/decremented, call
|
||||||
// AddedFields().
|
// AddedFields().
|
||||||
func (m *UserMutation) Fields() []string {
|
func (m *UserMutation) Fields() []string {
|
||||||
fields := make([]string, 0, 3)
|
fields := make([]string, 0, 4)
|
||||||
if m.username != nil {
|
if m.name != nil {
|
||||||
fields = append(fields, user.FieldUsername)
|
fields = append(fields, user.FieldName)
|
||||||
|
}
|
||||||
|
if m.email != nil {
|
||||||
|
fields = append(fields, user.FieldEmail)
|
||||||
}
|
}
|
||||||
if m.password != nil {
|
if m.password != nil {
|
||||||
fields = append(fields, user.FieldPassword)
|
fields = append(fields, user.FieldPassword)
|
||||||
|
|
@ -264,8 +304,10 @@ func (m *UserMutation) Fields() []string {
|
||||||
// schema.
|
// schema.
|
||||||
func (m *UserMutation) Field(name string) (ent.Value, bool) {
|
func (m *UserMutation) Field(name string) (ent.Value, bool) {
|
||||||
switch name {
|
switch name {
|
||||||
case user.FieldUsername:
|
case user.FieldName:
|
||||||
return m.Username()
|
return m.Name()
|
||||||
|
case user.FieldEmail:
|
||||||
|
return m.Email()
|
||||||
case user.FieldPassword:
|
case user.FieldPassword:
|
||||||
return m.Password()
|
return m.Password()
|
||||||
case user.FieldCreatedAt:
|
case user.FieldCreatedAt:
|
||||||
|
|
@ -279,8 +321,10 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
|
||||||
// database failed.
|
// database failed.
|
||||||
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||||
switch name {
|
switch name {
|
||||||
case user.FieldUsername:
|
case user.FieldName:
|
||||||
return m.OldUsername(ctx)
|
return m.OldName(ctx)
|
||||||
|
case user.FieldEmail:
|
||||||
|
return m.OldEmail(ctx)
|
||||||
case user.FieldPassword:
|
case user.FieldPassword:
|
||||||
return m.OldPassword(ctx)
|
return m.OldPassword(ctx)
|
||||||
case user.FieldCreatedAt:
|
case user.FieldCreatedAt:
|
||||||
|
|
@ -294,12 +338,19 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
|
||||||
// type.
|
// type.
|
||||||
func (m *UserMutation) SetField(name string, value ent.Value) error {
|
func (m *UserMutation) SetField(name string, value ent.Value) error {
|
||||||
switch name {
|
switch name {
|
||||||
case user.FieldUsername:
|
case user.FieldName:
|
||||||
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.SetUsername(v)
|
m.SetName(v)
|
||||||
|
return nil
|
||||||
|
case user.FieldEmail:
|
||||||
|
v, ok := value.(string)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||||
|
}
|
||||||
|
m.SetEmail(v)
|
||||||
return nil
|
return nil
|
||||||
case user.FieldPassword:
|
case user.FieldPassword:
|
||||||
v, ok := value.(string)
|
v, ok := value.(string)
|
||||||
|
|
@ -364,8 +415,11 @@ func (m *UserMutation) 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 *UserMutation) ResetField(name string) error {
|
func (m *UserMutation) ResetField(name string) error {
|
||||||
switch name {
|
switch name {
|
||||||
case user.FieldUsername:
|
case user.FieldName:
|
||||||
m.ResetUsername()
|
m.ResetName()
|
||||||
|
return nil
|
||||||
|
case user.FieldEmail:
|
||||||
|
m.ResetEmail()
|
||||||
return nil
|
return nil
|
||||||
case user.FieldPassword:
|
case user.FieldPassword:
|
||||||
m.ResetPassword()
|
m.ResetPassword()
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,20 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
userFields := schema.User{}.Fields()
|
userFields := schema.User{}.Fields()
|
||||||
_ = userFields
|
_ = userFields
|
||||||
// userDescUsername is the schema descriptor for username field.
|
// userDescName is the schema descriptor for name field.
|
||||||
userDescUsername := userFields[0].Descriptor()
|
userDescName := userFields[0].Descriptor()
|
||||||
// user.UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
// user.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||||
user.UsernameValidator = userDescUsername.Validators[0].(func(string) error)
|
user.NameValidator = userDescName.Validators[0].(func(string) error)
|
||||||
|
// userDescEmail is the schema descriptor for email field.
|
||||||
|
userDescEmail := userFields[1].Descriptor()
|
||||||
|
// user.EmailValidator is a validator for the "email" field. It is called by the builders before save.
|
||||||
|
user.EmailValidator = userDescEmail.Validators[0].(func(string) error)
|
||||||
// userDescPassword is the schema descriptor for password field.
|
// userDescPassword is the schema descriptor for password field.
|
||||||
userDescPassword := userFields[1].Descriptor()
|
userDescPassword := userFields[2].Descriptor()
|
||||||
// user.PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
// user.PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
||||||
user.PasswordValidator = userDescPassword.Validators[0].(func(string) error)
|
user.PasswordValidator = userDescPassword.Validators[0].(func(string) error)
|
||||||
// userDescCreatedAt is the schema descriptor for created_at field.
|
// userDescCreatedAt is the schema descriptor for created_at field.
|
||||||
userDescCreatedAt := userFields[2].Descriptor()
|
userDescCreatedAt := userFields[3].Descriptor()
|
||||||
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
|
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,11 @@ type User struct {
|
||||||
// Fields of the User.
|
// Fields of the User.
|
||||||
func (User) Fields() []ent.Field {
|
func (User) Fields() []ent.Field {
|
||||||
return []ent.Field{
|
return []ent.Field{
|
||||||
field.String("username").
|
field.String("name").
|
||||||
Unique().
|
|
||||||
NotEmpty(),
|
NotEmpty(),
|
||||||
|
field.String("email").
|
||||||
|
NotEmpty().
|
||||||
|
Unique(),
|
||||||
field.String("password").
|
field.String("password").
|
||||||
Sensitive().
|
Sensitive().
|
||||||
NotEmpty(),
|
NotEmpty(),
|
||||||
|
|
|
||||||
26
ent/user.go
26
ent/user.go
|
|
@ -16,8 +16,10 @@ type User struct {
|
||||||
config `json:"-"`
|
config `json:"-"`
|
||||||
// ID of the ent.
|
// ID of the ent.
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
// Username holds the value of the "username" field.
|
// Name holds the value of the "name" field.
|
||||||
Username string `json:"username,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
// Email holds the value of the "email" field.
|
||||||
|
Email string `json:"email,omitempty"`
|
||||||
// Password holds the value of the "password" field.
|
// Password holds the value of the "password" field.
|
||||||
Password string `json:"-"`
|
Password string `json:"-"`
|
||||||
// CreatedAt holds the value of the "created_at" field.
|
// CreatedAt holds the value of the "created_at" field.
|
||||||
|
|
@ -31,7 +33,7 @@ func (*User) scanValues(columns []string) ([]interface{}, error) {
|
||||||
switch columns[i] {
|
switch columns[i] {
|
||||||
case user.FieldID:
|
case user.FieldID:
|
||||||
values[i] = new(sql.NullInt64)
|
values[i] = new(sql.NullInt64)
|
||||||
case user.FieldUsername, user.FieldPassword:
|
case user.FieldName, user.FieldEmail, user.FieldPassword:
|
||||||
values[i] = new(sql.NullString)
|
values[i] = new(sql.NullString)
|
||||||
case user.FieldCreatedAt:
|
case user.FieldCreatedAt:
|
||||||
values[i] = new(sql.NullTime)
|
values[i] = new(sql.NullTime)
|
||||||
|
|
@ -56,11 +58,17 @@ func (u *User) assignValues(columns []string, values []interface{}) error {
|
||||||
return fmt.Errorf("unexpected type %T for field id", value)
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
}
|
}
|
||||||
u.ID = int(value.Int64)
|
u.ID = int(value.Int64)
|
||||||
case user.FieldUsername:
|
case user.FieldName:
|
||||||
if value, ok := values[i].(*sql.NullString); !ok {
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
return fmt.Errorf("unexpected type %T for field username", values[i])
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||||
} else if value.Valid {
|
} else if value.Valid {
|
||||||
u.Username = value.String
|
u.Name = value.String
|
||||||
|
}
|
||||||
|
case user.FieldEmail:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field email", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
u.Email = value.String
|
||||||
}
|
}
|
||||||
case user.FieldPassword:
|
case user.FieldPassword:
|
||||||
if value, ok := values[i].(*sql.NullString); !ok {
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
|
@ -102,8 +110,10 @@ func (u *User) String() string {
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
builder.WriteString("User(")
|
builder.WriteString("User(")
|
||||||
builder.WriteString(fmt.Sprintf("id=%v", u.ID))
|
builder.WriteString(fmt.Sprintf("id=%v", u.ID))
|
||||||
builder.WriteString(", username=")
|
builder.WriteString(", name=")
|
||||||
builder.WriteString(u.Username)
|
builder.WriteString(u.Name)
|
||||||
|
builder.WriteString(", email=")
|
||||||
|
builder.WriteString(u.Email)
|
||||||
builder.WriteString(", password=<sensitive>")
|
builder.WriteString(", password=<sensitive>")
|
||||||
builder.WriteString(", created_at=")
|
builder.WriteString(", created_at=")
|
||||||
builder.WriteString(u.CreatedAt.Format(time.ANSIC))
|
builder.WriteString(u.CreatedAt.Format(time.ANSIC))
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,10 @@ const (
|
||||||
Label = "user"
|
Label = "user"
|
||||||
// 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"
|
||||||
// FieldUsername holds the string denoting the username field in the database.
|
// FieldName holds the string denoting the name field in the database.
|
||||||
FieldUsername = "username"
|
FieldName = "name"
|
||||||
|
// FieldEmail holds the string denoting the email field in the database.
|
||||||
|
FieldEmail = "email"
|
||||||
// FieldPassword holds the string denoting the password field in the database.
|
// FieldPassword holds the string denoting the password field in the database.
|
||||||
FieldPassword = "password"
|
FieldPassword = "password"
|
||||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
|
@ -24,7 +26,8 @@ const (
|
||||||
// Columns holds all SQL columns for user fields.
|
// Columns holds all SQL columns for user fields.
|
||||||
var Columns = []string{
|
var Columns = []string{
|
||||||
FieldID,
|
FieldID,
|
||||||
FieldUsername,
|
FieldName,
|
||||||
|
FieldEmail,
|
||||||
FieldPassword,
|
FieldPassword,
|
||||||
FieldCreatedAt,
|
FieldCreatedAt,
|
||||||
}
|
}
|
||||||
|
|
@ -40,8 +43,10 @@ func ValidColumn(column string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||||
UsernameValidator func(string) error
|
NameValidator func(string) error
|
||||||
|
// EmailValidator is a validator for the "email" field. It is called by the builders before save.
|
||||||
|
EmailValidator func(string) error
|
||||||
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
// PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
||||||
PasswordValidator func(string) error
|
PasswordValidator 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.
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,17 @@ func IDLTE(id int) predicate.User {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ.
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
func Username(v string) predicate.User {
|
func Name(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.EQ(s.C(FieldUsername), v))
|
s.Where(sql.EQ(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Email applies equality check predicate on the "email" field. It's identical to EmailEQ.
|
||||||
|
func Email(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldEmail), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,22 +120,22 @@ func CreatedAt(v time.Time) predicate.User {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameEQ applies the EQ predicate on the "username" field.
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
func UsernameEQ(v string) predicate.User {
|
func NameEQ(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.EQ(s.C(FieldUsername), v))
|
s.Where(sql.EQ(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameNEQ applies the NEQ predicate on the "username" field.
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
func UsernameNEQ(v string) predicate.User {
|
func NameNEQ(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.NEQ(s.C(FieldUsername), v))
|
s.Where(sql.NEQ(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameIn applies the In predicate on the "username" field.
|
// NameIn applies the In predicate on the "name" field.
|
||||||
func UsernameIn(vs ...string) predicate.User {
|
func NameIn(vs ...string) predicate.User {
|
||||||
v := make([]interface{}, len(vs))
|
v := make([]interface{}, len(vs))
|
||||||
for i := range v {
|
for i := range v {
|
||||||
v[i] = vs[i]
|
v[i] = vs[i]
|
||||||
|
|
@ -140,12 +147,12 @@ func UsernameIn(vs ...string) predicate.User {
|
||||||
s.Where(sql.False())
|
s.Where(sql.False())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Where(sql.In(s.C(FieldUsername), v...))
|
s.Where(sql.In(s.C(FieldName), v...))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameNotIn applies the NotIn predicate on the "username" field.
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
func UsernameNotIn(vs ...string) predicate.User {
|
func NameNotIn(vs ...string) predicate.User {
|
||||||
v := make([]interface{}, len(vs))
|
v := make([]interface{}, len(vs))
|
||||||
for i := range v {
|
for i := range v {
|
||||||
v[i] = vs[i]
|
v[i] = vs[i]
|
||||||
|
|
@ -157,70 +164,181 @@ func UsernameNotIn(vs ...string) predicate.User {
|
||||||
s.Where(sql.False())
|
s.Where(sql.False())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.Where(sql.NotIn(s.C(FieldUsername), v...))
|
s.Where(sql.NotIn(s.C(FieldName), v...))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameGT applies the GT predicate on the "username" field.
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
func UsernameGT(v string) predicate.User {
|
func NameGT(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.GT(s.C(FieldUsername), v))
|
s.Where(sql.GT(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameGTE applies the GTE predicate on the "username" field.
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
func UsernameGTE(v string) predicate.User {
|
func NameGTE(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.GTE(s.C(FieldUsername), v))
|
s.Where(sql.GTE(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameLT applies the LT predicate on the "username" field.
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
func UsernameLT(v string) predicate.User {
|
func NameLT(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.LT(s.C(FieldUsername), v))
|
s.Where(sql.LT(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameLTE applies the LTE predicate on the "username" field.
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
func UsernameLTE(v string) predicate.User {
|
func NameLTE(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.LTE(s.C(FieldUsername), v))
|
s.Where(sql.LTE(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameContains applies the Contains predicate on the "username" field.
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
func UsernameContains(v string) predicate.User {
|
func NameContains(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.Contains(s.C(FieldUsername), v))
|
s.Where(sql.Contains(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameHasPrefix applies the HasPrefix predicate on the "username" field.
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
func UsernameHasPrefix(v string) predicate.User {
|
func NameHasPrefix(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.HasPrefix(s.C(FieldUsername), v))
|
s.Where(sql.HasPrefix(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameHasSuffix applies the HasSuffix predicate on the "username" field.
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
func UsernameHasSuffix(v string) predicate.User {
|
func NameHasSuffix(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.HasSuffix(s.C(FieldUsername), v))
|
s.Where(sql.HasSuffix(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameEqualFold applies the EqualFold predicate on the "username" field.
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
func UsernameEqualFold(v string) predicate.User {
|
func NameEqualFold(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.EqualFold(s.C(FieldUsername), v))
|
s.Where(sql.EqualFold(s.C(FieldName), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsernameContainsFold applies the ContainsFold predicate on the "username" field.
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
func UsernameContainsFold(v string) predicate.User {
|
func NameContainsFold(v string) predicate.User {
|
||||||
return predicate.User(func(s *sql.Selector) {
|
return predicate.User(func(s *sql.Selector) {
|
||||||
s.Where(sql.ContainsFold(s.C(FieldUsername), v))
|
s.Where(sql.ContainsFold(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailEQ applies the EQ predicate on the "email" field.
|
||||||
|
func EmailEQ(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailNEQ applies the NEQ predicate on the "email" field.
|
||||||
|
func EmailNEQ(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailIn applies the In predicate on the "email" field.
|
||||||
|
func EmailIn(vs ...string) predicate.User {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldEmail), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailNotIn applies the NotIn predicate on the "email" field.
|
||||||
|
func EmailNotIn(vs ...string) predicate.User {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldEmail), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailGT applies the GT predicate on the "email" field.
|
||||||
|
func EmailGT(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailGTE applies the GTE predicate on the "email" field.
|
||||||
|
func EmailGTE(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailLT applies the LT predicate on the "email" field.
|
||||||
|
func EmailLT(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailLTE applies the LTE predicate on the "email" field.
|
||||||
|
func EmailLTE(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailContains applies the Contains predicate on the "email" field.
|
||||||
|
func EmailContains(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.Contains(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailHasPrefix applies the HasPrefix predicate on the "email" field.
|
||||||
|
func EmailHasPrefix(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasPrefix(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailHasSuffix applies the HasSuffix predicate on the "email" field.
|
||||||
|
func EmailHasSuffix(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasSuffix(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailEqualFold applies the EqualFold predicate on the "email" field.
|
||||||
|
func EmailEqualFold(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EqualFold(s.C(FieldEmail), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmailContainsFold applies the ContainsFold predicate on the "email" field.
|
||||||
|
func EmailContainsFold(v string) predicate.User {
|
||||||
|
return predicate.User(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.ContainsFold(s.C(FieldEmail), v))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,15 @@ type UserCreate struct {
|
||||||
hooks []Hook
|
hooks []Hook
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUsername sets the "username" field.
|
// SetName sets the "name" field.
|
||||||
func (uc *UserCreate) SetUsername(s string) *UserCreate {
|
func (uc *UserCreate) SetName(s string) *UserCreate {
|
||||||
uc.mutation.SetUsername(s)
|
uc.mutation.SetName(s)
|
||||||
|
return uc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEmail sets the "email" field.
|
||||||
|
func (uc *UserCreate) SetEmail(s string) *UserCreate {
|
||||||
|
uc.mutation.SetEmail(s)
|
||||||
return uc
|
return uc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,12 +131,20 @@ func (uc *UserCreate) defaults() {
|
||||||
|
|
||||||
// check runs all checks and user-defined validators on the builder.
|
// check runs all checks and user-defined validators on the builder.
|
||||||
func (uc *UserCreate) check() error {
|
func (uc *UserCreate) check() error {
|
||||||
if _, ok := uc.mutation.Username(); !ok {
|
if _, ok := uc.mutation.Name(); !ok {
|
||||||
return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "username"`)}
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "name"`)}
|
||||||
}
|
}
|
||||||
if v, ok := uc.mutation.Username(); ok {
|
if v, ok := uc.mutation.Name(); ok {
|
||||||
if err := user.UsernameValidator(v); err != nil {
|
if err := user.NameValidator(v); err != nil {
|
||||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "username": %w`, err)}
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "name": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := uc.mutation.Email(); !ok {
|
||||||
|
return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "email"`)}
|
||||||
|
}
|
||||||
|
if v, ok := uc.mutation.Email(); ok {
|
||||||
|
if err := user.EmailValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "email": %w`, err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, ok := uc.mutation.Password(); !ok {
|
if _, ok := uc.mutation.Password(); !ok {
|
||||||
|
|
@ -171,13 +185,21 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if value, ok := uc.mutation.Username(); ok {
|
if value, ok := uc.mutation.Name(); ok {
|
||||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
Type: field.TypeString,
|
Type: field.TypeString,
|
||||||
Value: value,
|
Value: value,
|
||||||
Column: user.FieldUsername,
|
Column: user.FieldName,
|
||||||
})
|
})
|
||||||
_node.Username = value
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := uc.mutation.Email(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: user.FieldEmail,
|
||||||
|
})
|
||||||
|
_node.Email = value
|
||||||
}
|
}
|
||||||
if value, ok := uc.mutation.Password(); ok {
|
if value, ok := uc.mutation.Password(); ok {
|
||||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
|
|
||||||
|
|
@ -253,12 +253,12 @@ func (uq *UserQuery) Clone() *UserQuery {
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// var v []struct {
|
// var v []struct {
|
||||||
// Username string `json:"username,omitempty"`
|
// Name string `json:"name,omitempty"`
|
||||||
// Count int `json:"count,omitempty"`
|
// Count int `json:"count,omitempty"`
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// client.User.Query().
|
// client.User.Query().
|
||||||
// GroupBy(user.FieldUsername).
|
// GroupBy(user.FieldName).
|
||||||
// Aggregate(ent.Count()).
|
// Aggregate(ent.Count()).
|
||||||
// Scan(ctx, &v)
|
// Scan(ctx, &v)
|
||||||
//
|
//
|
||||||
|
|
@ -280,11 +280,11 @@ func (uq *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// var v []struct {
|
// var v []struct {
|
||||||
// Username string `json:"username,omitempty"`
|
// Name string `json:"name,omitempty"`
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// client.User.Query().
|
// client.User.Query().
|
||||||
// Select(user.FieldUsername).
|
// Select(user.FieldName).
|
||||||
// Scan(ctx, &v)
|
// Scan(ctx, &v)
|
||||||
//
|
//
|
||||||
func (uq *UserQuery) Select(fields ...string) *UserSelect {
|
func (uq *UserQuery) Select(fields ...string) *UserSelect {
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,15 @@ func (uu *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
||||||
return uu
|
return uu
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUsername sets the "username" field.
|
// SetName sets the "name" field.
|
||||||
func (uu *UserUpdate) SetUsername(s string) *UserUpdate {
|
func (uu *UserUpdate) SetName(s string) *UserUpdate {
|
||||||
uu.mutation.SetUsername(s)
|
uu.mutation.SetName(s)
|
||||||
|
return uu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEmail sets the "email" field.
|
||||||
|
func (uu *UserUpdate) SetEmail(s string) *UserUpdate {
|
||||||
|
uu.mutation.SetEmail(s)
|
||||||
return uu
|
return uu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,9 +111,14 @@ func (uu *UserUpdate) 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 (uu *UserUpdate) check() error {
|
func (uu *UserUpdate) check() error {
|
||||||
if v, ok := uu.mutation.Username(); ok {
|
if v, ok := uu.mutation.Name(); ok {
|
||||||
if err := user.UsernameValidator(v); err != nil {
|
if err := user.NameValidator(v); err != nil {
|
||||||
return &ValidationError{Name: "username", err: fmt.Errorf("ent: validator failed for field \"username\": %w", err)}
|
return &ValidationError{Name: "name", err: fmt.Errorf("ent: validator failed for field \"name\": %w", err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := uu.mutation.Email(); ok {
|
||||||
|
if err := user.EmailValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "email", err: fmt.Errorf("ent: validator failed for field \"email\": %w", err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v, ok := uu.mutation.Password(); ok {
|
if v, ok := uu.mutation.Password(); ok {
|
||||||
|
|
@ -136,11 +147,18 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if value, ok := uu.mutation.Username(); ok {
|
if value, ok := uu.mutation.Name(); ok {
|
||||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
Type: field.TypeString,
|
Type: field.TypeString,
|
||||||
Value: value,
|
Value: value,
|
||||||
Column: user.FieldUsername,
|
Column: user.FieldName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := uu.mutation.Email(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: user.FieldEmail,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if value, ok := uu.mutation.Password(); ok {
|
if value, ok := uu.mutation.Password(); ok {
|
||||||
|
|
@ -169,9 +187,15 @@ type UserUpdateOne struct {
|
||||||
mutation *UserMutation
|
mutation *UserMutation
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUsername sets the "username" field.
|
// SetName sets the "name" field.
|
||||||
func (uuo *UserUpdateOne) SetUsername(s string) *UserUpdateOne {
|
func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne {
|
||||||
uuo.mutation.SetUsername(s)
|
uuo.mutation.SetName(s)
|
||||||
|
return uuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEmail sets the "email" field.
|
||||||
|
func (uuo *UserUpdateOne) SetEmail(s string) *UserUpdateOne {
|
||||||
|
uuo.mutation.SetEmail(s)
|
||||||
return uuo
|
return uuo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,9 +279,14 @@ func (uuo *UserUpdateOne) 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 (uuo *UserUpdateOne) check() error {
|
func (uuo *UserUpdateOne) check() error {
|
||||||
if v, ok := uuo.mutation.Username(); ok {
|
if v, ok := uuo.mutation.Name(); ok {
|
||||||
if err := user.UsernameValidator(v); err != nil {
|
if err := user.NameValidator(v); err != nil {
|
||||||
return &ValidationError{Name: "username", err: fmt.Errorf("ent: validator failed for field \"username\": %w", err)}
|
return &ValidationError{Name: "name", err: fmt.Errorf("ent: validator failed for field \"name\": %w", err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := uuo.mutation.Email(); ok {
|
||||||
|
if err := user.EmailValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "email", err: fmt.Errorf("ent: validator failed for field \"email\": %w", err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v, ok := uuo.mutation.Password(); ok {
|
if v, ok := uuo.mutation.Password(); ok {
|
||||||
|
|
@ -303,11 +332,18 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if value, ok := uuo.mutation.Username(); ok {
|
if value, ok := uuo.mutation.Name(); ok {
|
||||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
Type: field.TypeString,
|
Type: field.TypeString,
|
||||||
Value: value,
|
Value: value,
|
||||||
Column: user.FieldUsername,
|
Column: user.FieldName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := uuo.mutation.Email(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: user.FieldEmail,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if value, ok := uuo.mutation.Password(); ok {
|
if value, ok := uuo.mutation.Password(); ok {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginForm struct {
|
LoginForm struct {
|
||||||
Username string `form:"username" validate:"required" label:"Username"`
|
Email string `form:"email" validate:"required,email" label:"Email address"`
|
||||||
Password string `form:"password" validate:"required" label:"Password"`
|
Password string `form:"password" validate:"required" label:"Password"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -54,7 +54,7 @@ func (l *Login) Post(c echo.Context) error {
|
||||||
// Attempt to load the user
|
// Attempt to load the user
|
||||||
u, err := l.Container.ORM.User.
|
u, err := l.Container.ORM.User.
|
||||||
Query().
|
Query().
|
||||||
Where(user.Username(l.form.Username)).
|
Where(user.Email(l.form.Email)).
|
||||||
First(c.Request().Context())
|
First(c.Request().Context())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -80,6 +80,6 @@ func (l *Login) Post(c echo.Context) error {
|
||||||
return fail("unable to log in user", err)
|
return fail("unable to log in user", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.Success(c, fmt.Sprintf("Welcome back, %s. You are now logged in.", u.Username))
|
msg.Success(c, fmt.Sprintf("Welcome back, %s. You are now logged in.", u.Name))
|
||||||
return l.Redirect(c, "home")
|
return l.Redirect(c, "home")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,10 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterForm struct {
|
RegisterForm struct {
|
||||||
Username string `form:"username" validate:"required"`
|
Name string `form:"name" validate:"required" label:"Name"`
|
||||||
Password string `form:"password" validate:"required"`
|
Email string `form:"email" validate:"required,email" label:"Email address"`
|
||||||
|
Password string `form:"password" validate:"required" label:"Password"`
|
||||||
|
ConfirmPassword string `form:"password-confirm" validate:"required,eqfield=Password" label:"Confirm password"` // TODO validate same
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -44,7 +46,7 @@ func (r *Register) Post(c echo.Context) error {
|
||||||
|
|
||||||
// Validate the form
|
// Validate the form
|
||||||
if err := c.Validate(r.form); err != nil {
|
if err := c.Validate(r.form); err != nil {
|
||||||
msg.Danger(c, "All fields are required.")
|
r.SetValidationErrorMessages(c, err, r.form)
|
||||||
return r.Get(c)
|
return r.Get(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +59,8 @@ func (r *Register) Post(c echo.Context) error {
|
||||||
// Attempt creating the user
|
// Attempt creating the user
|
||||||
u, err := r.Container.ORM.User.
|
u, err := r.Container.ORM.User.
|
||||||
Create().
|
Create().
|
||||||
SetUsername(r.form.Username).
|
SetName(r.form.Name).
|
||||||
|
SetEmail(r.form.Email).
|
||||||
SetPassword(pwHash).
|
SetPassword(pwHash).
|
||||||
Save(c.Request().Context())
|
Save(c.Request().Context())
|
||||||
|
|
||||||
|
|
@ -65,7 +68,7 @@ func (r *Register) Post(c echo.Context) error {
|
||||||
return fail("unable to create user", err)
|
return fail("unable to create user", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Logger().Infof("user created: %s", u.Username)
|
c.Logger().Infof("user created: %s", u.Name)
|
||||||
|
|
||||||
err = auth.Login(c, u.ID)
|
err = auth.Login(c, u.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="login" class="label">Username</label>
|
<label for="email" class="label">Email address</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input id="login" type="text" name="username" class="input" value="{{.Data.Username}}" required>
|
<input id="email" type="email" name="email" class="input" value="{{.Data.Email}}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="username" class="label">Username</label>
|
<label for="name" class="label">Name</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<input type="text" id="username" name="username" class="input" value="{{.Data.Username}}" required>
|
<input type="text" id="name" name="name" class="input" value="{{.Data.Name}}" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="email" class="label">Email address</label>
|
||||||
|
<div class="control">
|
||||||
|
<input type="email" id="email" name="email" class="input" value="{{.Data.Email}}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
|
@ -12,6 +18,12 @@
|
||||||
<input type="password" id="password" name="password" placeholder="*******" class="input" required>
|
<input type="password" id="password" name="password" placeholder="*******" class="input" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label for="password-confirm" class="label">Confirm password</label>
|
||||||
|
<div class="control">
|
||||||
|
<input type="password" id="password-confirm" name="password-confirm" placeholder="*******" class="input" required>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="field is-grouped">
|
<div class="field is-grouped">
|
||||||
<p class="control">
|
<p class="control">
|
||||||
<button class="button is-primary">Register</button>
|
<button class="button is-primary">Register</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue