2020-02-09 17:03:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-07-23 10:53:26 +00:00
|
|
|
b64 "encoding/base64"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2020-02-09 17:03:10 +00:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
2023-07-23 10:53:26 +00:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2020-02-09 17:03:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func handleProfile(w http.ResponseWriter, r *http.Request) {
|
2022-12-01 22:05:59 +00:00
|
|
|
templateProfile := getTemplate("profile.html")
|
2020-02-09 17:03:10 +00:00
|
|
|
|
|
|
|
login := checkLogin(w, r)
|
|
|
|
if login == nil {
|
2023-07-24 13:57:01 +00:00
|
|
|
templatePasswd := getTemplate("passwd.html")
|
|
|
|
templatePasswd.Execute(w, PasswdTplData{
|
2023-07-25 19:35:22 +00:00
|
|
|
|
|
|
|
Common: NestedCommonTplData{
|
|
|
|
CanAdmin: false,
|
|
|
|
LoggedIn: false},
|
2023-07-24 13:57:01 +00:00
|
|
|
})
|
2020-02-09 17:03:10 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data := &ProfileTplData{
|
2023-07-25 19:35:22 +00:00
|
|
|
Login: NestedLoginTplData{
|
|
|
|
Status: login,
|
|
|
|
Login: login,
|
|
|
|
},
|
|
|
|
Common: NestedCommonTplData{
|
|
|
|
CanAdmin: login.Common.CanAdmin,
|
|
|
|
LoggedIn: true,
|
|
|
|
ErrorMessage: "",
|
|
|
|
Success: false,
|
|
|
|
},
|
2020-02-09 17:03:10 +00:00
|
|
|
}
|
|
|
|
|
2020-02-11 22:24:53 +00:00
|
|
|
data.Mail = login.UserEntry.GetAttributeValue("mail")
|
2023-07-17 08:19:01 +00:00
|
|
|
data.DisplayName = login.UserEntry.GetAttributeValue("displayName")
|
|
|
|
data.GivenName = login.UserEntry.GetAttributeValue("givenName")
|
2020-02-11 22:24:53 +00:00
|
|
|
data.Surname = login.UserEntry.GetAttributeValue("sn")
|
2023-07-22 05:36:00 +00:00
|
|
|
// data.Visibility = login.UserEntry.GetAttributeValue(FIELD_NAME_DIRECTORY_VISIBILITY)
|
2021-07-26 21:01:48 +00:00
|
|
|
data.Description = login.UserEntry.GetAttributeValue("description")
|
2023-07-17 08:19:01 +00:00
|
|
|
//data.ProfilePicture = login.UserEntry.GetAttributeValue(FIELD_NAME_PROFILE_PICTURE)
|
2020-02-11 22:24:53 +00:00
|
|
|
|
2020-02-09 17:03:10 +00:00
|
|
|
if r.Method == "POST" {
|
2021-07-29 22:04:17 +00:00
|
|
|
//5MB maximum size files
|
|
|
|
r.ParseMultipartForm(5 << 20)
|
2023-07-22 05:36:00 +00:00
|
|
|
user := User{
|
|
|
|
DN: login.Info.DN,
|
|
|
|
// CN: ,
|
|
|
|
GivenName: strings.TrimSpace(strings.Join(r.Form["given_name"], "")),
|
|
|
|
DisplayName: strings.TrimSpace(strings.Join(r.Form["display_name"], "")),
|
|
|
|
Mail: strings.TrimSpace(strings.Join(r.Form["mail"], "")),
|
|
|
|
SN: strings.TrimSpace(strings.Join(r.Form["surname"], "")),
|
|
|
|
//UID: ,
|
|
|
|
Description: strings.TrimSpace(strings.Join(r.Form["description"], "")),
|
|
|
|
// Password: ,
|
2021-07-29 22:04:17 +00:00
|
|
|
}
|
2023-07-22 07:52:34 +00:00
|
|
|
|
2023-07-22 08:01:05 +00:00
|
|
|
if user.DisplayName != "" {
|
2023-07-22 07:49:09 +00:00
|
|
|
err := modify(user, config, login.conn)
|
|
|
|
if err != nil {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.ErrorMessage = "handleProfile : " + err.Error()
|
2023-07-22 07:49:09 +00:00
|
|
|
} else {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.Success = true
|
2023-07-22 07:49:09 +00:00
|
|
|
}
|
2020-02-09 17:03:10 +00:00
|
|
|
}
|
2023-07-22 08:10:30 +00:00
|
|
|
findUser, err := get(user, config, login.conn)
|
|
|
|
if err != nil {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.ErrorMessage = "handleProfile : " + err.Error()
|
2023-07-22 08:10:30 +00:00
|
|
|
}
|
|
|
|
data.DisplayName = findUser.DisplayName
|
|
|
|
data.GivenName = findUser.GivenName
|
|
|
|
data.Surname = findUser.SN
|
|
|
|
data.Description = findUser.Description
|
|
|
|
data.Mail = findUser.Mail
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.LoggedIn = false
|
2021-07-29 22:04:17 +00:00
|
|
|
|
2023-07-22 05:36:00 +00:00
|
|
|
/*
|
|
|
|
visible := strings.TrimSpace(strings.Join(r.Form["visibility"], ""))
|
|
|
|
if visible != "" {
|
|
|
|
visible = "on"
|
|
|
|
} else {
|
|
|
|
visible = "off"
|
|
|
|
}
|
|
|
|
data.Visibility = visible
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
profilePicture, err := uploadProfilePicture(w, r, login)
|
|
|
|
if err != nil {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.ErrorMessage = err.Error()
|
2023-07-22 05:36:00 +00:00
|
|
|
}
|
|
|
|
if profilePicture != "" {
|
|
|
|
data.ProfilePicture = profilePicture
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
//modify_request.Replace(FIELD_NAME_DIRECTORY_VISIBILITY, []string{data.Visibility})
|
|
|
|
//modify_request.Replace(FIELD_NAME_DIRECTORY_VISIBILITY, []string{"on"})
|
|
|
|
//if data.ProfilePicture != "" {
|
|
|
|
// modify_request.Replace(FIELD_NAME_PROFILE_PICTURE, []string{data.ProfilePicture})
|
|
|
|
// }
|
|
|
|
|
|
|
|
// err := login.conn.Modify(modify_request)
|
|
|
|
// log.Printf(fmt.Sprintf("Profile:079: %v",modify_request))
|
|
|
|
// log.Printf(fmt.Sprintf("Profile:079: %v",err))
|
|
|
|
// log.Printf(fmt.Sprintf("Profile:079: %v",data))
|
|
|
|
// if err != nil {
|
2023-07-25 19:35:22 +00:00
|
|
|
// data.Common.ErrorMessage = err.Error()
|
2023-07-22 05:36:00 +00:00
|
|
|
// } else {
|
2023-07-25 19:35:22 +00:00
|
|
|
// data.Common.Success = true
|
2023-07-22 05:36:00 +00:00
|
|
|
// }
|
|
|
|
|
2020-02-09 17:03:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
templateProfile.Execute(w, data)
|
|
|
|
}
|
|
|
|
|
2023-07-23 10:53:26 +00:00
|
|
|
func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
|
|
|
|
templateFoundPasswordPage := getTemplate("passwd.html")
|
2023-07-24 13:38:01 +00:00
|
|
|
data := PasswdTplData{
|
2023-07-25 19:35:22 +00:00
|
|
|
Common: NestedCommonTplData{
|
|
|
|
CanAdmin: false,
|
|
|
|
LoggedIn: false},
|
2023-07-24 13:38:01 +00:00
|
|
|
}
|
2023-07-23 10:53:26 +00:00
|
|
|
code := mux.Vars(r)["code"]
|
|
|
|
// code = strings.TrimSpace(strings.Join([]string{code}, ""))
|
|
|
|
newCode, _ := b64.URLEncoding.DecodeString(code)
|
|
|
|
ldapConn, err := openNewUserLdap(config)
|
|
|
|
if err != nil {
|
2023-07-23 11:12:59 +00:00
|
|
|
log.Printf(fmt.Sprint("handleFoundPassword / openNewUserLdap / %v", err))
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.ErrorMessage = err.Error()
|
2023-07-23 10:53:26 +00:00
|
|
|
}
|
|
|
|
codeArray := strings.Split(string(newCode), ";")
|
|
|
|
user := User{
|
|
|
|
UID: codeArray[0],
|
|
|
|
Password: codeArray[1],
|
2023-07-23 11:12:59 +00:00
|
|
|
DN: "uid=" + codeArray[0] + ",ou=invitations,dc=resdigita,dc=org",
|
2023-07-23 10:53:26 +00:00
|
|
|
}
|
2023-07-23 11:39:05 +00:00
|
|
|
user.SeeAlso, err = passwordFound(user, config, ldapConn)
|
2023-07-23 10:53:26 +00:00
|
|
|
if err != nil {
|
2023-07-23 11:14:50 +00:00
|
|
|
log.Printf("handleFoundPassword / passwordFound %v", err)
|
|
|
|
log.Printf("handleFoundPassword / passwordFound %v", err)
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.ErrorMessage = err.Error()
|
2023-07-23 10:53:26 +00:00
|
|
|
}
|
2023-07-23 11:37:20 +00:00
|
|
|
if r.Method == "POST" {
|
|
|
|
r.ParseForm()
|
|
|
|
|
|
|
|
password := strings.Join(r.Form["password"], "")
|
|
|
|
password2 := strings.Join(r.Form["password2"], "")
|
|
|
|
|
|
|
|
if len(password) < 8 {
|
|
|
|
data.TooShortError = true
|
|
|
|
} else if password2 != password {
|
|
|
|
data.NoMatchError = true
|
|
|
|
} else {
|
|
|
|
err := passwd(User{
|
|
|
|
DN: user.SeeAlso,
|
|
|
|
Password: password,
|
|
|
|
}, config, ldapConn)
|
|
|
|
if err != nil {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.ErrorMessage = err.Error()
|
2023-07-23 11:37:20 +00:00
|
|
|
} else {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.Success = true
|
2023-07-23 11:37:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.CanAdmin = false
|
2023-07-23 10:53:26 +00:00
|
|
|
templateFoundPasswordPage.Execute(w, data)
|
|
|
|
}
|
|
|
|
|
2020-02-09 17:03:10 +00:00
|
|
|
func handlePasswd(w http.ResponseWriter, r *http.Request) {
|
2022-12-01 22:05:59 +00:00
|
|
|
templatePasswd := getTemplate("passwd.html")
|
2020-02-09 17:03:10 +00:00
|
|
|
data := &PasswdTplData{
|
2023-07-25 19:35:22 +00:00
|
|
|
Common: NestedCommonTplData{
|
|
|
|
CanAdmin: false,
|
|
|
|
LoggedIn: false,
|
|
|
|
ErrorMessage: "",
|
|
|
|
Success: false,
|
|
|
|
},
|
2020-02-09 17:03:10 +00:00
|
|
|
}
|
|
|
|
|
2023-07-24 13:57:01 +00:00
|
|
|
login := checkLogin(w, r)
|
|
|
|
if login == nil {
|
|
|
|
templatePasswd.Execute(w, data)
|
|
|
|
return
|
|
|
|
}
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Login.Status = login
|
2023-07-24 13:57:01 +00:00
|
|
|
|
2020-02-09 17:03:10 +00:00
|
|
|
if r.Method == "POST" {
|
|
|
|
r.ParseForm()
|
|
|
|
|
|
|
|
password := strings.Join(r.Form["password"], "")
|
|
|
|
password2 := strings.Join(r.Form["password2"], "")
|
|
|
|
|
2020-02-09 18:56:01 +00:00
|
|
|
if len(password) < 8 {
|
|
|
|
data.TooShortError = true
|
|
|
|
} else if password2 != password {
|
2020-02-09 17:03:10 +00:00
|
|
|
data.NoMatchError = true
|
|
|
|
} else {
|
2023-07-22 05:43:41 +00:00
|
|
|
err := passwd(User{
|
|
|
|
DN: login.Info.DN,
|
|
|
|
Password: password,
|
|
|
|
}, config, login.conn)
|
2023-07-22 05:36:00 +00:00
|
|
|
if err != nil {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.ErrorMessage = err.Error()
|
2023-07-22 05:36:00 +00:00
|
|
|
} else {
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.Success = true
|
2023-07-22 05:36:00 +00:00
|
|
|
}
|
2020-02-09 17:03:10 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-25 19:35:22 +00:00
|
|
|
data.Common.CanAdmin = false
|
2020-02-09 17:03:10 +00:00
|
|
|
templatePasswd.Execute(w, data)
|
|
|
|
}
|