token-handler: handle authorization through Epita CRI LDAP
This commit is contained in:
parent
58e541d6ad
commit
38902bee8d
6 changed files with 194 additions and 12 deletions
|
@ -59,11 +59,11 @@ func init() {
|
|||
}
|
||||
|
||||
type Student struct {
|
||||
Id int64 `json:"id"`
|
||||
Login string `json:"login"`
|
||||
Time time.Time `json:"time"`
|
||||
IP string `json:"ip"`
|
||||
MAC string `json:"mac"`
|
||||
Id int64 `json:"id"`
|
||||
Login string `json:"login"`
|
||||
Time *time.Time `json:"time"`
|
||||
IP *string `json:"ip"`
|
||||
MAC *string `json:"mac"`
|
||||
}
|
||||
|
||||
type uploadedStudent struct {
|
||||
|
@ -106,16 +106,17 @@ func getStudentByLogin(login string) (s Student, err error) {
|
|||
func studentExists(login string) bool {
|
||||
var z int
|
||||
err := DBQueryRow("SELECT 1 FROM students WHERE login=?", login).Scan(&z)
|
||||
return err != nil && z == 1
|
||||
return err == nil && z == 1
|
||||
}
|
||||
|
||||
func NewStudent(login string) (Student, error) {
|
||||
if res, err := DBExec("INSERT INTO students (login, time) VALUES (?, ?)", login, time.Now()); err != nil {
|
||||
t := time.Now()
|
||||
if res, err := DBExec("INSERT INTO students (login, time) VALUES (?, ?)", login, t); err != nil {
|
||||
return Student{}, err
|
||||
} else if sid, err := res.LastInsertId(); err != nil {
|
||||
return Student{}, err
|
||||
} else {
|
||||
return Student{sid, login, time.Now(), "", ""}, nil
|
||||
return Student{sid, login, &t, nil, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +169,8 @@ func createStudent(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
}
|
||||
exist.registerAccess(std.IP, std.MAC)
|
||||
|
||||
exist.IP = fmt.Sprintf("172.23.0.%d", exist.IPSuffix())
|
||||
ip := fmt.Sprintf("172.23.0.%d", exist.IPSuffix())
|
||||
exist.IP = &ip
|
||||
|
||||
return exist, nil
|
||||
}
|
||||
|
|
Reference in a new issue