|
|
@@ -98,6 +98,25 @@ func AddToAuthMap(conn *websocket.Conn, token map[string]string, authed bool) er
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// the same but the other way
|
|
|
+func RemoveFromAuthMap(tokenId string, fromAuthorized bool) error {
|
|
|
+ if fromAuthorized {
|
|
|
+ AuthenticatedClients.Lock()
|
|
|
+ if _, ok := AuthenticatedClients.Conns[tokenId]; ok {
|
|
|
+ delete(AuthenticatedClients.Conns, tokenId)
|
|
|
+ }
|
|
|
+ AuthenticatedClients.Unlock()
|
|
|
+ } else {
|
|
|
+ UnauthClients.Lock()
|
|
|
+ if _, ok := UnauthClients.Conns[tokenId]; ok {
|
|
|
+ delete(UnauthClients.Conns, tokenId)
|
|
|
+ }
|
|
|
+ UnauthClients.Unlock()
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// check the validity of the token
|
|
|
func CheckToken(token map[string]string, conn *websocket.Conn, r *http.Request, setup bool) bool {
|
|
|
// great you have token. we see if valid.
|
|
|
@@ -197,7 +216,7 @@ func AddSession(tokenID string, hash string, created string, authorized bool) er
|
|
|
if err := config.UpdateConf(update); err != nil {
|
|
|
return fmt.Errorf("Error adding session: %v", err)
|
|
|
}
|
|
|
- if err := config.RemoveSession(tokenID, false); err != nil {
|
|
|
+ if err := RemoveFromAuthMap(tokenID, false); err != nil {
|
|
|
return fmt.Errorf("Error removing session: %v", err)
|
|
|
}
|
|
|
} else {
|
|
|
@@ -211,7 +230,7 @@ func AddSession(tokenID string, hash string, created string, authorized bool) er
|
|
|
if err := config.UpdateConf(update); err != nil {
|
|
|
return fmt.Errorf("Error adding session: %v", err)
|
|
|
}
|
|
|
- if err := config.RemoveSession(tokenID, true); err != nil {
|
|
|
+ if err := RemoveFromAuthMap(tokenID, true); err != nil {
|
|
|
return fmt.Errorf("Error removing session: %v", err)
|
|
|
}
|
|
|
}
|