diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-09-15 13:59:48 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-09-15 13:59:48 +0200 |
commit | 02e384f99eb10ab299805073c37ac2f4ed3f2cdc (patch) | |
tree | be45a1a68f18dd1a0c58c6879aaba469ca73f3c9 | |
parent | 1e75c21b65021da0c3c5a8be9be12114a2327464 (diff) | |
download | guichet-02e384f99eb10ab299805073c37ac2f4ed3f2cdc.tar.gz guichet-02e384f99eb10ab299805073c37ac2f4ed3f2cdc.zip |
extract "build DN logic"
-rw-r--r-- | main.go | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -198,6 +198,9 @@ func logRequest(handler http.Handler) http.Handler { func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus { var login_info *LoginInfo + //@FIXME check authentication header + + session, err := store.Get(r, SESSION_NAME) if err == nil { username, ok := session.Values["login_username"] @@ -364,6 +367,15 @@ type LoginFormData struct { ErrorMessage string } +func buildUserDN(username string) string { + user_dn := fmt.Sprintf("%s=%s,%s", config.UserNameAttr, username, config.UserBaseDN) + if strings.EqualFold(username, config.AdminAccount) { + user_dn = username + } + + return user_dn +} + func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo { templateLogin := getTemplate("login.html") @@ -375,10 +387,7 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo { username := strings.Join(r.Form["username"], "") password := strings.Join(r.Form["password"], "") - user_dn := fmt.Sprintf("%s=%s,%s", config.UserNameAttr, username, config.UserBaseDN) - if strings.EqualFold(username, config.AdminAccount) { - user_dn = username - } + user_dn := buildUserDN(username) l := ldapOpen(w) if l == nil { |