token-validator: display last known IP and MAC for students
This commit is contained in:
parent
e08c9306da
commit
20749da348
@ -50,6 +50,8 @@ type Student struct {
|
||||
Id int64 `json:"id"`
|
||||
Login string `json:"login"`
|
||||
Time time.Time `json:"time"`
|
||||
IP string `json:"ip"`
|
||||
MAC string `json:"mac"`
|
||||
}
|
||||
|
||||
type uploadedStudent struct {
|
||||
@ -59,14 +61,14 @@ type uploadedStudent struct {
|
||||
}
|
||||
|
||||
func getStudents() (students []Student, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_student, login, time FROM students"); errr != nil {
|
||||
if rows, errr := DBQuery("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"); errr != nil {
|
||||
return nil, errr
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var s Student
|
||||
if err = rows.Scan(&s.Id, &s.Login, &s.Time); err != nil {
|
||||
if err = rows.Scan(&s.Id, &s.Login, &s.Time, &s.IP, &s.MAC); err != nil {
|
||||
return
|
||||
}
|
||||
students = append(students, s)
|
||||
@ -80,7 +82,7 @@ func getStudents() (students []Student, err error) {
|
||||
}
|
||||
|
||||
func getStudent(id int) (s Student, err error) {
|
||||
err = DBQueryRow("SELECT id_student, login, time FROM students WHERE id_student=?", id).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 S.id_student=?", id).Scan(&s.Id, &s.Login, &s.Time, &s.IP, &s.MAC)
|
||||
return
|
||||
}
|
||||
|
||||
@ -101,7 +103,7 @@ func NewStudent(login string) (Student, error) {
|
||||
} else if sid, err := res.LastInsertId(); err != nil {
|
||||
return Student{}, err
|
||||
} else {
|
||||
return Student{sid, login, time.Now()}, nil
|
||||
return Student{sid, login, time.Now(), "", ""}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user