G Pas
This commit is contained in:
parent
dca6b2190b
commit
7eedf221d5
1 changed files with 21 additions and 19 deletions
40
gpas.go
40
gpas.go
|
@ -5,14 +5,14 @@ gpas is GVoisin password reset
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/emersion/go-sasl"
|
// "github.com/emersion/go-sasl"
|
||||||
"github.com/emersion/go-smtp"
|
// "github.com/emersion/go-smtp"
|
||||||
|
"net/smtp"
|
||||||
|
|
||||||
"github.com/go-ldap/ldap/v3"
|
"github.com/go-ldap/ldap/v3"
|
||||||
// "strings"
|
// "strings"
|
||||||
)
|
)
|
||||||
|
@ -46,22 +46,24 @@ func passwordLost(user User, config *ConfigFile, ldapConn *ldap.Conn) error {
|
||||||
return errors.New("Il n'y a pas d'utilisateur qui correspond")
|
return errors.New("Il n'y a pas d'utilisateur qui correspond")
|
||||||
}
|
}
|
||||||
// Préparation du courriel à envoyer
|
// Préparation du courriel à envoyer
|
||||||
code := "GPas"
|
// code := "GPas"
|
||||||
templateMail := template.Must(template.ParseFiles(templatePath + "/invite_mail.txt"))
|
// templateMail := template.Must(template.ParseFiles(templatePath + "/invite_mail.txt"))
|
||||||
buf := bytes.NewBuffer([]byte{})
|
// buf := bytes.NewBuffer([]byte{})
|
||||||
templateMail.Execute(buf, &CodeMailFields{
|
// templateMail.Execute(buf, &CodeMailFields{
|
||||||
To: user.OtherMailbox,
|
// To: user.OtherMailbox,
|
||||||
From: config.MailFrom,
|
// From: config.MailFrom,
|
||||||
InviteFrom: "GPas",
|
// InviteFrom: "GPas",
|
||||||
Code: code,
|
// Code: code,
|
||||||
WebBaseAddress: config.WebAddress,
|
// WebBaseAddress: config.WebAddress,
|
||||||
})
|
// })
|
||||||
|
message := []byte("Hi " + user.OtherMailbox)
|
||||||
log.Printf("Sending mail to: %s", user.OtherMailbox)
|
log.Printf("Sending mail to: %s", user.OtherMailbox)
|
||||||
var auth sasl.Client = nil
|
// var auth sasl.Client = nil
|
||||||
if config.SMTPUsername != "" {
|
// if config.SMTPUsername != "" {
|
||||||
auth = sasl.NewPlainClient("", config.SMTPUsername, config.SMTPPassword)
|
// auth = sasl.NewPlainClient("", config.SMTPUsername, config.SMTPPassword)
|
||||||
}
|
// }
|
||||||
err = smtp.SendMail(config.SMTPServer, auth, config.MailFrom, []string{user.OtherMailbox}, buf)
|
auth := smtp.PlainAuth("", config.SMTPUsername, config.SMTPPassword, config.SMTPServer)
|
||||||
|
err = smtp.SendMail(config.SMTPServer+":587", auth, config.SMTPUsername, []string{user.OtherMailbox}, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue