mirror of
https://github.com/lingble/databunker.git
synced 2026-03-20 03:53:43 +00:00
expire old consent records
This commit is contained in:
@@ -245,6 +245,7 @@ func (e mainEnv) dbCleanup() {
|
||||
if exp > 0 {
|
||||
e.db.deleteExpired0(TblName.Audit, exp)
|
||||
}
|
||||
e.db.expireConsentRecords()
|
||||
case <-e.stopChan:
|
||||
log.Printf("db cleanup closed\n")
|
||||
ticker.Stop()
|
||||
|
||||
@@ -148,3 +148,28 @@ func (dbobj dbcon) filterConsentRecords(brief string, offset int32, limit int32)
|
||||
//fmt.Printf("Found multiple documents (array of pointers): %+v\n", results)
|
||||
return resultJSON, count, nil
|
||||
}
|
||||
|
||||
func (dbobj dbcon) expireConsentRecords() error {
|
||||
records, err := dbobj.getExpiring(TblName.Consent, "status", "accept")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, rec := range records {
|
||||
now := int32(time.Now().Unix())
|
||||
// update date, status
|
||||
bdoc := bson.M{}
|
||||
bdoc["when"] = now
|
||||
bdoc["status"] = "expired"
|
||||
userTOKEN := rec["token"].(string)
|
||||
brief := rec["brief"].(string)
|
||||
fmt.Printf("This consent record is expired: %s - %s\n", userTOKEN, brief)
|
||||
if len(userTOKEN) > 0 {
|
||||
fmt.Printf("%s %s\n", userTOKEN, brief)
|
||||
dbobj.updateRecord2(TblName.Consent, "token", userTOKEN, "brief", brief, &bdoc, nil)
|
||||
} else {
|
||||
usercode := rec["who"].(string)
|
||||
dbobj.updateRecord2(TblName.Consent, "who", usercode, "brief", brief, &bdoc, nil)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
11
src/qldb.go
11
src/qldb.go
@@ -654,6 +654,13 @@ func (dbobj dbcon) cleanupRecord(t Tbl, keyName string, keyValue string, data in
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (dbobj dbcon) getExpiring(t Tbl, keyName string, keyValue string) ([]bson.M, error) {
|
||||
table := getTable(t)
|
||||
now := int32(time.Now().Unix())
|
||||
q := fmt.Sprintf("select * from %s WHERE endtime>0 AND endtime<%d AND %s=$1", table, now, escapeName(keyName))
|
||||
return dbobj.getListDo(q, keyValue)
|
||||
}
|
||||
|
||||
func (dbobj dbcon) getList(t Tbl, keyName string, keyValue string, start int32, limit int32) ([]bson.M, error) {
|
||||
table := getTable(t)
|
||||
if limit > 100 {
|
||||
@@ -668,6 +675,10 @@ func (dbobj dbcon) getList(t Tbl, keyName string, keyValue string, start int32,
|
||||
q = q + " LIMIT " + strconv.FormatInt(int64(limit), 10)
|
||||
}
|
||||
fmt.Printf("q: %s\n", q)
|
||||
return dbobj.getListDo(q, keyValue)
|
||||
}
|
||||
|
||||
func (dbobj dbcon) getListDo(q string, keyValue string) ([]bson.M, error) {
|
||||
tx, err := dbobj.db.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -288,7 +288,7 @@ func (e mainEnv) userLoginEnter(w http.ResponseWriter, r *http.Request, ps httpr
|
||||
|
||||
userTOKEN := userBson["token"].(string)
|
||||
event.Record = userTOKEN
|
||||
fmt.Printf("Found user record: %s\n", userTOKEN)
|
||||
fmt.Printf("Found user record: %s\n", userBson)
|
||||
tmpCode := userBson["tempcode"].(int32)
|
||||
if tmp == tmpCode {
|
||||
// user ented correct key
|
||||
|
||||
Reference in New Issue
Block a user