feat google oauth
This commit is contained in:
@@ -14,6 +14,7 @@ type User struct {
|
||||
Password string `gorm:"column:password" json:"password"`
|
||||
WechatOpenID string `gorm:"column:wechat_open_id" json:"wechat_open_id"`
|
||||
WechatUnionID string `gorm:"column:wechat_union_id" json:"wechat_union_id"`
|
||||
GoogleID string `gorm:"column:google_id" json:"google_id"`
|
||||
}
|
||||
|
||||
func (u *User) TableName() string {
|
||||
@@ -63,3 +64,18 @@ func (dao *UserDao) GetByEmail(tx *gorm.DB, email string) (*User, error) {
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func (dao *UserDao) GetByGoogleID(tx *gorm.DB, googleID string) (*User, error) {
|
||||
var user User
|
||||
if err := tx.Where("google_id = ?", googleID).First(&user).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func (dao *UserDao) Update(tx *gorm.DB, user *User) error {
|
||||
return tx.Save(user).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user