even furhter sigh
This commit is contained in:
parent
1af237bb2d
commit
9b75094613
@ -21,14 +21,11 @@ var _db db.Session
|
|||||||
var _wan *webauthn.WebAuthn
|
var _wan *webauthn.WebAuthn
|
||||||
var _sess *scs.SessionManager
|
var _sess *scs.SessionManager
|
||||||
|
|
||||||
func Initialize(wan *webauthn.WebAuthn, db db.Session) {
|
func Route(wan *webauthn.WebAuthn, db db.Session, router http.Handler) http.Handler {
|
||||||
sessionManager := scs.New()
|
|
||||||
sessionManager.Lifetime = 5 * time.Minute
|
|
||||||
_db = db
|
_db = db
|
||||||
_wan = wan
|
_wan = wan
|
||||||
}
|
_sess = scs.New()
|
||||||
|
_sess.Lifetime = 5 * time.Minute
|
||||||
func Route(router http.Handler) http.Handler {
|
|
||||||
return _sess.LoadAndSave(router)
|
return _sess.LoadAndSave(router)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +44,7 @@ func LoginHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params
|
|||||||
password := req.FormValue("password")
|
password := req.FormValue("password")
|
||||||
|
|
||||||
user := &user.User{}
|
user := &user.User{}
|
||||||
if err := _db.Get(user, db.Cond{"name": username}); err != nil {
|
if err := _db.Get(user, db.Cond{"handle": username}); err != nil {
|
||||||
err := &errors.InvalidCredentials{Status: http.StatusForbidden, Reason: fmt.Sprintf("User not found for name: %s (%s)", username, err)}
|
err := &errors.InvalidCredentials{Status: http.StatusForbidden, Reason: fmt.Sprintf("User not found for name: %s (%s)", username, err)}
|
||||||
err.Log()
|
err.Log()
|
||||||
http.Error(w, err.Error(), err.Code())
|
http.Error(w, err.Error(), err.Code())
|
||||||
|
@ -191,8 +191,6 @@ func Initialize(config *Config) (http.Handler, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
auth.Initialize(wan, _db)
|
|
||||||
|
|
||||||
serverRoot, err := fs.Sub(staticFiles, "static")
|
serverRoot, err := fs.Sub(staticFiles, "static")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -216,7 +214,7 @@ func Initialize(config *Config) (http.Handler, error) {
|
|||||||
router.POST("/api/user/:id", allowCORS(auth.RequireAdmin(auth.Enforce2FA(updateUser))))
|
router.POST("/api/user/:id", allowCORS(auth.RequireAdmin(auth.Enforce2FA(updateUser))))
|
||||||
router.DELETE("/api/user/:id", allowCORS(auth.RequireAdmin(auth.Enforce2FA(deleteUser))))
|
router.DELETE("/api/user/:id", allowCORS(auth.RequireAdmin(auth.Enforce2FA(deleteUser))))
|
||||||
|
|
||||||
return auth.Route(router), nil
|
return auth.Route(wan, _db, router), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderTemplate(template []byte) httprouter.Handle {
|
func renderTemplate(template []byte) httprouter.Handle {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// Copyright © 2022 Roberto Hidalgo <nidito@un.rob.mx>
|
||||||
import * as webauthn from "./webauthn.js"
|
import * as webauthn from "./webauthn.js"
|
||||||
|
|
||||||
const host = document.location.protocol + "//" + document.location.host
|
const host = document.location.protocol + "//" + document.location.host
|
||||||
|
Loading…
Reference in New Issue
Block a user