mirror of
https://github.com/m1k1o/neko.git
synced 2025-07-17 00:35:58 +02:00
auth moved from websockets to session.
This commit is contained in:
parent
3ea979ed47
commit
c10b2212d1
8 changed files with 65 additions and 53 deletions
37
internal/session/auth.go
Normal file
37
internal/session/auth.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package session
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
// TODO: Refactor
|
||||
func (manager *SessionManagerCtx) Authenticate(r *http.Request) (string, string, bool, error) {
|
||||
ip := r.RemoteAddr
|
||||
|
||||
//if ws.conf.Proxy {
|
||||
// ip = utils.ReadUserIP(r)
|
||||
//}
|
||||
|
||||
id, err := utils.NewUID(32)
|
||||
if err != nil {
|
||||
return "", ip, false, err
|
||||
}
|
||||
|
||||
passwords, ok := r.URL.Query()["password"]
|
||||
if !ok || len(passwords[0]) < 1 {
|
||||
return "", ip, false, fmt.Errorf("no password provided")
|
||||
}
|
||||
|
||||
if passwords[0] == manager.config.AdminPassword {
|
||||
return id, ip, true, nil
|
||||
}
|
||||
|
||||
if passwords[0] == manager.config.Password {
|
||||
return id, ip, false, nil
|
||||
}
|
||||
|
||||
return "", ip, false, fmt.Errorf("invalid password: %s", passwords[0])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue