feat google oauth

This commit is contained in:
liuyuanchuang
2026-03-06 10:28:56 +08:00
parent 8852ee5a3a
commit ed7232e5c0
7 changed files with 261 additions and 17 deletions

View File

@@ -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
}