Refactoring
This commit is contained in:
parent
9acc67a06a
commit
49f650e350
4 changed files with 40 additions and 1 deletions
|
@ -165,5 +165,7 @@ func passwordFound(user User, config *ConfigFile, ldapConn *ldap.Conn) (string,
|
|||
log.Printf("passwordFound %v", searchRes)
|
||||
return "", err
|
||||
}
|
||||
delReq := ldap.NewDelRequest("uid="+user.CN+","+config.InvitationBaseDN, nil)
|
||||
ldapConn.Del(delReq)
|
||||
return searchRes.Entries[0].GetAttributeValue("seeAlso"), err
|
||||
}
|
||||
|
|
|
@ -86,6 +86,9 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
|||
if user.SN != "" {
|
||||
req.Attribute("sn", []string{user.SN})
|
||||
}
|
||||
if user.OtherMailbox != "" {
|
||||
req.Attribute("carLicense", []string{user.OtherMailbox})
|
||||
}
|
||||
if user.Description != "" {
|
||||
req.Attribute("description", []string{user.Description})
|
||||
}
|
||||
|
@ -112,8 +115,18 @@ func add(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// Send the email
|
||||
err = sendMail(SendMailTplData{
|
||||
From: "alice@resdigita.org",
|
||||
To: user.OtherMailbox,
|
||||
ContentVars: map[string]string{
|
||||
"InviteFrom": "alice@resdigita.org",
|
||||
"SebAddress": "https://www.gvoisins.org",
|
||||
"Code": "...",
|
||||
},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func modify(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||
|
|
11
utils.go
11
utils.go
|
@ -1,12 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"math/rand"
|
||||
|
||||
"html/template"
|
||||
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
// "golang.org/x/text/encoding/unicode"
|
||||
)
|
||||
|
@ -47,3 +50,11 @@ func suggestPassword() string {
|
|||
}
|
||||
return password
|
||||
}
|
||||
|
||||
// Sends an email according to the enclosed information
|
||||
func sendMail(sendMailTplData SendMailTplData) error {
|
||||
templateMail := template.Must(template.ParseFiles(templatePath + "/" + sendMailTplData.RelTemplatePath))
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
err := templateMail.Execute(buf, sendMailTplData)
|
||||
return err
|
||||
}
|
||||
|
|
13
view.go
13
view.go
|
@ -218,6 +218,19 @@ type LoginFormData struct {
|
|||
Common NestedCommonTplData
|
||||
}
|
||||
|
||||
// Data to be passed to an email for sending
|
||||
type SendMailTplData struct {
|
||||
// Sender of the email
|
||||
To string
|
||||
// Receiver of the email
|
||||
From string
|
||||
// Relative path (without leading /) to the email template in the templates folder
|
||||
// usually ending in .txt
|
||||
RelTemplatePath string
|
||||
// Variables to be included in the template of the email
|
||||
ContentVars map[string]string
|
||||
}
|
||||
|
||||
var templatePath = "./templates"
|
||||
|
||||
func getTemplate(name string) *template.Template {
|
||||
|
|
Loading…
Reference in a new issue