add sign_up_method to users table
This commit is contained in:
parent
336fe10ca4
commit
27690fb2b6
|
@ -18,6 +18,8 @@ type User struct {
|
||||||
EmailVerifiedAt int64
|
EmailVerifiedAt int64
|
||||||
CreatedAt int64 `gorm:"autoCreateTime"`
|
CreatedAt int64 `gorm:"autoCreateTime"`
|
||||||
UpdatedAt int64 `gorm:"autoUpdateTime"`
|
UpdatedAt int64 `gorm:"autoUpdateTime"`
|
||||||
|
Image string
|
||||||
|
SignUpMethod string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user *User) BeforeSave(tx *gorm.DB) error {
|
func (user *User) BeforeSave(tx *gorm.DB) error {
|
||||||
|
@ -31,7 +33,7 @@ func (user *User) BeforeSave(tx *gorm.DB) error {
|
||||||
|
|
||||||
// AddUser function to add user
|
// AddUser function to add user
|
||||||
func (mgr *manager) AddUser(user User) (User, error) {
|
func (mgr *manager) AddUser(user User) (User, error) {
|
||||||
result := mgr.db.Clauses(clause.OnConflict{DoNothing: true}).Create(&user)
|
result := mgr.db.Clauses(clause.OnConflict{UpdateAll: true, Columns: []clause.Column{{Name: "email"}}}).Create(&user)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
log.Println(result.Error)
|
log.Println(result.Error)
|
||||||
return user, result.Error
|
return user, result.Error
|
||||||
|
|
|
@ -3,7 +3,7 @@ package enum
|
||||||
type SignupMethod int
|
type SignupMethod int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Basic SignupMethod = iota
|
BasicAuth SignupMethod = iota
|
||||||
MagicLink
|
MagicLink
|
||||||
Google
|
Google
|
||||||
Github
|
Github
|
||||||
|
@ -12,8 +12,8 @@ const (
|
||||||
|
|
||||||
func (d SignupMethod) String() string {
|
func (d SignupMethod) String() string {
|
||||||
return [...]string{
|
return [...]string{
|
||||||
"basic",
|
"basic_auth",
|
||||||
"magiclink",
|
"magic_link",
|
||||||
"google",
|
"google",
|
||||||
"github",
|
"github",
|
||||||
"facebook",
|
"facebook",
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/yauthdev/yauth/server/db"
|
"github.com/yauthdev/yauth/server/db"
|
||||||
|
"github.com/yauthdev/yauth/server/enum"
|
||||||
"github.com/yauthdev/yauth/server/graph/generated"
|
"github.com/yauthdev/yauth/server/graph/generated"
|
||||||
"github.com/yauthdev/yauth/server/graph/model"
|
"github.com/yauthdev/yauth/server/graph/model"
|
||||||
"github.com/yauthdev/yauth/server/utils"
|
"github.com/yauthdev/yauth/server/utils"
|
||||||
|
@ -121,13 +122,14 @@ func (r *mutationResolver) BasicAuthSignUp(ctx context.Context, params model.Bas
|
||||||
user.LastName = *params.LastName
|
user.LastName = *params.LastName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.SignUpMethod = enum.BasicAuth.String()
|
||||||
_, err = db.Mgr.AddUser(user)
|
_, err = db.Mgr.AddUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert verification request
|
// insert verification request
|
||||||
verificationType := "BASIC_AUTH_SIGNUP"
|
verificationType := enum.BasicAuth.String()
|
||||||
token, err := utils.CreateVerificationToken(params.Email, verificationType)
|
token, err := utils.CreateVerificationToken(params.Email, verificationType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(`Error generating token`, err)
|
log.Println(`Error generating token`, err)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user