Implementing Activate User

This commit is contained in:
Chris Mann 2023-07-21 14:15:44 +02:00
parent 7ff0a9d14e
commit 83f1d05c6c
3 changed files with 18 additions and 20 deletions

View file

@ -6,8 +6,8 @@ package main
import ( import (
"crypto/tls" "crypto/tls"
"fmt"
"log" "log"
"net"
"net/http" "net/http"
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
@ -20,21 +20,22 @@ func logRequest(handler http.Handler) http.Handler {
}) })
} }
func ldapOpen(w http.ResponseWriter) *ldap.Conn { func ldapOpen(w http.ResponseWriter) (*ldap.Conn, error) {
l, err := ldap.DialURL(config.LdapServerAddr)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Printf(fmt.Sprintf("27: %v %v", err, l))
return nil
}
if config.LdapTLS { if config.LdapTLS {
err = l.StartTLS(&tls.Config{InsecureSkipVerify: true}) tlsConf := &tls.Config{
if err != nil { ServerName: config.LdapServerAddr,
http.Error(w, err.Error(), http.StatusInternalServerError) InsecureSkipVerify: true,
return nil
} }
return ldap.DialTLS("tcp", net.JoinHostPort(config.LdapServerAddr, "636"), tlsConf)
} else {
return ldap.DialURL("ldap://" + config.LdapServerAddr)
} }
return l // if err != nil {
// http.Error(w, err.Error(), http.StatusInternalServerError)
// log.Printf(fmt.Sprintf("27: %v %v", err, l))
// return nil
// }
// return l
} }

View file

@ -39,7 +39,7 @@ func checkInviterLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
// New account creation directly from interface // New account creation directly from interface
func handleInviteNewAccount(w http.ResponseWriter, r *http.Request) { func handleInviteNewAccount(w http.ResponseWriter, r *http.Request) {
l := ldapOpen(w) l, err := ldapOpen(w)
l.Bind(config.NewUserDN, config.NewUserPassword) l.Bind(config.NewUserDN, config.NewUserPassword)
// login := checkInviterLogin(w, r) // login := checkInviterLogin(w, r)

View file

@ -62,7 +62,7 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
} }
} }
l := ldapOpen(w) l, err := ldapOpen(w)
if l == nil { if l == nil {
return nil return nil
} }
@ -236,10 +236,7 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
} }
func doLogin(w http.ResponseWriter, r *http.Request, username string, user_dn string, password string) (*LoginInfo, error) { func doLogin(w http.ResponseWriter, r *http.Request, username string, user_dn string, password string) (*LoginInfo, error) {
l := ldapOpen(w) l, _ := ldapOpen(w)
if l == nil {
return nil, nil
}
err := l.Bind(user_dn, password) err := l.Bind(user_dn, password)
if err != nil { if err != nil {