Factoring the model user and correcting password
This commit is contained in:
parent
0153f8acec
commit
5b9168fd1a
2 changed files with 7 additions and 11 deletions
14
login.go
14
login.go
|
@ -231,21 +231,21 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
|
||||||
templateLogin.Execute(w, LoginFormData{})
|
templateLogin.Execute(w, LoginFormData{})
|
||||||
return nil
|
return nil
|
||||||
} else if r.Method == "POST" {
|
} else if r.Method == "POST" {
|
||||||
log.Printf("%v", "Parsing Form handleLogin")
|
// log.Printf("%v", "Parsing Form handleLogin")
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
|
|
||||||
username := strings.Join(r.Form["username"], "")
|
username := strings.Join(r.Form["username"], "")
|
||||||
password := strings.Join(r.Form["password"], "")
|
password := strings.Join(r.Form["password"], "")
|
||||||
user_dn := fmt.Sprintf("%s=%s,%s", config.UserNameAttr, username, config.UserBaseDN)
|
user_dn := fmt.Sprintf("%s=%s,%s", config.UserNameAttr, username, config.UserBaseDN)
|
||||||
|
|
||||||
log.Printf("%v", user_dn)
|
// log.Printf("%v", user_dn)
|
||||||
log.Printf("%v", username)
|
// log.Printf("%v", username)
|
||||||
|
|
||||||
if strings.EqualFold(username, config.AdminAccount) {
|
if strings.EqualFold(username, config.AdminAccount) {
|
||||||
user_dn = username
|
user_dn = username
|
||||||
}
|
}
|
||||||
loginInfo, err := doLogin(w, r, username, user_dn, password)
|
loginInfo, err := doLogin(w, r, username, user_dn, password)
|
||||||
log.Printf("%v", loginInfo)
|
// log.Printf("%v", loginInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data := &LoginFormData{
|
data := &LoginFormData{
|
||||||
Username: username,
|
Username: username,
|
||||||
|
@ -275,8 +275,8 @@ func doLogin(w http.ResponseWriter, r *http.Request, username string, user_dn st
|
||||||
|
|
||||||
err := l.Bind(user_dn, password)
|
err := l.Bind(user_dn, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v", err)
|
log.Printf("doLogin : %v", err)
|
||||||
log.Printf("%v", user_dn)
|
log.Printf("doLogin : %v", user_dn)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ func doLogin(w http.ResponseWriter, r *http.Request, username string, user_dn st
|
||||||
|
|
||||||
err = session.Save(r, w)
|
err = session.Save(r, w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%v", err)
|
log.Printf("doLogin Session Save: %v", err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,6 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func modify(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
func modify(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
log.Printf("Modify User : %v", user)
|
|
||||||
modify_request := ldap.NewModifyRequest(user.DN, nil)
|
modify_request := ldap.NewModifyRequest(user.DN, nil)
|
||||||
previousUser, err := get(user, config, ldapConn)
|
previousUser, err := get(user, config, ldapConn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -169,9 +168,6 @@ func replaceIfContent(modifReq *ldap.ModifyRequest, key string, value string, pr
|
||||||
if value != "" {
|
if value != "" {
|
||||||
modifReq.Replace(key, []string{value})
|
modifReq.Replace(key, []string{value})
|
||||||
} else if previousValue != "" {
|
} else if previousValue != "" {
|
||||||
log.Printf("modify User delete %v", key)
|
|
||||||
log.Printf("modify User delete %v", value)
|
|
||||||
log.Printf("modify User delete %v", previousValue)
|
|
||||||
modifReq.Delete(key, []string{previousValue})
|
modifReq.Delete(key, []string{previousValue})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue