Fixed Change Password Bug

This commit is contained in:
Chris Mann 2023-07-25 21:35:22 +02:00
parent 9258cb52af
commit ccb628df39
23 changed files with 181 additions and 504 deletions

185
admin.go
View file

@ -17,15 +17,13 @@ func checkAdminLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
return nil return nil
} }
if !login.CanAdmin { if !login.Common.CanAdmin {
http.Error(w, "Not authorized to perform administrative operations.", http.StatusUnauthorized) http.Error(w, "Not authorized to perform administrative operations.", http.StatusUnauthorized)
return nil return nil
} }
return login return login
} }
type EntryList []*ldap.Entry
func (d EntryList) Len() int { func (d EntryList) Len() int {
return len(d) return len(d)
} }
@ -38,15 +36,6 @@ func (d EntryList) Less(i, j int) bool {
return d[i].DN < d[j].DN return d[i].DN < d[j].DN
} }
type AdminUsersTplData struct {
Login *LoginStatus
UserNameAttr string
UserBaseDN string
Users EntryList
CanAdmin bool
LoggedIn bool
}
func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) { func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) {
templateAdminActivateUsers := getTemplate("admin_activate.html") templateAdminActivateUsers := getTemplate("admin_activate.html")
login := checkAdminLogin(w, r) login := checkAdminLogin(w, r)
@ -72,12 +61,16 @@ func handleAdminActivateUsers(w http.ResponseWriter, r *http.Request) {
} }
data := &AdminUsersTplData{ data := &AdminUsersTplData{
Login: login, Login: NestedLoginTplData{
Login: login,
},
UserNameAttr: config.UserNameAttr, UserNameAttr: config.UserNameAttr,
UserBaseDN: config.UserBaseDN, UserBaseDN: config.UserBaseDN,
Users: EntryList(sr.Entries), Users: EntryList(sr.Entries),
CanAdmin: login.CanAdmin, Common: NestedCommonTplData{
LoggedIn: true, CanAdmin: true,
LoggedIn: true,
},
} }
templateAdminActivateUsers.Execute(w, data) templateAdminActivateUsers.Execute(w, data)
@ -133,12 +126,13 @@ func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
} }
data := &AdminUsersTplData{ data := &AdminUsersTplData{
Login: login, Login: NestedLoginTplData{Login: login},
UserNameAttr: config.UserNameAttr, UserNameAttr: config.UserNameAttr,
UserBaseDN: config.UserBaseDN, UserBaseDN: config.UserBaseDN,
Users: EntryList(sr.Entries), Users: EntryList(sr.Entries),
CanAdmin: login.CanAdmin, Common: NestedCommonTplData{
LoggedIn: false, CanAdmin: login.Common.CanAdmin,
LoggedIn: false},
} }
sort.Sort(data.Users) sort.Sort(data.Users)
@ -154,15 +148,6 @@ func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
templateAdminUsers.Execute(w, data) templateAdminUsers.Execute(w, data)
} }
type AdminGroupsTplData struct {
Login *LoginStatus
GroupNameAttr string
GroupBaseDN string
Groups EntryList
CanAdmin bool
LoggedIn bool
}
func handleAdminGroups(w http.ResponseWriter, r *http.Request) { func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
templateAdminGroups := getTemplate("admin_groups.html") templateAdminGroups := getTemplate("admin_groups.html")
@ -185,27 +170,20 @@ func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
} }
data := &AdminGroupsTplData{ data := &AdminGroupsTplData{
Login: login, Login: NestedLoginTplData{
Login: login},
GroupNameAttr: config.GroupNameAttr, GroupNameAttr: config.GroupNameAttr,
GroupBaseDN: config.GroupBaseDN, GroupBaseDN: config.GroupBaseDN,
Groups: EntryList(sr.Entries), Groups: EntryList(sr.Entries),
CanAdmin: login.CanAdmin, Common: NestedCommonTplData{
LoggedIn: false, CanAdmin: login.Common.CanAdmin,
LoggedIn: false},
} }
sort.Sort(data.Groups) sort.Sort(data.Groups)
templateAdminGroups.Execute(w, data) templateAdminGroups.Execute(w, data)
} }
type AdminMailingTplData struct {
Login *LoginStatus
MailingNameAttr string
MailingBaseDN string
MailingLists EntryList
CanAdmin bool
LoggedIn bool
}
func handleAdminMailing(w http.ResponseWriter, r *http.Request) { func handleAdminMailing(w http.ResponseWriter, r *http.Request) {
templateAdminMailing := getTemplate("admin_mailing.html") templateAdminMailing := getTemplate("admin_mailing.html")
@ -228,32 +206,20 @@ func handleAdminMailing(w http.ResponseWriter, r *http.Request) {
} }
data := &AdminMailingTplData{ data := &AdminMailingTplData{
Login: login, Login: NestedLoginTplData{
Login: login},
MailingNameAttr: config.MailingNameAttr, MailingNameAttr: config.MailingNameAttr,
MailingBaseDN: config.MailingBaseDN, MailingBaseDN: config.MailingBaseDN,
MailingLists: EntryList(sr.Entries), MailingLists: EntryList(sr.Entries),
CanAdmin: login.CanAdmin, Common: NestedCommonTplData{
LoggedIn: false, CanAdmin: login.Common.CanAdmin,
LoggedIn: false},
} }
sort.Sort(data.MailingLists) sort.Sort(data.MailingLists)
templateAdminMailing.Execute(w, data) templateAdminMailing.Execute(w, data)
} }
type AdminMailingListTplData struct {
Login *LoginStatus
MailingNameAttr string
MailingBaseDN string
MailingList *ldap.Entry
Members EntryList
PossibleNewMembers EntryList
AllowGuest bool
Error string
Success bool
CanAdmin bool
LoggedIn bool
}
func handleAdminMailingList(w http.ResponseWriter, r *http.Request) { func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
templateAdminMailingList := getTemplate("admin_mailing_list.html") templateAdminMailingList := getTemplate("admin_mailing_list.html")
@ -424,7 +390,9 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
} }
data := &AdminMailingListTplData{ data := &AdminMailingListTplData{
Login: login, Login: NestedLoginTplData{
Login: login,
},
MailingNameAttr: config.MailingNameAttr, MailingNameAttr: config.MailingNameAttr,
MailingBaseDN: config.MailingBaseDN, MailingBaseDN: config.MailingBaseDN,
@ -432,11 +400,11 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
Members: members, Members: members,
PossibleNewMembers: possibleNewMembers, PossibleNewMembers: possibleNewMembers,
AllowGuest: config.MailingGuestsBaseDN != "", AllowGuest: config.MailingGuestsBaseDN != "",
Common: NestedCommonTplData{
Error: dError, CanAdmin: true,
Success: dSuccess, Error: dError,
CanAdmin: login.CanAdmin, Success: dSuccess,
LoggedIn: true, LoggedIn: true},
} }
sort.Sort(data.Members) sort.Sort(data.Members)
sort.Sort(data.PossibleNewMembers) sort.Sort(data.PossibleNewMembers)
@ -448,54 +416,6 @@ func handleAdminMailingList(w http.ResponseWriter, r *http.Request) {
// LDAP EXPLORER // LDAP EXPLORER
// =================================================== // ===================================================
type AdminLDAPTplData struct {
DN string
Path []PathItem
ChildrenOU []Child
ChildrenOther []Child
CanAddChild bool
Props map[string]*PropValues
CanDelete bool
HasMembers bool
Members []EntryName
PossibleNewMembers []EntryName
HasGroups bool
Groups []EntryName
PossibleNewGroups []EntryName
ListMemGro map[string]string
Error string
Success bool
CanAdmin bool
}
type EntryName struct {
DN string
Name string
}
type Child struct {
DN string
Identifier string
Name string
}
type PathItem struct {
DN string
Identifier string
Active bool
}
type PropValues struct {
Name string
Values []string
Editable bool
Deletable bool
}
func handleAdminLDAP(w http.ResponseWriter, r *http.Request) { func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
templateAdminLDAP := getTemplate("admin_ldap.html") templateAdminLDAP := getTemplate("admin_ldap.html")
@ -922,32 +842,15 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
Groups: groups, Groups: groups,
PossibleNewGroups: possibleNewGroups, PossibleNewGroups: possibleNewGroups,
Error: dError, Common: NestedCommonTplData{
Success: dSuccess, CanAdmin: true,
CanAdmin: true, LoggedIn: true,
Error: dError,
Success: dSuccess,
},
}) })
} }
type CreateData struct {
SuperDN string
Path []PathItem
Template string
IdType string
IdValue string
DisplayName string
GivenName string
Member string
Mail string
Description string
StructuralObjectClass string
ObjectClass string
SN string
Error string
CanAdmin bool
}
func handleAdminCreate(w http.ResponseWriter, r *http.Request) { func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
templateAdminCreate := getTemplate("admin_create.html") templateAdminCreate := getTemplate("admin_create.html")
@ -1044,11 +947,11 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
} }
if len(object_class) == 0 { if len(object_class) == 0 {
data.Error = "No object class specified" data.Common.Error = "No object class specified"
} else if match, err := regexp.MatchString("^[a-z]+$", data.IdType); err != nil || !match { } else if match, err := regexp.MatchString("^[a-z]+$", data.IdType); err != nil || !match {
data.Error = "Invalid identifier type" data.Common.Error = "Invalid identifier type"
} else if len(data.IdValue) == 0 { } else if len(data.IdValue) == 0 {
data.Error = "No identifier specified" data.Common.Error = "No identifier specified"
} else { } else {
newUser := User{ newUser := User{
DN: data.IdType + "=" + data.IdValue + "," + super_dn, DN: data.IdType + "=" + data.IdValue + "," + super_dn,
@ -1058,9 +961,9 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
// req.Attribute("objectclass", object_class) // req.Attribute("objectclass", object_class)
// req.Attribute("mail", []string{data.IdValue}) // req.Attribute("mail", []string{data.IdValue})
/* /*
if data.StructuralObjectClass != "" { if data.StructuralObjectClass != "" {
req.Attribute("structuralobjectclass", []string{data.StructuralObjectClass}) req.Attribute("structuralobjectclass", []string{data.StructuralObjectClass})
} }
*/ */
if data.Mail != "" { if data.Mail != "" {
newUser.Mail = data.Mail newUser.Mail = data.Mail
@ -1102,7 +1005,7 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
// // log.Printf(fmt.Sprintf("899: %v",req)) // // log.Printf(fmt.Sprintf("899: %v",req))
// // log.Printf(fmt.Sprintf("899: %v",data)) // // log.Printf(fmt.Sprintf("899: %v",data))
// if err != nil { // if err != nil {
// data.Error = err.Error() // data.Common.Error = err.Error()
// } else { // } else {
if template == "ml" { if template == "ml" {
http.Redirect(w, r, "/admin/mailing/"+data.IdValue, http.StatusFound) http.Redirect(w, r, "/admin/mailing/"+data.IdValue, http.StatusFound)
@ -1112,7 +1015,7 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
// } // }
} }
} }
data.CanAdmin = true data.Common.CanAdmin = true
templateAdminCreate.Execute(w, data) templateAdminCreate.Execute(w, data)
} }

View file

@ -11,51 +11,6 @@ import (
"os" "os"
) )
type ConfigFile struct {
HttpBindAddr string `json:"http_bind_addr"`
LdapServerAddr string `json:"ldap_server_addr"`
LdapTLS bool `json:"ldap_tls"`
BaseDN string `json:"base_dn"`
UserBaseDN string `json:"user_base_dn"`
UserNameAttr string `json:"user_name_attr"`
GroupBaseDN string `json:"group_base_dn"`
GroupNameAttr string `json:"group_name_attr"`
MailingBaseDN string `json:"mailing_list_base_dn"`
MailingNameAttr string `json:"mailing_list_name_attr"`
MailingGuestsBaseDN string `json:"mailing_list_guest_user_base_dn"`
InvitationBaseDN string `json:"invitation_base_dn"`
InvitationNameAttr string `json:"invitation_name_attr"`
InvitedMailFormat string `json:"invited_mail_format"`
InvitedAutoGroups []string `json:"invited_auto_groups"`
WebAddress string `json:"web_address"`
MailFrom string `json:"mail_from"`
SMTPServer string `json:"smtp_server"`
SMTPUsername string `json:"smtp_username"`
SMTPPassword string `json:"smtp_password"`
AdminAccount string `json:"admin_account"`
GroupCanInvite string `json:"group_can_invite"`
GroupCanAdmin string `json:"group_can_admin"`
S3AdminEndpoint string `json:"s3_admin_endpoint"`
S3AdminToken string `json:"s3_admin_token"`
S3Endpoint string `json:"s3_endpoint"`
S3AccessKey string `json:"s3_access_key"`
S3SecretKey string `json:"s3_secret_key"`
S3Region string `json:"s3_region"`
S3Bucket string `json:"s3_bucket"`
Org string `json:"org"`
DomainName string `json:"domain_name"`
NewUserDN string `json:"new_user_dn"`
NewUserPassword string `json:"new_user_password"`
}
var configFlag = flag.String("config", "./config.json", "Configuration file path") var configFlag = flag.String("config", "./config.json", "Configuration file path")
var config *ConfigFile var config *ConfigFile

View file

@ -23,19 +23,6 @@ func handleDirectory(w http.ResponseWriter, r *http.Request) {
templateDirectory.Execute(w, nil) templateDirectory.Execute(w, nil)
} }
type SearchResult struct {
DN string
Id string
DisplayName string
Email string
Description string
ProfilePicture string
}
type SearchResults struct {
Results []SearchResult
}
func handleDirectorySearch(w http.ResponseWriter, r *http.Request) { func handleDirectorySearch(w http.ResponseWriter, r *http.Request) {
templateDirectoryResults := template.Must(template.ParseFiles(templatePath + "/directory_results.html")) templateDirectoryResults := template.Must(template.ParseFiles(templatePath + "/directory_results.html"))

22
home.go
View file

@ -6,14 +6,6 @@ package main
import "net/http" import "net/http"
type HomePageData struct {
Login *LoginStatus
BaseDN string
Org string
CanAdmin bool
LoggedIn bool
}
func handleHome(w http.ResponseWriter, r *http.Request) { func handleHome(w http.ResponseWriter, r *http.Request) {
templateHome := getTemplate("home.html") templateHome := getTemplate("home.html")
@ -28,15 +20,17 @@ func handleHome(w http.ResponseWriter, r *http.Request) {
can_admin := false can_admin := false
if login != nil { if login != nil {
can_admin = login.CanAdmin can_admin = login.Common.CanAdmin
} }
data := HomePageData{ data := HomePageData{
Login: login, Login: NestedLoginTplData{
BaseDN: config.BaseDN, Login: login},
Org: config.Org, BaseDN: config.BaseDN,
CanAdmin: can_admin, Org: config.Org,
LoggedIn: true, Common: NestedCommonTplData{
CanAdmin: can_admin,
LoggedIn: true},
} }
templateHome.Execute(w, data) templateHome.Execute(w, data)

122
invite.go
View file

@ -38,32 +38,12 @@ func checkInviterLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
// New account creation directly from interface // New account creation directly from interface
type PasswordFoundData struct {
ErrorMessage string
Success bool
Username string
Mail string
OtherMailbox string
CanAdmin bool
LoggedIn bool
}
type PasswordLostData struct {
ErrorMessage string
Success bool
Username string
Mail string
OtherMailbox string
CanAdmin bool
LoggedIn bool
}
func openNewUserLdap(config *ConfigFile) (*ldap.Conn, error) { func openNewUserLdap(config *ConfigFile) (*ldap.Conn, error) {
l, err := openLdap(config) l, err := openLdap(config)
if err != nil { if err != nil {
log.Printf(fmt.Sprintf("openNewUserLdap 1 : %v %v", err, l)) log.Printf(fmt.Sprintf("openNewUserLdap 1 : %v %v", err, l))
log.Printf(fmt.Sprintf("openNewUserLdap 1 : %v", config)) log.Printf(fmt.Sprintf("openNewUserLdap 1 : %v", config))
// data.ErrorMessage = err.Error() // data.Common.ErrorMessage = err.Error()
} }
err = l.Bind(config.NewUserDN, config.NewUserPassword) err = l.Bind(config.NewUserDN, config.NewUserPassword)
if err != nil { if err != nil {
@ -71,7 +51,7 @@ func openNewUserLdap(config *ConfigFile) (*ldap.Conn, error) {
log.Printf(fmt.Sprintf("openNewUserLdap 2 : %v", config.NewUserDN)) log.Printf(fmt.Sprintf("openNewUserLdap 2 : %v", config.NewUserDN))
log.Printf(fmt.Sprintf("openNewUserLdap 2 : %v", config.NewUserPassword)) log.Printf(fmt.Sprintf("openNewUserLdap 2 : %v", config.NewUserPassword))
log.Printf(fmt.Sprintf("openNewUserLdap 2 : %v", config)) log.Printf(fmt.Sprintf("openNewUserLdap 2 : %v", config))
// data.ErrorMessage = err.Error() // data.Common.ErrorMessage = err.Error()
} }
return l, err return l, err
} }
@ -83,8 +63,9 @@ func handleLostPassword(w http.ResponseWriter, r *http.Request) {
} }
data := PasswordLostData{ data := PasswordLostData{
CanAdmin: false, Common: NestedCommonTplData{
LoggedIn: false, CanAdmin: false,
LoggedIn: false},
} }
if r.Method == "POST" { if r.Method == "POST" {
@ -101,23 +82,23 @@ func handleLostPassword(w http.ResponseWriter, r *http.Request) {
ldapConn, err := openNewUserLdap(config) ldapConn, err := openNewUserLdap(config)
if err != nil { if err != nil {
log.Printf(fmt.Sprintf("handleLostPassword 99 : %v %v", err, ldapConn)) log.Printf(fmt.Sprintf("handleLostPassword 99 : %v %v", err, ldapConn))
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} }
err = passwordLost(user, config, ldapConn) err = passwordLost(user, config, ldapConn)
if err != nil { if err != nil {
log.Printf(fmt.Sprintf("handleLostPassword 104 : %v %v", err, ldapConn)) log.Printf(fmt.Sprintf("handleLostPassword 104 : %v %v", err, ldapConn))
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} else { } else {
err = ldapConn.Bind(config.NewUserDN, config.NewUserPassword) err = ldapConn.Bind(config.NewUserDN, config.NewUserPassword)
if err != nil { if err != nil {
log.Printf(fmt.Sprintf("handleLostPassword 109 : %v %v", err, ldapConn)) log.Printf(fmt.Sprintf("handleLostPassword 109 : %v %v", err, ldapConn))
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} else { } else {
data.Success = true data.Common.Success = true
} }
} }
} }
data.CanAdmin = false data.Common.CanAdmin = false
templateLostPasswordPage.Execute(w, data) templateLostPasswordPage.Execute(w, data)
} }
@ -205,26 +186,6 @@ func handleInvitationCode(w http.ResponseWriter, r *http.Request) {
// Common functions for new account // Common functions for new account
type NewAccountData struct {
Username string
DisplayName string
GivenName string
Surname string
Mail string
SuggestPW string
OtherEmail string
ErrorUsernameTaken bool
ErrorInvalidUsername bool
ErrorPasswordTooShort bool
ErrorPasswordMismatch bool
ErrorMessage string
WarningMessage string
Success bool
CanAdmin bool
LoggedIn bool
}
func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invitedBy string) bool { func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invitedBy string) bool {
templateInviteNewAccount := getTemplate("invite_new_account.html") templateInviteNewAccount := getTemplate("invite_new_account.html")
@ -249,15 +210,15 @@ func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invi
password2 := strings.Join(r.Form["password2"], "") password2 := strings.Join(r.Form["password2"], "")
if password1 != password2 { if password1 != password2 {
data.Success = false data.Common.Success = false
data.ErrorPasswordMismatch = true data.ErrorPasswordMismatch = true
} else { } else {
newUser.Password = password2 newUser.Password = password2
l.Bind(config.NewUserDN, config.NewUserPassword) l.Bind(config.NewUserDN, config.NewUserPassword)
err := add(newUser, config, l) err := add(newUser, config, l)
if err != nil { if err != nil {
data.Success = false data.Common.Success = false
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} }
http.Redirect(w, r, "/admin/activate", http.StatusFound) http.Redirect(w, r, "/admin/activate", http.StatusFound)
} }
@ -267,11 +228,11 @@ func handleNewAccount(w http.ResponseWriter, r *http.Request, l *ldap.Conn, invi
} else { } else {
data.SuggestPW = fmt.Sprintf("%s", suggestPassword()) data.SuggestPW = fmt.Sprintf("%s", suggestPassword())
} }
data.CanAdmin = false data.Common.CanAdmin = false
data.LoggedIn = false data.Common.LoggedIn = false
templateInviteNewAccount.Execute(w, data) templateInviteNewAccount.Execute(w, data)
return data.Success return data.Common.Success
} }
func tryCreateAccount(l *ldap.Conn, data *NewAccountData, pass1 string, pass2 string, invitedBy string) { func tryCreateAccount(l *ldap.Conn, data *NewAccountData, pass1 string, pass2 string, invitedBy string) {
@ -294,7 +255,7 @@ func tryCreateAccount(l *ldap.Conn, data *NewAccountData, pass1 string, pass2 st
sr, err := l.Search(searchRq) sr, err := l.Search(searchRq)
if err != nil { if err != nil {
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
checkFailed = true checkFailed = true
} }
@ -324,7 +285,7 @@ func tryCreateAccount(l *ldap.Conn, data *NewAccountData, pass1 string, pass2 st
req.Attribute("structuralobjectclass", []string{"inetOrgPerson"}) req.Attribute("structuralobjectclass", []string{"inetOrgPerson"})
pw, err := SSHAEncode(pass1) pw, err := SSHAEncode(pass1)
if err != nil { if err != nil {
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
return return
} }
req.Attribute("userpassword", []string{pw}) req.Attribute("userpassword", []string{pw})
@ -345,7 +306,7 @@ func tryCreateAccount(l *ldap.Conn, data *NewAccountData, pass1 string, pass2 st
err = l.Add(req) err = l.Add(req)
if err != nil { if err != nil {
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
return return
} }
@ -354,34 +315,15 @@ func tryCreateAccount(l *ldap.Conn, data *NewAccountData, pass1 string, pass2 st
req.Add("member", []string{userDn}) req.Add("member", []string{userDn})
err = l.Modify(req) err = l.Modify(req)
if err != nil { if err != nil {
data.WarningMessage += fmt.Sprintf("Cannot add to %s: %s\n", group, err.Error()) data.Common.WarningMessage += fmt.Sprintf("Cannot add to %s: %s\n", group, err.Error())
} }
} }
data.Success = true data.Common.Success = true
} }
// ---- Code generation ---- // ---- Code generation ----
type SendCodeData struct {
ErrorMessage string
ErrorInvalidEmail bool
Success bool
CodeDisplay string
CodeSentTo string
WebBaseAddress string
CanAdmin bool
}
type CodeMailFields struct {
From string
To string
Code string
InviteFrom string
WebBaseAddress string
CanAdmin bool
}
func handleInviteSendCode(w http.ResponseWriter, r *http.Request) { func handleInviteSendCode(w http.ResponseWriter, r *http.Request) {
templateInviteSendCode := getTemplate("invite_send_code.html") templateInviteSendCode := getTemplate("invite_send_code.html")
@ -407,10 +349,10 @@ func handleInviteSendCode(w http.ResponseWriter, r *http.Request) {
// modify_request.Add("carLicense", []string{fmt.Sprintf("%s,%s,%s",code, code_id, code_pw)}) // modify_request.Add("carLicense", []string{fmt.Sprintf("%s,%s,%s",code, code_id, code_pw)})
// err := login.conn.Modify(modify_request) // err := login.conn.Modify(modify_request)
// if err != nil { // if err != nil {
// data.ErrorMessage = err.Error() // data.Common.ErrorMessage = err.Error()
// // return // // return
// } else { // } else {
// data.Success = true // data.Common.Success = true
// data.CodeDisplay = code // data.CodeDisplay = code
// } // }
log.Printf(fmt.Sprintf("279: %v %v %v", code, code_id, code_pw)) log.Printf(fmt.Sprintf("279: %v %v %v", code, code_id, code_pw))
@ -423,13 +365,13 @@ func handleInviteSendCode(w http.ResponseWriter, r *http.Request) {
log.Printf(fmt.Sprintf("286: %v", addReq)) log.Printf(fmt.Sprintf("286: %v", addReq))
err := login.conn.Add(addReq) err := login.conn.Add(addReq)
if err != nil { if err != nil {
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
// return // return
} else { } else {
data.Success = true data.Common.Success = true
data.CodeDisplay = code data.CodeDisplay = code
} }
data.CanAdmin = login.CanAdmin data.Common.CanAdmin = login.Common.CanAdmin
templateInviteSendCode.Execute(w, data) templateInviteSendCode.Execute(w, data)
@ -513,7 +455,7 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod
// // log.Printf(fmt.Sprintf("899: %v",req)) // // log.Printf(fmt.Sprintf("899: %v",req))
// // log.Printf(fmt.Sprintf("899: %v",data)) // // log.Printf(fmt.Sprintf("899: %v",data))
// if err != nil { // if err != nil {
// data.Error = err.Error() // data.Common.Error = err.Error()
// } else { // } else {
// if template == "ml" { // if template == "ml" {
// http.Redirect(w, r, "/admin/mailing/"+data.IdValue, http.StatusFound) // http.Redirect(w, r, "/admin/mailing/"+data.IdValue, http.StatusFound)
@ -526,7 +468,7 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod
// req := ldap.NewAddRequest(inviteDn, nil) // req := ldap.NewAddRequest(inviteDn, nil)
// pw, err := SSHAEncode(code_pw) // pw, err := SSHAEncode(code_pw)
// if err != nil { // if err != nil {
// data.ErrorMessage = err.Error() // data.Common.ErrorMessage = err.Error()
// return // return
// } // }
// req.Attribute("employeeNumber", []string{pw}) // req.Attribute("employeeNumber", []string{pw})
@ -535,13 +477,13 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod
// err = login.conn.Add(req) // err = login.conn.Add(req)
// if err != nil { // if err != nil {
// log.Printf(fmt.Sprintf("286: %v", req)) // log.Printf(fmt.Sprintf("286: %v", req))
// data.ErrorMessage = err.Error() // data.Common.ErrorMessage = err.Error()
// return // return
// } // }
// If we want to display it, do so // If we want to display it, do so
if choice == "display" { if choice == "display" {
data.Success = true data.Common.Success = true
data.CodeDisplay = code data.CodeDisplay = code
return return
} }
@ -569,12 +511,12 @@ func trySendCode(login *LoginStatus, choice string, sendto string, data *SendCod
// } // }
// err = smtp.SendMail(config.SMTPServer, auth, config.MailFrom, []string{sendto}, buf) // err = smtp.SendMail(config.SMTPServer, auth, config.MailFrom, []string{sendto}, buf)
// if err != nil { // if err != nil {
// data.ErrorMessage = err.Error() // data.Common.ErrorMessage = err.Error()
// return // return
// } // }
// log.Printf("Mail sent.") // log.Printf("Mail sent.")
data.Success = true data.Common.Success = true
data.CodeSentTo = sendto data.CodeSentTo = sendto
} }

View file

@ -13,20 +13,6 @@ import (
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
) )
type LoginInfo struct {
Username string
DN string
Password string
}
type LoginStatus struct {
Info *LoginInfo
conn *ldap.Conn
UserEntry *ldap.Entry
CanAdmin bool
CanInvite bool
}
func (login *LoginStatus) WelcomeName() string { func (login *LoginStatus) WelcomeName() string {
ret := login.UserEntry.GetAttributeValue("givenName") ret := login.UserEntry.GetAttributeValue("givenName")
if ret == "" { if ret == "" {
@ -49,15 +35,6 @@ func handleLogout(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", http.StatusFound) http.Redirect(w, r, "/", http.StatusFound)
} }
type LoginFormData struct {
Username string
WrongUser bool
WrongPass bool
ErrorMessage string
LoggedIn bool
CanAdmin bool
}
func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo { func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
templateLogin := getTemplate("login.html") templateLogin := getTemplate("login.html")
@ -80,8 +57,11 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
if err != nil { if err != nil {
data := &LoginFormData{ data := &LoginFormData{
Username: username, Username: username,
LoggedIn: false, Common: NestedCommonTplData{
CanAdmin: false, CanAdmin: false,
CanInvite: true,
LoggedIn: false,
},
} }
if ldap.IsErrorWithCode(err, ldap.LDAPResultInvalidCredentials) { if ldap.IsErrorWithCode(err, ldap.LDAPResultInvalidCredentials) {
data.WrongPass = true data.WrongPass = true
@ -91,7 +71,7 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
log.Printf("%v", err) log.Printf("%v", err)
log.Printf("%v", user_dn) log.Printf("%v", user_dn)
log.Printf("%v", username) log.Printf("%v", username)
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} }
templateLogin.Execute(w, data) templateLogin.Execute(w, data)
} }
@ -99,7 +79,11 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
return loginInfo return loginInfo
} else if r.Method == "GET" { } else if r.Method == "GET" {
templateLogin.Execute(w, LoginFormData{CanAdmin: false}) templateLogin.Execute(w, LoginFormData{
Common: NestedCommonTplData{
CanAdmin: false,
CanInvite: true,
LoggedIn: false}})
return nil return nil
} else { } else {
http.Error(w, "Unsupported method", http.StatusBadRequest) http.Error(w, "Unsupported method", http.StatusBadRequest)

58
main.go
View file

@ -12,35 +12,21 @@ import (
// "encoding/json" // "encoding/json"
"flag" "flag"
// "fmt" // "fmt"
"html/template"
// "io/ioutil" // "io/ioutil"
"log" "log"
"net/http"
// "os" // "os"
"strings" // "strings"
"github.com/gorilla/mux"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
) )
const SESSION_NAME = "guichet_session" const SESSION_NAME = "guichet_session"
var staticPath = "./static"
var templatePath = "./templates"
var store sessions.Store = nil var store sessions.Store = nil
func getTemplate(name string) *template.Template {
return template.Must(template.New("layout.html").Funcs(template.FuncMap{
"contains": strings.Contains,
}).ParseFiles(
templatePath+"/layout.html",
templatePath+"/"+name,
))
}
func main() { func main() {
flag.Parse() flag.Parse()
config_file := readConfig() config_file := readConfig()
@ -52,45 +38,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
store = sessions.NewCookieStore(session_key) store = sessions.NewCookieStore(session_key)
_, err = makeGVRouter()
r := mux.NewRouter()
r.HandleFunc("/", handleHome)
r.HandleFunc("/logout", handleLogout)
r.HandleFunc("/profile", handleProfile)
r.HandleFunc("/passwd", handlePasswd)
r.HandleFunc("/picture/{name}", handleDownloadPicture)
r.HandleFunc("/admin/activate", handleAdminActivateUsers)
r.HandleFunc("/admin/unactivate/{cn}", handleAdminUnactivateUser)
r.HandleFunc("/admin/activate/{cn}", handleAdminActivateUser)
r.HandleFunc("/directory/search", handleDirectorySearch)
r.HandleFunc("/directory", handleDirectory)
r.HandleFunc("/garage/key", handleGarageKey)
r.HandleFunc("/garage/website", handleGarageWebsiteList)
r.HandleFunc("/garage/website/new", handleGarageWebsiteNew)
r.HandleFunc("/garage/website/b/{bucket}", handleGarageWebsiteInspect)
r.HandleFunc("/invite/new_account", handleInviteNewAccount)
r.HandleFunc("/invite/send_code", handleInviteSendCode)
r.HandleFunc("/gpassword/{code}", handleFoundPassword)
r.HandleFunc("/gpas", handleLostPassword)
r.HandleFunc("/invitation/{code}", handleInvitationCode)
r.HandleFunc("/admin/users", handleAdminUsers)
r.HandleFunc("/admin/groups", handleAdminGroups)
r.HandleFunc("/admin/mailing", handleAdminMailing)
r.HandleFunc("/admin/mailing/{id}", handleAdminMailingList)
r.HandleFunc("/admin/ldap/{dn}", handleAdminLDAP)
r.HandleFunc("/admin/create/{template}/{super_dn}", handleAdminCreate)
staticfiles := http.FileServer(http.Dir(staticPath))
r.Handle("/static/{file:.*}", http.StripPrefix("/static/", staticfiles))
// log.Printf("Starting HTTP server on %s", config.HttpBindAddr)
err = http.ListenAndServe(config.HttpBindAddr, logRequest(r))
if err != nil { if err != nil {
log.Fatal("Cannot start http server: ", err) log.Fatal("Cannot start http server: ", err)
} }

View file

@ -11,26 +11,6 @@ import (
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
) )
/*
Represents a user
*/
type User struct {
DN string
CN string
GivenName string
DisplayName string
Mail string
SN string
UID string
Description string
Password string
OtherMailbox string
CanAdmin bool
CanInvite bool
UserEntry *ldap.Entry
SeeAlso string
}
func get(user User, config *ConfigFile, ldapConn *ldap.Conn) (*User, error) { func get(user User, config *ConfigFile, ldapConn *ldap.Conn) (*User, error) {
searchReq := ldap.NewSearchRequest( searchReq := ldap.NewSearchRequest(
user.DN, user.DN,

View file

@ -10,33 +10,6 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
type ProfileTplData struct {
Status *LoginStatus
ErrorMessage string
Success bool
Mail string
DisplayName string
GivenName string
Surname string
Description string
Login *LoginStatus
CanAdmin bool
LoggedIn bool
}
//ProfilePicture string
//Visibility string
type PasswdTplData struct {
Status *LoginStatus
ErrorMessage string
TooShortError bool
NoMatchError bool
Success bool
CanAdmin bool
LoggedIn bool
}
func handleProfile(w http.ResponseWriter, r *http.Request) { func handleProfile(w http.ResponseWriter, r *http.Request) {
templateProfile := getTemplate("profile.html") templateProfile := getTemplate("profile.html")
@ -44,19 +17,25 @@ func handleProfile(w http.ResponseWriter, r *http.Request) {
if login == nil { if login == nil {
templatePasswd := getTemplate("passwd.html") templatePasswd := getTemplate("passwd.html")
templatePasswd.Execute(w, PasswdTplData{ templatePasswd.Execute(w, PasswdTplData{
LoggedIn: false,
CanAdmin: false, Common: NestedCommonTplData{
CanAdmin: false,
LoggedIn: false},
}) })
return return
} }
data := &ProfileTplData{ data := &ProfileTplData{
Status: login, Login: NestedLoginTplData{
Login: login, Status: login,
ErrorMessage: "", Login: login,
Success: false, },
CanAdmin: login.CanAdmin, Common: NestedCommonTplData{
LoggedIn: true, CanAdmin: login.Common.CanAdmin,
LoggedIn: true,
ErrorMessage: "",
Success: false,
},
} }
data.Mail = login.UserEntry.GetAttributeValue("mail") data.Mail = login.UserEntry.GetAttributeValue("mail")
@ -85,21 +64,21 @@ func handleProfile(w http.ResponseWriter, r *http.Request) {
if user.DisplayName != "" { if user.DisplayName != "" {
err := modify(user, config, login.conn) err := modify(user, config, login.conn)
if err != nil { if err != nil {
data.ErrorMessage = "handleProfile : " + err.Error() data.Common.ErrorMessage = "handleProfile : " + err.Error()
} else { } else {
data.Success = true data.Common.Success = true
} }
} }
findUser, err := get(user, config, login.conn) findUser, err := get(user, config, login.conn)
if err != nil { if err != nil {
data.ErrorMessage = "handleProfile : " + err.Error() data.Common.ErrorMessage = "handleProfile : " + err.Error()
} }
data.DisplayName = findUser.DisplayName data.DisplayName = findUser.DisplayName
data.GivenName = findUser.GivenName data.GivenName = findUser.GivenName
data.Surname = findUser.SN data.Surname = findUser.SN
data.Description = findUser.Description data.Description = findUser.Description
data.Mail = findUser.Mail data.Mail = findUser.Mail
data.LoggedIn = false data.Common.LoggedIn = false
/* /*
visible := strings.TrimSpace(strings.Join(r.Form["visibility"], "")) visible := strings.TrimSpace(strings.Join(r.Form["visibility"], ""))
@ -113,7 +92,7 @@ func handleProfile(w http.ResponseWriter, r *http.Request) {
/* /*
profilePicture, err := uploadProfilePicture(w, r, login) profilePicture, err := uploadProfilePicture(w, r, login)
if err != nil { if err != nil {
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} }
if profilePicture != "" { if profilePicture != "" {
data.ProfilePicture = profilePicture data.ProfilePicture = profilePicture
@ -131,9 +110,9 @@ func handleProfile(w http.ResponseWriter, r *http.Request) {
// log.Printf(fmt.Sprintf("Profile:079: %v",err)) // log.Printf(fmt.Sprintf("Profile:079: %v",err))
// log.Printf(fmt.Sprintf("Profile:079: %v",data)) // log.Printf(fmt.Sprintf("Profile:079: %v",data))
// if err != nil { // if err != nil {
// data.ErrorMessage = err.Error() // data.Common.ErrorMessage = err.Error()
// } else { // } else {
// data.Success = true // data.Common.Success = true
// } // }
} }
@ -144,8 +123,9 @@ func handleProfile(w http.ResponseWriter, r *http.Request) {
func handleFoundPassword(w http.ResponseWriter, r *http.Request) { func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
templateFoundPasswordPage := getTemplate("passwd.html") templateFoundPasswordPage := getTemplate("passwd.html")
data := PasswdTplData{ data := PasswdTplData{
CanAdmin: false, Common: NestedCommonTplData{
LoggedIn: false, CanAdmin: false,
LoggedIn: false},
} }
code := mux.Vars(r)["code"] code := mux.Vars(r)["code"]
// code = strings.TrimSpace(strings.Join([]string{code}, "")) // code = strings.TrimSpace(strings.Join([]string{code}, ""))
@ -153,7 +133,7 @@ func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
ldapConn, err := openNewUserLdap(config) ldapConn, err := openNewUserLdap(config)
if err != nil { if err != nil {
log.Printf(fmt.Sprint("handleFoundPassword / openNewUserLdap / %v", err)) log.Printf(fmt.Sprint("handleFoundPassword / openNewUserLdap / %v", err))
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} }
codeArray := strings.Split(string(newCode), ";") codeArray := strings.Split(string(newCode), ";")
user := User{ user := User{
@ -165,7 +145,7 @@ func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
log.Printf("handleFoundPassword / passwordFound %v", err) log.Printf("handleFoundPassword / passwordFound %v", err)
log.Printf("handleFoundPassword / passwordFound %v", err) log.Printf("handleFoundPassword / passwordFound %v", err)
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} }
if r.Method == "POST" { if r.Method == "POST" {
r.ParseForm() r.ParseForm()
@ -183,23 +163,25 @@ func handleFoundPassword(w http.ResponseWriter, r *http.Request) {
Password: password, Password: password,
}, config, ldapConn) }, config, ldapConn)
if err != nil { if err != nil {
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} else { } else {
data.Success = true data.Common.Success = true
} }
} }
} }
data.CanAdmin = false data.Common.CanAdmin = false
templateFoundPasswordPage.Execute(w, data) templateFoundPasswordPage.Execute(w, data)
} }
func handlePasswd(w http.ResponseWriter, r *http.Request) { func handlePasswd(w http.ResponseWriter, r *http.Request) {
templatePasswd := getTemplate("passwd.html") templatePasswd := getTemplate("passwd.html")
data := &PasswdTplData{ data := &PasswdTplData{
ErrorMessage: "", Common: NestedCommonTplData{
Success: false, CanAdmin: false,
CanAdmin: false, LoggedIn: false,
LoggedIn: false, ErrorMessage: "",
Success: false,
},
} }
login := checkLogin(w, r) login := checkLogin(w, r)
@ -207,7 +189,7 @@ func handlePasswd(w http.ResponseWriter, r *http.Request) {
templatePasswd.Execute(w, data) templatePasswd.Execute(w, data)
return return
} }
data.Status = login data.Login.Status = login
if r.Method == "POST" { if r.Method == "POST" {
r.ParseForm() r.ParseForm()
@ -225,12 +207,12 @@ func handlePasswd(w http.ResponseWriter, r *http.Request) {
Password: password, Password: password,
}, config, login.conn) }, config, login.conn)
if err != nil { if err != nil {
data.ErrorMessage = err.Error() data.Common.ErrorMessage = err.Error()
} else { } else {
data.Success = true data.Common.Success = true
} }
} }
} }
data.CanAdmin = false data.Common.CanAdmin = false
templatePasswd.Execute(w, data) templatePasswd.Execute(w, data)
} }

View file

@ -60,8 +60,10 @@ func checkLogin(w http.ResponseWriter, r *http.Request) *LoginStatus {
Info: login_info, Info: login_info,
conn: l, conn: l,
UserEntry: userEntry, UserEntry: userEntry,
CanAdmin: ldapUser.CanAdmin, Common: NestedCommonTplData{
CanInvite: ldapUser.CanInvite, CanAdmin: ldapUser.CanAdmin,
CanInvite: ldapUser.CanInvite,
},
} }
return loginStatus return loginStatus
} else { } else {

View file

@ -20,9 +20,9 @@
</nav> </nav>
</div> </div>
{{if .Error}} {{if .Common.Error}}
<div class="alert alert-danger mt-4">Impossible de créer l'objet. <div class="alert alert-danger mt-4">Impossible de créer l'objet.
<div style="font-size: 0.8em">{{ .Error }}</div> <div style="font-size: 0.8em">{{ .Common.Error }}</div>
</div> </div>
{{end}} {{end}}

View file

@ -59,10 +59,10 @@
<hr class="mt-4" /> <hr class="mt-4" />
{{end}} {{end}}
{{if .Success}} {{if .Common.Success}}
<div class="alert alert-success mt-2">Modification enregistrée.</div> <div class="alert alert-success mt-2">Modification enregistrée.</div>
{{end}} {{end}}
{{if .Error}} {{if .Common.Error}}
<div class="alert alert-danger mt-2"> <div class="alert alert-danger mt-2">
Impossible d'effectuer la modification. Impossible d'effectuer la modification.
<div style="font-size: 0.8em">{{.Error}}</div> <div style="font-size: 0.8em">{{.Error}}</div>

View file

@ -10,10 +10,10 @@
<a class="ml-auto btn btn-dark" href="/admin/mailing">Liste des ML</a> <a class="ml-auto btn btn-dark" href="/admin/mailing">Liste des ML</a>
</div> </div>
{{if .Success}} {{if .Common.Success}}
<div class="alert alert-success mt-2">Modification enregistrée.</div> <div class="alert alert-success mt-2">Modification enregistrée.</div>
{{end}} {{end}}
{{if .Error}} {{if .Common.Error}}
<div class="alert alert-danger mt-2"> <div class="alert alert-danger mt-2">
Impossible d'effectuer la modification. Impossible d'effectuer la modification.
<div style="font-size: 0.8em">{{.Error}}</div> <div style="font-size: 0.8em">{{.Error}}</div>

View file

@ -179,7 +179,7 @@ hugo deploy
<tbody> <tbody>
<tr> <tr>
<th scope="row">Nom d'utilisateur-ice</th> <th scope="row">Nom d'utilisateur-ice</th>
<td>{{ .Status.Info.Username }}</td> <td>{{ .Login.Status.Info.Username }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Mot de passe</th> <th scope="row">Mot de passe</th>
@ -210,7 +210,7 @@ hugo deploy
<div class="card-body"> <div class="card-body">
<p>Un exemple avec SCP :</p> <p>Un exemple avec SCP :</p>
<pre> <pre>
scp -oHostKeyAlgorithms=+ssh-rsa -P2222 -r ./public {{ .Status.Info.Username }}@bagage.resdigita.org:mon_bucket/ scp -oHostKeyAlgorithms=+ssh-rsa -P2222 -r ./public {{ .Login.Status.Info.Username }}@bagage.resdigita.org:mon_bucket/
</pre> </pre>
</div> </div>
</div> </div>

View file

@ -35,7 +35,7 @@
</tr> </tr>
<tr> <tr>
<th scope="row">Document d'erreur</th> <th scope="row">Document d'erreur</th>
<td>{{ .ErrorDoc }}</td> <td>{{ .Common.ErrorDoc }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Nombre de fichiers</th> <th scope="row">Nombre de fichiers</th>

View file

@ -5,7 +5,7 @@
{{define "body"}} {{define "body"}}
<div class="alert alert-info"> <div class="alert alert-info">
Bienvenue, <strong>{{ .Login.WelcomeName }}</strong> ! Bienvenue, <strong>{{ .Login.Login.WelcomeName }}</strong> !
</div> </div>
<div class="mt-3"> <div class="mt-3">

View file

@ -7,18 +7,18 @@
<div class="d-flex"> <div class="d-flex">
<h2>Création d'un nouveau compte</h2> <h2>Création d'un nouveau compte</h2>
</div> </div>
{{if .ErrorMessage}} {{if .Common.ErrorMessage}}
<div class="alert alert-danger mt-4">Impossible de créer le compte. <div class="alert alert-danger mt-4">Impossible de créer le compte.
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div> <div style="font-size: 0.8em">{{ .Common.ErrorMessage }}</div>
</div> </div>
{{end}} {{end}}
{{if .WarningMessage}} {{if .Common.WarningMessage}}
<div class="alert alert-danger mt-4">Des erreurs se sont produites, le compte pourrait ne pas être totalement <div class="alert alert-danger mt-4">Des erreurs se sont produites, le compte pourrait ne pas être totalement
fonctionnel. fonctionnel.
<div style="font-size: 0.8em">{{ .WarningMessage }}</div> <div style="font-size: 0.8em">{{ .Common.WarningMessage }}</div>
</div> </div>
{{end}} {{end}}
{{if .Success}} {{if .Common.Success}}
<div class="alert alert-success mt-4"> <div class="alert alert-success mt-4">
Le compe a été créé ! Le compe a été créé !
Rendez-vous <a href="/logout">sur la page d'accueil</a> pour vous connecter avec ce nouveau compte. Rendez-vous <a href="/logout">sur la page d'accueil</a> pour vous connecter avec ce nouveau compte.
@ -46,20 +46,20 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="username">Identifiant :</label> <label for="username">Identifiant :</label>
<input type="text" id="username" name="username" class="form-control" value="{{ .Username }}" /> <input type="text" id="username" name="username" class="form-control" value="{{ .Login.Login.Username }}" />
<small class="form-text text-muted"> <small class="form-text text-muted">
Votre identifiant doit être en minuscule. Votre identifiant doit être en minuscule.
</small> </small>
</div> </div>
<div id="calc-uid"></div> <div id="calc-uid"></div>
<div id="calc-cn"></div> <div id="calc-cn"></div>
{{if .ErrorInvalidUsername}} {{if .Common.ErrorInvalidUsername}}
<div class="alert alert-warning"> <div class="alert alert-warning">
Nom d'utilisateur invalide. Ne peut contenir que les caractères suivants : chiffres, lettres minuscules, point, Nom d'utilisateur invalide. Ne peut contenir que les caractères suivants : chiffres, lettres minuscules, point,
tiret bas (_) et tiret du milieu (-). tiret bas (_) et tiret du milieu (-).
</div> </div>
{{end}} {{end}}
{{if .ErrorUsernameTaken}} {{if .Common.ErrorUsernameTaken}}
<div class="alert alert-warning"> <div class="alert alert-warning">
Ce nom d'utilisateur est déjà pris. Ce nom d'utilisateur est déjà pris.
</div> </div>
@ -80,7 +80,7 @@
caractères spéciaux sans modération ! caractères spéciaux sans modération !
</small> </small>
</div> </div>
{{if .ErrorPasswordTooShort}} {{if .Common.ErrorPasswordTooShort}}
<div class="alert alert-warning"> <div class="alert alert-warning">
Le mot de passe choisi est trop court (minimum 8 caractères). Le mot de passe choisi est trop court (minimum 8 caractères).
</div> </div>
@ -89,7 +89,7 @@
<label for="password2">Répéter le mot de passe :</label> <label for="password2">Répéter le mot de passe :</label>
<input type="password" id="password2" name="password2" class="form-control" /> <input type="password" id="password2" name="password2" class="form-control" />
</div> </div>
{{if .ErrorPasswordMismatch}} {{if .Common.ErrorPasswordMismatch}}
<div class="alert alert-warning"> <div class="alert alert-warning">
Les deux mots de passe entrés ne correspondent pas. Les deux mots de passe entrés ne correspondent pas.
</div> </div>

View file

@ -8,12 +8,12 @@
<a class="ml-auto btn btn-info" href="/">Retour</a> <a class="ml-auto btn btn-info" href="/">Retour</a>
</div> </div>
{{if .ErrorMessage}} {{if .Common.ErrorMessage}}
<div class="alert alert-danger mt-4">Impossible de génerer ou d'envoyer le code. <div class="alert alert-danger mt-4">Impossible de génerer ou d'envoyer le code.
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div> <div style="font-size: 0.8em">{{ .Common.ErrorMessage }}</div>
</div> </div>
{{end}} {{end}}
{{if .Success}} {{if .Common.Success}}
<div class="alert alert-success mt-4"> <div class="alert alert-success mt-4">
{{if .CodeSentTo}} {{if .CodeSentTo}}
Un code d'invitation a bien été envoyé à <code>{{ .CodeSentTo }}</code>. Un code d'invitation a bien été envoyé à <code>{{ .CodeSentTo }}</code>.
@ -41,7 +41,7 @@
</label> </label>
<input class="form-control" type="text" name="sendto" id="sendto" placeholder="Addresse mail..." onclick="document.getElementById('choice_send').checked = true;" /> <input class="form-control" type="text" name="sendto" id="sendto" placeholder="Addresse mail..." onclick="document.getElementById('choice_send').checked = true;" />
</div> </div>
{{if .ErrorInvalidEmail}} {{if .Common.ErrorInvalidEmail}}
<div class="alert alert-warning mt-4"> <div class="alert alert-warning mt-4">
Addresse mail invalide. Addresse mail invalide.
</div> </div>

View file

@ -55,7 +55,7 @@
<li><a href="https://www.lesgrandsvoisins.com/admin">Editer le site web</a></li> <li><a href="https://www.lesgrandsvoisins.com/admin">Editer le site web</a></li>
<li><a href="https://www.lesgrandsvoisins.com/admin">Editer le blog</a></li> <li><a href="https://www.lesgrandsvoisins.com/admin">Editer le blog</a></li>
</ul></li> </ul></li>
{{if .CanAdmin}} {{if .Common.CanAdmin}}
<li>&lt;&nbsp;<a href="#">Administration</a> <li>&lt;&nbsp;<a href="#">Administration</a>
<ul class="submenu"> <ul class="submenu">
<!-- <li><a href="/admin/activate">Administrer LDAP</a> --> <!-- <li><a href="/admin/activate">Administrer LDAP</a> -->
@ -67,7 +67,7 @@
{{end}} {{end}}
<li>&lt;&nbsp;<a href="#">Compte</a> <li>&lt;&nbsp;<a href="#">Compte</a>
<ul class="submenu"> <ul class="submenu">
{{if .LoggedIn}} {{if .Common.LoggedIn}}
<li><a href="/logout">Se déconnecter</a></li> <li><a href="/logout">Se déconnecter</a></li>
<li><a href="/">Tableau de bord</a></li> <li><a href="/">Tableau de bord</a></li>
<li><a href="/profile">Modifier mon profil</a></li> <li><a href="/profile">Modifier mon profil</a></li>

View file

@ -17,14 +17,14 @@
{{if .WrongPass}} {{if .WrongPass}}
<div class="alert alert-danger">Mot de passe invalide.</div> <div class="alert alert-danger">Mot de passe invalide.</div>
{{end}} {{end}}
{{if .ErrorMessage}} {{if .Common.ErrorMessage}}
<div class="alert alert-danger">Impossible de se connecter. <div class="alert alert-danger">Impossible de se connecter.
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div> <div style="font-size: 0.8em">{{ .Common.ErrorMessage }}</div>
</div> </div>
{{end}} {{end}}
<div class="form-group"> <div class="form-group">
<label for="username">Identifiant :</label> <label for="username">Identifiant :</label>
<input type="text" name="username" id="username" class="form-control" value="{{ .Username }}" /> <input type="text" name="username" id="username" class="form-control" value="{{ .Login.Login.Username }}" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="password">Mot de passe :</label> <label for="password">Mot de passe :</label>

View file

@ -8,12 +8,12 @@
<h2>Modifier mon mot de passe</h2> <h2>Modifier mon mot de passe</h2>
</div> </div>
{{if .ErrorMessage}} {{if .Common.ErrorMessage}}
<div class="alert alert-danger mt-4">Impossible d'effectuer la modification. <div class="alert alert-danger mt-4">Impossible d'effectuer la modification.
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div> <div style="font-size: 0.8em">{{ .Common.ErrorMessage }}</div>
</div> </div>
{{end}} {{end}}
{{if .Success}} {{if .Common.Success}}
<div class="alert alert-success mt-4"> <div class="alert alert-success mt-4">
Nouveau mot de passe enregistré. Nouveau mot de passe enregistré.
</div> </div>

View file

@ -8,12 +8,12 @@
<p>Refaire son mot de passe</p> <p>Refaire son mot de passe</p>
{{if .ErrorMessage}} {{if .Common.ErrorMessage}}
<div class="alert alert-danger">Impossible <div class="alert alert-danger">Impossible
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div> <div style="font-size: 0.8em">{{ .Common.ErrorMessage }}</div>
</div> </div>
{{end}} {{end}}
{{if .Success}} {{if .Common.Success}}
<div class="alert alert-success mt-4"> <div class="alert alert-success mt-4">
Email envoyé au courriel de secours. Email envoyé au courriel de secours.
</div> </div>
@ -24,7 +24,7 @@
<form method="POST"> <form method="POST">
<div class="form-group"> <div class="form-group">
<label for="username">Ou identifiant :</label> <label for="username">Ou identifiant :</label>
<input type="text" name="username" id="username" class="form-control" value="{{ .Username }}" /> <input type="text" name="username" id="username" class="form-control" value="{{ .Login.Login.Username }}" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="mail">ou mail (interne aux GV) :</label> <label for="mail">ou mail (interne aux GV) :</label>

View file

@ -8,12 +8,12 @@
<h2>Modifier mon profil</h2> <h2>Modifier mon profil</h2>
</div> </div>
{{if .ErrorMessage}} {{if .Common.ErrorMessage}}
<div class="alert alert-danger mt-4">Impossible d'effectuer la modification. <div class="alert alert-danger mt-4">Impossible d'effectuer la modification.
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div> <div style="font-size: 0.8em">{{ .Common.ErrorMessage }}</div>
</div> </div>
{{end}} {{end}}
{{if .Success}} {{if .Common.Success}}
<div class="alert alert-success mt-4"> <div class="alert alert-success mt-4">
Profil enregistré. Profil enregistré.
</div> </div>
@ -22,7 +22,7 @@
<div class="form-row"> <div class="form-row">
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label>Identifiant:</label> <label>Identifiant:</label>
<input type="text" disabled="true" class="form-control" value="{{ .Status.Info.Username }}" /> <input type="text" disabled="true" class="form-control" value="{{ .Login.Status.Info.Username }}" />
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="mail">Adresse e-mail:</label> <label for="mail">Adresse e-mail:</label>