aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-09 17:45:22 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-09 17:45:22 +0100
commit27a411fe69cd3d8f669acb76b56d2390efc86deb (patch)
tree2a4e608f91036271412cd6f154e043f4587f497e /main.go
parent6297981c3bf01f94566ad76dc25b3b76c9c32029 (diff)
downloadguichet-27a411fe69cd3d8f669acb76b56d2390efc86deb.tar.gz
guichet-27a411fe69cd3d8f669acb76b56d2390efc86deb.zip
Password change
Diffstat (limited to 'main.go')
-rw-r--r--main.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/main.go b/main.go
index aa2bad7..cac2948 100644
--- a/main.go
+++ b/main.go
@@ -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)
+}