-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui_reset.go
37 lines (33 loc) · 1.1 KB
/
ui_reset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// +build plain
package main
import (
"log"
"net/http"
gomail "gopkg.in/gomail.v2"
)
func reset(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
templ.ExecuteTemplate(w, "reset", nil)
case "POST":
var user User
user.Email = r.FormValue("email")
if err := sqlGetUser(&user); err != nil {
http.Error(w, http.StatusText(http.StatusNotAcceptable), http.StatusNotAcceptable)
return
}
// https://stackoverflow.com/a/24431749
mail := gomail.NewMessage()
mail.SetAddressHeader("From", config.SMTP.User, config.SMTP.Name)
mail.SetAddressHeader("To", r.FormValue("email"), "")
mail.SetHeader("Subject", "Check your password request")
mail.SetBody("text/html", user.Password)
dialer := gomail.NewPlainDialer(config.SMTP.Server, config.SMTP.Port, config.SMTP.User, config.SMTP.Password)
//dialer.TLSConfig = &tls.Config{InsecureSkipVerify: true}
if err := dialer.DialAndSend(mail); err != nil {
log.Println(err)
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte("A mail with instructions was send, read and <a href=\"/\">sign in</a>"))
}
}