token-validator: ip, ping, ...

This commit is contained in:
nemunaire 2019-02-27 05:49:08 +01:00
commit 081b22a64a
5 changed files with 118 additions and 28 deletions

View file

@ -87,7 +87,7 @@ func getStudent(id int) (s Student, err error) {
}
func getStudentByLogin(login string) (s Student, err error) {
err = DBQueryRow("SELECT id_student, login, time FROM students WHERE login=?", login).Scan(&s.Id, &s.Login, &s.Time)
err = DBQueryRow("SELECT S.id_student, S.login, MAX(L.time), L.ip, L.mac FROM students S INNER JOIN (SELECT a.id_student, a.time, a.ip, a.mac FROM student_login a INNER JOIN (SELECT id_student, MAX(time) AS time FROM student_login GROUP BY id_student) b ON a.id_student = b.id_student AND a.time = b.time) L ON S.id_student = L.id_student WHERE login=?", login).Scan(&s.Id, &s.Login, &s.Time, &s.IP, &s.MAC)
return
}
@ -155,6 +155,9 @@ func createStudent(_ httprouter.Params, body []byte) (interface{}, error) {
}
}
exist.registerAccess(std.IP, std.MAC)
exist.IP = fmt.Sprintf("172.23.0.%d", exist.IPSuffix())
return exist, nil
}