MCPcopy Index your code
hub / github.com/TruthHun/BookStack / CheckIPIsAllowed

Method CheckIPIsAllowed

models/reg_limit.go:38–58  ·  view source on GitHub ↗
(ip string)

Source from the content-addressed store, hash-verified

36}
37
38func (rl *RegLimit) CheckIPIsAllowed(ip string) (allowHour, allowDaily bool) {
39 now := time.Now()
40 o := orm.NewOrm()
41 if rl.HourRegNum > 0 {
42 hourBefore := now.Add(-1 * time.Hour)
43 cnt, _ := o.QueryTable(rl).Filter("ip", ip).Filter("created_at__gt", hourBefore).Filter("created_at__lt", now).Count()
44 if int(cnt) >= rl.HourRegNum {
45 return false, true
46 }
47 }
48
49 DayBefore := now.Add(-24 * time.Hour)
50 if rl.DailyRegNum > 0 {
51 cnt, _ := o.QueryTable(rl).Filter("ip", ip).Filter("created_at__gt", DayBefore).Filter("created_at__lt", now).Count()
52 if int(cnt) >= rl.DailyRegNum {
53 return true, false
54 }
55 }
56 o.QueryTable(rl).Filter("created_at__lt", DayBefore).Delete()
57 return true, true
58}
59
60func (rl *RegLimit) Insert(ip string) (err error) {
61 rl.Ip = ip

Callers 1

RegisterMethod · 0.95

Calls 3

AddMethod · 0.45
CountMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected