token-validator: save ping state (0: ping ok, 1: arping only)
This commit is contained in:
parent
22a3d75645
commit
c35a8f5e6b
3 changed files with 16 additions and 9 deletions
|
@ -26,18 +26,23 @@ func lastPing(student Student, body []byte) (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s Student) lastPongs() (pongs []time.Time, err error) {
|
||||
if rows, errr := DBQuery("SELECT time FROM student_pong WHERE id_student = ? ORDER BY time DESC", s.Id); errr != nil {
|
||||
type Pong struct {
|
||||
Date time.Time
|
||||
State bool
|
||||
}
|
||||
|
||||
func (s Student) lastPongs() (pongs []Pong, err error) {
|
||||
if rows, errr := DBQuery("SELECT time, state FROM student_pong WHERE id_student = ? ORDER BY time DESC", s.Id); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var t time.Time
|
||||
if err = rows.Scan(&t); err != nil {
|
||||
var p Pong
|
||||
if err = rows.Scan(&p.Date, &p.State); err != nil {
|
||||
return
|
||||
}
|
||||
pongs = append(pongs, t)
|
||||
pongs = append(pongs, p)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return
|
||||
|
@ -58,7 +63,7 @@ func stdPong(student Student, body []byte) (interface{}, error) {
|
|||
}
|
||||
|
||||
|
||||
if res, err := DBExec("INSERT INTO student_pong (id_student, time) VALUES (?, ?)", student.Id, time.Now()); err != nil {
|
||||
if res, err := DBExec("INSERT INTO student_pong (id_student, time, state) VALUES (?, ?, ?)", student.Id, time.Now(), gt.Challenge == 0); err != nil {
|
||||
return false, err
|
||||
} else if _, err := res.LastInsertId(); err != nil {
|
||||
return false, err
|
||||
|
|
Reference in a new issue