forked from nixcn/nixcn-cms
27
data/user.go
27
data/user.go
@@ -165,18 +165,25 @@ func (self *User) FastListUsers(limit, offset int64) (*[]UserSearchDoc, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *User) GenCheckinCode(eventId uuid.UUID) (*string, error) {
|
func (self *User) GenCheckinCode(eventId uuid.UUID) (*string, error) {
|
||||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
||||||
randomNumber := rng.Intn(900000) + 100000
|
|
||||||
randNumString := fmt.Sprintf("%06d", randomNumber)
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ttl := viper.GetDuration("ttl.checkin_code_ttl")
|
ttl := viper.GetDuration("ttl.checkin_code_ttl")
|
||||||
Redis.Set(
|
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
ctx,
|
|
||||||
"checkin_code:"+randNumString,
|
for {
|
||||||
self.UserId.String()+":"+eventId.String(),
|
code := fmt.Sprintf("%06d", rng.Intn(900000)+100000)
|
||||||
ttl,
|
ok, err := Redis.SetNX(
|
||||||
)
|
ctx,
|
||||||
return &randNumString, nil
|
"checkin_code:"+code,
|
||||||
|
"user_id:"+self.UserId.String()+":event_id:"+eventId.String(),
|
||||||
|
ttl,
|
||||||
|
).Result()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
return &code, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *User) VerifyCheckinCode(checkinCode string) (*uuid.UUID, error) {
|
func (self *User) VerifyCheckinCode(checkinCode string) (*uuid.UUID, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user