Compare commits
3 Commits
bcaa023d3c
...
074b3f8f31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
074b3f8f31 | ||
|
|
f8b3c10933 | ||
|
|
c11425dde7 |
@@ -1,7 +1,6 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
@@ -38,7 +37,7 @@ func Infof(message string, v ...any) {
|
||||
if currentLevel > InfoLevel {
|
||||
return
|
||||
}
|
||||
log.Printf("Info: %s", fmt.Sprintf(message, v...))
|
||||
log.Printf("Info: "+message, v...)
|
||||
}
|
||||
|
||||
func Debug(message string) {
|
||||
@@ -52,7 +51,7 @@ func Debugf(message string, v ...any) {
|
||||
if currentLevel > DebugLevel {
|
||||
return
|
||||
}
|
||||
log.Printf("Debug: %s", fmt.Sprintf(message, v...))
|
||||
log.Printf("Debug: "+message, v...)
|
||||
}
|
||||
|
||||
func Warn(message string) {
|
||||
@@ -66,7 +65,7 @@ func Warnf(message string, v ...any) {
|
||||
if currentLevel > WarnLevel {
|
||||
return
|
||||
}
|
||||
log.Printf("Warn: %s", fmt.Sprintf(message, v...))
|
||||
log.Printf("Warn: "+message, v...)
|
||||
}
|
||||
|
||||
func Error(message string) {
|
||||
@@ -80,7 +79,7 @@ func Errorf(message string, v ...any) {
|
||||
if currentLevel > ErrorLevel {
|
||||
return
|
||||
}
|
||||
log.Printf("Error: %s", fmt.Sprintf(message, v...))
|
||||
log.Printf("Error: "+message, v...)
|
||||
}
|
||||
|
||||
func Fatal(message string) {
|
||||
|
||||
@@ -228,10 +228,11 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if exist {
|
||||
if r.FormValue("csrf_token") != sessionData.CSRFToken {
|
||||
http.Error(w, "Unable to log user out", http.StatusForbidden)
|
||||
log.Printf("%s attempted to logout with invalid csrf token", sessionData.data.Username)
|
||||
logging.Debugf("%s attempted to logout with invalid csrf token", sessionData.data.Username)
|
||||
return
|
||||
}
|
||||
}
|
||||
logging.Infof("handling logout event for %s", sessionData.data.Username)
|
||||
|
||||
deleteSession(token)
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
@@ -289,9 +290,9 @@ func logoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func cleanupSessions() {
|
||||
sessionMutex.Lock()
|
||||
defer sessionMutex.Unlock()
|
||||
logging.Debug("Cleaning up stale session\n")
|
||||
|
||||
sessionMutex.Lock()
|
||||
sessions_to_delete := []string{}
|
||||
for session_token, session_data := range sessions {
|
||||
timeUntilRemoval := time.Minute * 5
|
||||
@@ -302,8 +303,9 @@ func cleanupSessions() {
|
||||
sessions_to_delete = append(sessions_to_delete, session_token)
|
||||
}
|
||||
}
|
||||
sessionMutex.Unlock()
|
||||
for _, session_id := range sessions_to_delete {
|
||||
delete(sessions, session_id)
|
||||
deleteSession(session_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user