2023-11-01 14:11:00 +01:00
|
|
|
/*
|
|
|
|
* Sicherheitsunterweisung
|
|
|
|
* Copyright (C) 2023 Jason Streifling
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-10-05 18:08:44 +02:00
|
|
|
package main
|
2023-10-04 17:13:03 +02:00
|
|
|
|
2023-10-04 17:29:22 +02:00
|
|
|
import (
|
2023-10-10 20:57:53 +02:00
|
|
|
"html/template"
|
2023-10-04 17:29:22 +02:00
|
|
|
"log"
|
|
|
|
"net/http"
|
2023-10-16 18:51:52 +02:00
|
|
|
|
2023-10-28 08:49:28 +02:00
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/data"
|
2024-01-06 08:27:54 +01:00
|
|
|
"streifling.com/jason/sicherheitsunterweisung/packages/server"
|
2023-10-04 17:29:22 +02:00
|
|
|
)
|
|
|
|
|
2023-10-19 20:06:08 +02:00
|
|
|
func main() {
|
2023-10-28 08:49:28 +02:00
|
|
|
db, err := data.OpenDB("sicherheitsunterweisung")
|
2023-10-05 17:42:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
2023-10-05 19:52:11 +02:00
|
|
|
}
|
2023-10-04 18:55:48 +02:00
|
|
|
|
2024-01-06 08:27:54 +01:00
|
|
|
mux := server.NewMux()
|
|
|
|
sessions := make([]*server.Session, 0)
|
|
|
|
sessionChan := make(chan *server.Session)
|
2023-10-19 20:06:08 +02:00
|
|
|
|
2023-10-04 18:55:48 +02:00
|
|
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
2023-10-10 20:57:53 +02:00
|
|
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
template.Must(template.ParseFiles("templates/index.html", "templates/login.html")).Execute(w, nil)
|
|
|
|
})
|
2024-01-06 08:27:54 +01:00
|
|
|
mux.HandleFunc("/internal-login/", server.HandleInternalLogin(db, &sessions, sessionChan))
|
|
|
|
mux.HandleFunc("/external-login/", server.HandleExternalLogin(&sessions))
|
2023-10-19 20:06:08 +02:00
|
|
|
|
2023-10-28 09:17:10 +02:00
|
|
|
go mux.HandleSessions(db, sessionChan, &sessions)
|
2023-10-04 17:29:22 +02:00
|
|
|
|
|
|
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
|
|
|
}
|