Factoring the model user and correcting password

This commit is contained in:
Chris Mann 2023-07-22 08:28:23 +02:00
parent b182683030
commit 2cc58a6e09
2 changed files with 101 additions and 84 deletions

View file

@ -88,11 +88,22 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
return checkLogin(w, r)
}
ldapUser, err := get(User{
DN: login_info.DN,
}, config, l)
loginStatus := &LoginStatus{
Info: login_info,
conn: l,
UserEntry: ldapUser.UserEntry,
CanAdmin: ldapUser.CanAdmin,
CanInvite: ldapUser.CanInvite,
}
return loginStatus
/*
requestKind := "(objectClass=organizationalPerson)"
if strings.EqualFold(login_info.DN, config.AdminAccount) {
requestKind = "(objectclass=*)"
@ -176,6 +187,7 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
// }
return loginStatus
*/
}
func handleLogout(w http.ResponseWriter, r *http.Request) {

View file

@ -6,6 +6,7 @@ package main
import (
"fmt"
"log"
"strings"
"github.com/go-ldap/ldap/v3"
)
@ -25,6 +26,7 @@ type User struct {
Password string
CanAdmin bool
CanInvite bool
UserEntry *ldap.Entry
}
func get(user User, config *ConfigFile, ldapConn *ldap.Conn) (*User, error) {
@ -52,6 +54,9 @@ func get(user User, config *ConfigFile, ldapConn *ldap.Conn) (*User, error) {
SN: searchRes.Entries[0].GetAttributeValue("sn"),
UID: searchRes.Entries[0].GetAttributeValue("uid"),
CN: searchRes.Entries[0].GetAttributeValue("cn"),
CanAdmin: strings.EqualFold(user.DN, config.AdminAccount),
CanInvite: true,
UserEntry: searchRes.Entries[0],
}
return &resUser, nil
}