| 123456789101112131415161718 |
- package user
- import (
- "github.com/runningwater/gohub/pkg/hash"
- "gorm.io/gorm"
- )
- // BeforeSave 回调方法
- func (u *User) BeforeSave(tx *gorm.DB) (err error) {
- // 如果密码有变化
- if !hash.BcryptIsHashed(u.Password) {
- u.Password = hash.BcryptHash(u.Password)
- }
- return
- }
|