structs und funcs privat gemacht, wenn möglich
This commit is contained in:
@ -21,6 +21,19 @@ import (
|
||||
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
||||
)
|
||||
|
||||
func findCorrectLogin(l string, ss *[]*Session) (*briefing, *participant, bool) {
|
||||
for _, s := range *ss {
|
||||
for _, b := range s.briefings {
|
||||
for _, p := range b.participants {
|
||||
if l == p.login {
|
||||
return b, p, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
instructors, err := db.GetInstructors()
|
||||
@ -32,15 +45,15 @@ func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.H
|
||||
for _, i := range instructors {
|
||||
if r.PostFormValue("login") == fmt.Sprint(i.ID) {
|
||||
session := Session{
|
||||
UUID: uuid.New(),
|
||||
Instructor: *i,
|
||||
Briefings: make([]*Briefing, 0),
|
||||
uuid: uuid.New(),
|
||||
instructor: *i,
|
||||
briefings: make([]*briefing, 0),
|
||||
}
|
||||
(*ss) = append((*ss), &session)
|
||||
cs <- &session
|
||||
|
||||
data := tableHTMLData{SessionID: session.UUID}
|
||||
data.OTD, err = db.GetAllOverviewTableData()
|
||||
data := tableHTMLData{sessionID: session.uuid}
|
||||
data.otd, err = db.GetAllOverviewTableData()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
log.Panicln(err)
|
||||
@ -54,26 +67,13 @@ func HandleInternalLogin(db *data.DB, ss *[]*Session, cs chan<- *Session) http.H
|
||||
}
|
||||
}
|
||||
|
||||
func findCorrectLogin(l string, ss *[]*Session) (*Briefing, *Participant, bool) {
|
||||
for _, s := range *ss {
|
||||
for _, b := range s.Briefings {
|
||||
for _, p := range b.Participants {
|
||||
if l == p.Login {
|
||||
return b, p, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
func HandleExternalLogin(ss *[]*Session) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
briefing, participant, loginCorrect := findCorrectLogin(r.PostFormValue("login"), ss)
|
||||
if loginCorrect {
|
||||
data := participantHTMLData{
|
||||
BriefingID: briefing.UUID,
|
||||
Participant: Participant{Login: participant.Login},
|
||||
briefingID: briefing.uuid,
|
||||
participant: *participant,
|
||||
}
|
||||
|
||||
template.Must(template.ParseFiles("templates/participant.html")).ExecuteTemplate(w, "content", data)
|
||||
|
Reference in New Issue
Block a user