Implementing Activate User

This commit is contained in:
Chris Mann 2023-07-21 09:13:17 +02:00
parent 395c00b9ec
commit 891f18f009
4 changed files with 24 additions and 9 deletions

View file

@ -51,6 +51,9 @@ type ConfigFile struct {
S3Bucket string `json:"s3_bucket"`
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")

View file

@ -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)
}

View file

@ -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");

View file

@ -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))