diff options
author | Alex Auvolat <alex@adnab.me> | 2020-02-09 17:45:22 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-02-09 17:45:22 +0100 |
commit | 27a411fe69cd3d8f669acb76b56d2390efc86deb (patch) | |
tree | 2a4e608f91036271412cd6f154e043f4587f497e /main.go | |
parent | 6297981c3bf01f94566ad76dc25b3b76c9c32029 (diff) | |
download | guichet-27a411fe69cd3d8f669acb76b56d2390efc86deb.tar.gz guichet-27a411fe69cd3d8f669acb76b56d2390efc86deb.zip |
Password change
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -94,6 +94,7 @@ func main() { http.HandleFunc("/", handleHome) http.HandleFunc("/logout", handleLogout) http.HandleFunc("/profile", handleProfile) + http.HandleFunc("/passwd", handlePasswd) staticfiles := http.FileServer(http.Dir("static")) http.Handle("/static/", http.StripPrefix("/static/", staticfiles)) @@ -358,3 +359,47 @@ func handleProfile(w http.ResponseWriter, r *http.Request) { templateProfile.Execute(w, data) } + +type PasswdTplData struct { + Status *LoginStatus + ErrorMessage string + NoMatchError bool + Success bool +} + +func handlePasswd(w http.ResponseWriter, r *http.Request) { + templatePasswd := template.Must(template.ParseFiles("templates/layout.html", "templates/passwd.html")) + + login := checkLogin(w, r) + if login == nil { + return + } + + data := &PasswdTplData{ + Status: login, + ErrorMessage: "", + Success: false, + } + + if r.Method == "POST" { + r.ParseForm() + + password := strings.Join(r.Form["password"], "") + password2 := strings.Join(r.Form["password2"], "") + + if password2 != password { + data.NoMatchError = true + } else { + modify_request := ldap.NewModifyRequest(login.Info.DN, nil) + modify_request.Replace("userpassword", []string{SSHAEncode([]byte(password))}) + err := login.conn.Modify(modify_request) + if err != nil { + data.ErrorMessage = err.Error() + } else { + data.Success = true + } + } + } + + templatePasswd.Execute(w, data) +} |