Implement login resolver (#15)
* add sign_up_method to users table * add session store * implement login resolver
This commit is contained in:
@@ -36,13 +36,13 @@ func init() {
|
||||
TablePrefix: "yauth_",
|
||||
},
|
||||
}
|
||||
if constants.DB_TYPE == enum.Postgres {
|
||||
if constants.DB_TYPE == enum.Postgres.String() {
|
||||
db, err = gorm.Open(postgres.Open(constants.DB_URL), ormConfig)
|
||||
}
|
||||
if constants.DB_TYPE == enum.Mysql {
|
||||
if constants.DB_TYPE == enum.Mysql.String() {
|
||||
db, err = gorm.Open(mysql.Open(constants.DB_URL), ormConfig)
|
||||
}
|
||||
if constants.DB_TYPE == enum.Sqlite {
|
||||
if constants.DB_TYPE == enum.Sqlite.String() {
|
||||
db, err = gorm.Open(sqlite.Open(constants.DB_URL), ormConfig)
|
||||
}
|
||||
|
||||
|
@@ -18,11 +18,13 @@ 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 {
|
||||
// Modify current operation through tx.Statement, e.g:
|
||||
if pw, err := bcrypt.GenerateFromPassword([]byte(user.Password), 0); err == nil {
|
||||
if pw, err := bcrypt.GenerateFromPassword([]byte(user.Password), bcrypt.DefaultCost); err == nil {
|
||||
tx.Statement.SetColumn("Password", pw)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user