Files
open-im-server/pkg/common/db/mysql/demo_model.go
T

43 lines
1.3 KiB
Go
Raw Normal View History

2023-01-16 20:14:26 +08:00
package mysql
2021-12-01 12:16:02 +08:00
import (
2023-01-11 16:23:16 +08:00
"gorm.io/gorm"
2021-12-01 12:16:02 +08:00
)
2023-01-11 16:23:16 +08:00
var RegisterDB *gorm.DB
type Register struct {
Account string `gorm:"column:account;primary_key;type:char(255)" json:"account"`
Password string `gorm:"column:password;type:varchar(255)" json:"password"`
Ex string `gorm:"column:ex;size:1024" json:"ex"`
UserID string `gorm:"column:user_id;type:varchar(255)" json:"userID"`
AreaCode string `gorm:"column:area_code;type:varchar(255)"`
InvitationCode string `gorm:"column:invitation_code;type:varchar(255)"`
RegisterIP string `gorm:"column:register_ip;type:varchar(255)"`
}
2023-01-04 17:22:55 +08:00
func GetRegister(account, areaCode, userID string) (*Register, error) {
var r Register
2023-01-11 16:23:16 +08:00
return &r, RegisterDB.Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?",
2022-07-05 11:01:10 +08:00
userID, "", account, account, areaCode).Take(&r).Error
2021-12-01 12:16:02 +08:00
}
2022-02-21 16:24:25 +08:00
2022-08-15 20:21:06 +08:00
func SetPassword(account, password, ex, userID, areaCode, ip string) error {
2023-01-04 17:22:55 +08:00
r := Register{
2022-08-15 20:21:06 +08:00
Account: account,
Password: password,
Ex: ex,
UserID: userID,
RegisterIP: ip,
AreaCode: areaCode,
2021-12-01 12:16:02 +08:00
}
2023-01-11 16:23:16 +08:00
return RegisterDB.Table("registers").Create(&r).Error
2022-02-21 16:24:25 +08:00
}
2021-12-01 12:16:02 +08:00
2022-02-21 16:24:25 +08:00
func ResetPassword(account, password string) error {
2023-01-04 17:22:55 +08:00
r := Register{
2022-02-23 15:27:23 +08:00
Password: password,
2022-02-21 16:24:25 +08:00
}
2023-01-11 16:23:16 +08:00
return RegisterDB.Table("registers").Where("account = ?", account).Updates(&r).Error
2021-12-01 12:16:02 +08:00
}