This commit is contained in:
parent
ef5aa743bf
commit
38f9b4bf78
|
@ -2679,6 +2679,8 @@ input UpdateProfileInput {
|
||||||
|
|
||||||
input CreateUserInput {
|
input CreateUserInput {
|
||||||
email: String
|
email: String
|
||||||
|
email_verified: Boolean
|
||||||
|
email_verified_at: Int64
|
||||||
password: String
|
password: String
|
||||||
given_name: String
|
given_name: String
|
||||||
family_name: String
|
family_name: String
|
||||||
|
@ -2686,6 +2688,8 @@ input CreateUserInput {
|
||||||
nickname: String
|
nickname: String
|
||||||
phone_number: String
|
phone_number: String
|
||||||
picture: String
|
picture: String
|
||||||
|
created_at: Int64
|
||||||
|
updated_at: Int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -16256,7 +16260,7 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o
|
||||||
asMap[k] = v
|
asMap[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldsInOrder := [...]string{"email", "password", "given_name", "family_name", "middle_name", "nickname", "phone_number", "picture"}
|
fieldsInOrder := [...]string{"email", "email_verified", "email_verified_at", "password", "given_name", "family_name", "middle_name", "nickname", "phone_number", "picture", "created_at", "updated_at"}
|
||||||
for _, k := range fieldsInOrder {
|
for _, k := range fieldsInOrder {
|
||||||
v, ok := asMap[k]
|
v, ok := asMap[k]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -16272,6 +16276,24 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
it.Email = data
|
it.Email = data
|
||||||
|
case "email_verified":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("email_verified"))
|
||||||
|
data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
|
it.EmailVerified = data
|
||||||
|
case "email_verified_at":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("email_verified_at"))
|
||||||
|
data, err := ec.unmarshalOInt642ᚖint64(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
|
it.EmailVerifiedAt = data
|
||||||
case "password":
|
case "password":
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -16335,6 +16357,24 @@ func (ec *executionContext) unmarshalInputCreateUserInput(ctx context.Context, o
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
it.Picture = data
|
it.Picture = data
|
||||||
|
case "created_at":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("created_at"))
|
||||||
|
data, err := ec.unmarshalOInt642ᚖint64(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
|
it.CreatedAt = data
|
||||||
|
case "updated_at":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("updated_at"))
|
||||||
|
data, err := ec.unmarshalOInt642ᚖint64(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
|
it.UpdatedAt = data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
server/graph/model/mod.go
Normal file
1
server/graph/model/mod.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package model
|
|
@ -38,6 +38,8 @@ type AuthResponse struct {
|
||||||
|
|
||||||
type CreateUserInput struct {
|
type CreateUserInput struct {
|
||||||
Email *string `json:"email,omitempty"`
|
Email *string `json:"email,omitempty"`
|
||||||
|
EmailVerified *bool `json:"email_verified,omitempty"`
|
||||||
|
EmailVerifiedAt *int64 `json:"email_verified_at,omitempty"`
|
||||||
Password *string `json:"password,omitempty"`
|
Password *string `json:"password,omitempty"`
|
||||||
GivenName *string `json:"given_name,omitempty"`
|
GivenName *string `json:"given_name,omitempty"`
|
||||||
FamilyName *string `json:"family_name,omitempty"`
|
FamilyName *string `json:"family_name,omitempty"`
|
||||||
|
@ -45,6 +47,8 @@ type CreateUserInput struct {
|
||||||
Nickname *string `json:"nickname,omitempty"`
|
Nickname *string `json:"nickname,omitempty"`
|
||||||
PhoneNumber *string `json:"phone_number,omitempty"`
|
PhoneNumber *string `json:"phone_number,omitempty"`
|
||||||
Picture *string `json:"picture,omitempty"`
|
Picture *string `json:"picture,omitempty"`
|
||||||
|
CreatedAt *int64 `json:"created_at,omitempty"`
|
||||||
|
UpdatedAt *int64 `json:"updated_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteEmailTemplateRequest struct {
|
type DeleteEmailTemplateRequest struct {
|
||||||
|
|
|
@ -410,6 +410,8 @@ input UpdateProfileInput {
|
||||||
|
|
||||||
input CreateUserInput {
|
input CreateUserInput {
|
||||||
email: String
|
email: String
|
||||||
|
email_verified: Boolean
|
||||||
|
email_verified_at: Int64
|
||||||
password: String
|
password: String
|
||||||
given_name: String
|
given_name: String
|
||||||
family_name: String
|
family_name: String
|
||||||
|
@ -417,6 +419,8 @@ input CreateUserInput {
|
||||||
nickname: String
|
nickname: String
|
||||||
phone_number: String
|
phone_number: String
|
||||||
picture: String
|
picture: String
|
||||||
|
created_at: Int64
|
||||||
|
updated_at: Int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ func CreateUserResolver(ctx context.Context, params model.CreateUserInput) (*mod
|
||||||
return res, fmt.Errorf("unauthorized")
|
return res, fmt.Errorf("unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
log := log.New();
|
log := log.New()
|
||||||
|
|
||||||
if params.PhoneNumber != nil {
|
if params.PhoneNumber != nil {
|
||||||
// verify if phone number is unique
|
// verify if phone number is unique
|
||||||
|
@ -47,6 +47,15 @@ func CreateUserResolver(ctx context.Context, params model.CreateUserInput) (*mod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if params.EmailVerified != nil {
|
||||||
|
if *params.EmailVerified {
|
||||||
|
now := time.Now().Unix()
|
||||||
|
params.EmailVerifiedAt = &now
|
||||||
|
} else {
|
||||||
|
params.EmailVerifiedAt = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if params.Email != nil {
|
if params.Email != nil {
|
||||||
// check if valid email
|
// check if valid email
|
||||||
if !validators.IsValidEmail(*params.Email) {
|
if !validators.IsValidEmail(*params.Email) {
|
||||||
|
@ -64,6 +73,7 @@ func CreateUserResolver(ctx context.Context, params model.CreateUserInput) (*mod
|
||||||
|
|
||||||
hostname := parsers.GetHost(gc)
|
hostname := parsers.GetHost(gc)
|
||||||
params.Email = &newEmail
|
params.Email = &newEmail
|
||||||
|
params.EmailVerifiedAt = nil
|
||||||
// insert verification request
|
// insert verification request
|
||||||
_, nonceHash, err := utils.GenerateNonce()
|
_, nonceHash, err := utils.GenerateNonce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -101,6 +111,9 @@ func CreateUserResolver(ctx context.Context, params model.CreateUserInput) (*mod
|
||||||
// json-typed model to store in database
|
// json-typed model to store in database
|
||||||
userdata := models.User{
|
userdata := models.User{
|
||||||
Email: *params.Email,
|
Email: *params.Email,
|
||||||
|
EmailVerifiedAt: params.EmailVerifiedAt,
|
||||||
|
CreatedAt: *params.CreatedAt,
|
||||||
|
UpdatedAt: *params.UpdatedAt,
|
||||||
Password: params.Password,
|
Password: params.Password,
|
||||||
GivenName: params.GivenName,
|
GivenName: params.GivenName,
|
||||||
FamilyName: params.FamilyName,
|
FamilyName: params.FamilyName,
|
||||||
|
@ -114,22 +127,21 @@ func CreateUserResolver(ctx context.Context, params model.CreateUserInput) (*mod
|
||||||
user, err = db.Provider.AddUser(ctx, &userdata)
|
user, err = db.Provider.AddUser(ctx, &userdata)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to create user: ", err)
|
log.Debug("Failed to update user: ", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the user data to the appropriate type for the GraphQL response
|
createdAt := user.CreatedAt
|
||||||
|
updatedAt := user.UpdatedAt
|
||||||
res = &model.User{
|
res = &model.User{
|
||||||
ID: user.ID,
|
ID: user.ID,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
|
Picture: user.Picture,
|
||||||
GivenName: user.GivenName,
|
GivenName: user.GivenName,
|
||||||
FamilyName: user.FamilyName,
|
FamilyName: user.FamilyName,
|
||||||
MiddleName: user.MiddleName,
|
Roles: strings.Split(user.Roles, ","),
|
||||||
Nickname: user.Nickname,
|
CreatedAt: &createdAt,
|
||||||
PhoneNumber: user.PhoneNumber,
|
UpdatedAt: &updatedAt,
|
||||||
Picture: user.Picture,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user