Trying a utility file
This commit is contained in:
parent
7a7fd592e4
commit
24c1d118bd
2 changed files with 49 additions and 3 deletions
2
admin.go
2
admin.go
|
@ -79,7 +79,7 @@ func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
|
||||||
SN: "User",
|
SN: "User",
|
||||||
DisplayName: "New User",
|
DisplayName: "New User",
|
||||||
Mail: "newuser@lesgv.com",
|
Mail: "newuser@lesgv.com",
|
||||||
})
|
}, config, login)
|
||||||
|
|
||||||
templateAdminUsers.Execute(w, data)
|
templateAdminUsers.Execute(w, data)
|
||||||
}
|
}
|
||||||
|
|
50
utils.go
50
utils.go
|
@ -3,6 +3,8 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/go-ldap/ldap/v3"
|
||||||
// "bytes"
|
// "bytes"
|
||||||
// "crypto/rand"
|
// "crypto/rand"
|
||||||
// "encoding/binary"
|
// "encoding/binary"
|
||||||
|
@ -27,8 +29,52 @@ type NewUser struct {
|
||||||
Mail string
|
Mail string
|
||||||
SN string
|
SN string
|
||||||
UID string
|
UID string
|
||||||
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
func addNewUser(newUser NewUser) {
|
func openLdap(config ConfigFile) *ldap.Conn {
|
||||||
log.Printf(fmt.Sprint("Adding New User"))
|
l, err := ldap.DialURL(config.LdapServerAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprint("Erreur connect LDAP %v", err))
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addNewUser(newUser NewUser, config ConfigFile, login LoginStatus) bool {
|
||||||
|
log.Printf(fmt.Sprint("Adding New User"))
|
||||||
|
// l := openLdap(config)
|
||||||
|
// l.Bind(config.)
|
||||||
|
dn := newUser.DN
|
||||||
|
req := ldap.NewAddRequest(dn, nil)
|
||||||
|
req.Attribute("objectClass", []string{"top", "inetOrgPerson"})
|
||||||
|
if newUser.DisplayName != "" {
|
||||||
|
req.Attribute("displayName", []string{newUser.DisplayName})
|
||||||
|
}
|
||||||
|
if newUser.GivenName != "" {
|
||||||
|
req.Attribute("givenName", []string{newUser.GivenName})
|
||||||
|
}
|
||||||
|
if newUser.Mail != "" {
|
||||||
|
req.Attribute("mail", []string{newUser.Mail})
|
||||||
|
}
|
||||||
|
// if newUser.Member != "" {
|
||||||
|
// req.Attribute("member", []string{newUser.Member})
|
||||||
|
// }
|
||||||
|
if newUser.SN != "" {
|
||||||
|
req.Attribute("sn", []string{newUser.SN})
|
||||||
|
}
|
||||||
|
if newUser.Description != "" {
|
||||||
|
req.Attribute("description", []string{newUser.Description})
|
||||||
|
}
|
||||||
|
err := login.conn.Add(req)
|
||||||
|
// log.Printf(fmt.Sprintf("71: %v",err))
|
||||||
|
// log.Printf(fmt.Sprintf("72: %v",req))
|
||||||
|
// log.Printf(fmt.Sprintf("73: %v",newUser))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(fmt.Sprintf("75: %v", err))
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue