aboutsummaryrefslogtreecommitdiff
path: root/profile.go
diff options
context:
space:
mode:
authorMrArmonius <mrarmonius@gmail.com>2021-07-30 00:04:17 +0200
committerAlex Auvolat <alex@adnab.me>2021-08-16 12:54:08 +0200
commita2a484daba1ef42d82f596a989caf203ee9a370f (patch)
treea3ec45738fa59448dd99d6dd5e69172f18043e90 /profile.go
parent0ca6a159b215967a6d13b9bad5c008983e032c3f (diff)
downloadguichet-a2a484daba1ef42d82f596a989caf203ee9a370f.tar.gz
guichet-a2a484daba1ef42d82f596a989caf203ee9a370f.zip
Add profile image front-end and back-end
Correct when empty result The image showed when the result was empty. Now if the `dn == ""` then we write in the column image just `""`
Diffstat (limited to 'profile.go')
-rw-r--r--profile.go25
1 files changed, 22 insertions, 3 deletions
diff --git a/profile.go b/profile.go
index ba317fe..ab43922 100644
--- a/profile.go
+++ b/profile.go
@@ -18,6 +18,7 @@ type ProfileTplData struct {
Surname string
Visibility string
Description string
+ NameImage string
}
func handleProfile(w http.ResponseWriter, r *http.Request) {
@@ -42,13 +43,27 @@ func handleProfile(w http.ResponseWriter, r *http.Request) {
data.Description = login.UserEntry.GetAttributeValue("description")
if r.Method == "POST" {
- r.ParseForm()
+ //5MB maximum size files
+ r.ParseMultipartForm(5 << 20)
data.DisplayName = strings.TrimSpace(strings.Join(r.Form["display_name"], ""))
data.GivenName = strings.TrimSpace(strings.Join(r.Form["given_name"], ""))
data.Surname = strings.TrimSpace(strings.Join(r.Form["surname"], ""))
data.Description = strings.Trim(strings.Join(r.Form["description"], ""), "")
- data.Visibility = strings.TrimSpace(strings.Join(r.Form["visibility"], ""))
+ visible := strings.TrimSpace(strings.Join(r.Form["visibility"], ""))
+ if visible != "" {
+ visible = "on"
+ }
+ data.Visibility = visible
+
+ ok, name, err := uploadImage(w, r, login)
+ if err != nil {
+ data.ErrorMessage = err.Error()
+ }
+
+ if ok {
+ data.NameImage = name
+ }
modify_request := ldap.NewModifyRequest(login.Info.DN, nil)
modify_request.Replace("displayname", []string{data.DisplayName})
@@ -56,13 +71,17 @@ func handleProfile(w http.ResponseWriter, r *http.Request) {
modify_request.Replace("sn", []string{data.Surname})
modify_request.Replace("description", []string{data.Description})
modify_request.Replace("visibility", []string{data.Visibility})
+ if ok {
+ modify_request.Replace("profilImage", []string{data.NameImage})
+ }
- err := login.conn.Modify(modify_request)
+ err = login.conn.Modify(modify_request)
if err != nil {
data.ErrorMessage = err.Error()
} else {
data.Success = true
}
+
}
templateProfile.Execute(w, data)