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) {
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
randomNumber := rng.Intn(900000) + 100000
|
||||
randNumString := fmt.Sprintf("%06d", randomNumber)
|
||||
ctx := context.Background()
|
||||
ttl := viper.GetDuration("ttl.checkin_code_ttl")
|
||||
Redis.Set(
|
||||
ctx,
|
||||
"checkin_code:"+randNumString,
|
||||
self.UserId.String()+":"+eventId.String(),
|
||||
ttl,
|
||||
)
|
||||
return &randNumString, nil
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
for {
|
||||
code := fmt.Sprintf("%06d", rng.Intn(900000)+100000)
|
||||
ok, err := Redis.SetNX(
|
||||
ctx,
|
||||
"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) {
|
||||
|
||||
Reference in New Issue
Block a user