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

View file

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