add sign_up_method to users table

This commit is contained in:
Lakhan Samani 2021-07-14 12:46:48 +05:30
parent 336fe10ca4
commit 27690fb2b6
3 changed files with 9 additions and 5 deletions

View File

@ -18,6 +18,8 @@ type User struct {
EmailVerifiedAt int64
CreatedAt int64 `gorm:"autoCreateTime"`
UpdatedAt int64 `gorm:"autoUpdateTime"`
Image string
SignUpMethod string
}
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
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 {
log.Println(result.Error)
return user, result.Error

View File

@ -3,7 +3,7 @@ package enum
type SignupMethod int
const (
Basic SignupMethod = iota
BasicAuth SignupMethod = iota
MagicLink
Google
Github
@ -12,8 +12,8 @@ const (
func (d SignupMethod) String() string {
return [...]string{
"basic",
"magiclink",
"basic_auth",
"magic_link",
"google",
"github",
"facebook",

View File

@ -11,6 +11,7 @@ import (
"time"
"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/model"
"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.SignUpMethod = enum.BasicAuth.String()
_, err = db.Mgr.AddUser(user)
if err != nil {
return res, err
}
// insert verification request
verificationType := "BASIC_AUTH_SIGNUP"
verificationType := enum.BasicAuth.String()
token, err := utils.CreateVerificationToken(params.Email, verificationType)
if err != nil {
log.Println(`Error generating token`, err)