diff --git a/config.go b/config.go index 0f77f10..448ba80 100644 --- a/config.go +++ b/config.go @@ -50,7 +50,10 @@ type ConfigFile struct { S3Region string `json:"s3_region"` S3Bucket string `json:"s3_bucket"` - Org string `json:"org"` + Org string `json:"org"` + DomainName string `json:"domain_name"` + NewUserDN string `json:"new_user_dn"` + NewUserPassword string `json:"new_user_password"` } var configFlag = flag.String("config", "./config.json", "Configuration file path") diff --git a/invite.go b/invite.go index 6cd92ed..5fb1ae5 100644 --- a/invite.go +++ b/invite.go @@ -39,9 +39,9 @@ func checkInviterLogin(w http.ResponseWriter, r *http.Request) *LoginStatus { func handleInviteNewAccount(w http.ResponseWriter, r *http.Request) { login := checkInviterLogin(w, r) - if login == nil { - return - } + // if login == nil { + // return + // } handleNewAccount(w, r, login.conn, login.Info.DN) } @@ -124,7 +124,7 @@ func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invi r.ParseForm() newUser := NewUser{} - login := checkLogin(w, r) + // login := checkLogin(w, r) newUser.CN = fmt.Sprintf("%s@%s", strings.TrimSpace(strings.Join(r.Form["username"], "")), "lesgv.com") newUser.DisplayName = strings.TrimSpace(strings.Join(r.Form["displayname"], "")) @@ -142,7 +142,7 @@ func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invi data.ErrorPasswordMismatch = true } else { newUser.Password = password2 - data.Success = addNewUser(newUser, config, login) + data.Success = addNewUser(newUser, config) http.Redirect(w, r, "/admin/ldap/"+newUser.DN, http.StatusFound) } diff --git a/templates/invite_new_account.html b/templates/invite_new_account.html index baf2278..011878e 100644 --- a/templates/invite_new_account.html +++ b/templates/invite_new_account.html @@ -92,10 +92,18 @@ function changeDisplayname () { displayname = document.getElementById("displayname"); username = document.getElementById("username"); + givenname = document.getElementById("givenname"); + sn = document.getElementById("sn"); if (!username.value) { username.value = displayname.value; changeUsername(); } + if (!givenname.value) { + givenname.value = displayname.value.split(" ")[0]; + } + if (!sn.value) { + sn.value = displayname.value.split(" ")[1]; + } } function changeUsername () { username = document.getElementById("username"); diff --git a/utils.go b/utils.go index 9a16443..d905862 100644 --- a/utils.go +++ b/utils.go @@ -40,9 +40,10 @@ func suggestPassword() string { return password } -func addNewUser(newUser NewUser, config *ConfigFile, login *LoginStatus) bool { +func addNewUser(newUser NewUser, config *ConfigFile) bool { log.Printf(fmt.Sprint("Adding New User")) - // l := openLdap(config) + l := openLdap(*config) + l.Bind(config.NewUserDN, config.NewUserPassword) // l.Bind(config.) dn := newUser.DN req := ldap.NewAddRequest(dn, nil) @@ -72,7 +73,10 @@ func addNewUser(newUser NewUser, config *ConfigFile, login *LoginStatus) bool { pw, _ := SSHAEncode(newUser.Password) req.Attribute("userPassword", []string{pw}) } - err := login.conn.Add(req) + + // conn := + + err := l.Add(req) log.Printf(fmt.Sprintf("71: %v", err)) log.Printf(fmt.Sprintf("72: %v", req)) log.Printf(fmt.Sprintf("73: %v", newUser))