Factoring the model user and correcting password

This commit is contained in:
Chris Mann 2023-07-22 08:17:20 +02:00
parent 890604b943
commit b182683030

View file

@ -23,6 +23,37 @@ type User struct {
UID string UID string
Description string Description string
Password string Password string
CanAdmin bool
CanInvite bool
}
func get(user User, config *ConfigFile, ldapConn *ldap.Conn) (*User, error) {
searchReq := ldap.NewSearchRequest(
user.DN,
ldap.ScopeBaseObject,
0,
0,
0,
false,
"",
[]string{
"*",
},
nil,
)
searchRes, err := ldapConn.Search(searchReq)
if err != nil {
return nil, err
}
resUser := User{
DN: user.DN,
GivenName: searchRes.Entries[0].GetAttributeValue("givenName"),
DisplayName: searchRes.Entries[0].GetAttributeValue("displayName"),
SN: searchRes.Entries[0].GetAttributeValue("sn"),
UID: searchRes.Entries[0].GetAttributeValue("uid"),
CN: searchRes.Entries[0].GetAttributeValue("cn"),
}
return &resUser, nil
} }
func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error { func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {