fixed a bug that stopped sessions from being deleted
This commit is contained in:
@@ -9,6 +9,7 @@ type EventType int
|
||||
|
||||
const (
|
||||
ReadFile EventType = iota
|
||||
AuthenticateUser
|
||||
)
|
||||
|
||||
func Info(message string) {
|
||||
@@ -58,5 +59,10 @@ func Event(eventType EventType, eventData ...any) {
|
||||
log.Printf("Reading file %s", eventData[0])
|
||||
break
|
||||
}
|
||||
case AuthenticateUser:
|
||||
{
|
||||
log.Printf("Authenticating user %s", eventData[0])
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ func createUserPhoto(username string, photoData []byte) error {
|
||||
}
|
||||
|
||||
func authenticateUser(username, password string) (UserData, error) {
|
||||
logging.Event(logging.AuthenticateUser, username)
|
||||
ldapServerMutex.Lock()
|
||||
defer ldapServerMutex.Unlock()
|
||||
if ldapServer.Connection == nil {
|
||||
@@ -232,9 +233,7 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
sessionMutex.Lock()
|
||||
delete(sessions, token)
|
||||
sessionMutex.Unlock()
|
||||
deleteSession(token)
|
||||
http.Redirect(w, r, "/login", http.StatusSeeOther)
|
||||
}
|
||||
|
||||
|
||||
@@ -94,3 +94,13 @@ func validateSession(r *http.Request) (bool, *SessionData) {
|
||||
logging.Infof("Validated session for %s", sessionData.data.Username)
|
||||
return true, &sessionData
|
||||
}
|
||||
|
||||
func deleteSession(session_id string) {
|
||||
sessionMutex.Lock()
|
||||
|
||||
tokenEncoded := sha256.Sum256([]byte(session_id))
|
||||
tokenEncodedString := string(tokenEncoded[:])
|
||||
|
||||
delete(sessions, tokenEncodedString)
|
||||
sessionMutex.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user