選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

81 行
1.8KB

  1. package main
  2. import (
  3. "biukop.com/sfm/loan"
  4. "fmt"
  5. "github.com/brianvoe/gofakeit/v6"
  6. log "github.com/sirupsen/logrus"
  7. "net/http"
  8. "net/smtp"
  9. "strings"
  10. )
  11. func apiV1EmailPassword(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
  12. id := r.URL.Path[len(apiV1Prefix+"email-password/"):] //remove prefix
  13. u := loan.User{}
  14. e := u.Read(id)
  15. if e != nil {
  16. apiV1Client403Error(w, r, ss)
  17. return
  18. }
  19. newPass := gofakeit.Password(true, true, true, false, false, 8)
  20. log.Info("newPass", u, newPass)
  21. u.SetPass(newPass)
  22. e = u.Write()
  23. if e != nil {
  24. apiV1Client403Error(w, r, ss)
  25. return
  26. }
  27. sendEmailPassLink(u, u.Login, newPass)
  28. apiV1SendJson(true, w, r, ss)
  29. }
  30. func sendEmailPassLink(user loan.User, email string, pass string) {
  31. // Sender data.
  32. from := "mailer@biukop.com.au"
  33. password := "hpfitsrujgkewcdw"
  34. // Receiver email address.
  35. to := []string{
  36. "patrick@biukop.com.au",
  37. email,
  38. }
  39. // smtp server configuration.
  40. smtpHost := "smtp.gmail.com"
  41. smtpPort := "587"
  42. raw := `Subject: Password Reset
  43. Dear {user},
  44. We have reset your password to {pass}. Please logon to https://sfmarkets.com.au/broker to check your new credentials.
  45. There is no need to reply this mail. If you encounter any difficulties, please contact SuperFinance market directly.
  46. This is an automated email, and no one is monitoring this mailbox, please do not reply.
  47. Kind Regards
  48. Biukop Mailing service team.
  49. `
  50. raw = strings.Replace(raw, "{user}", user.Display, -1)
  51. raw = strings.Replace(raw, "{pass}", pass, -1)
  52. // Message.
  53. message := []byte(raw)
  54. // Authentication.
  55. auth := smtp.PlainAuth("", from, password, smtpHost)
  56. // Sending email.
  57. err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, to, message)
  58. if err != nil {
  59. fmt.Println(err)
  60. return
  61. }
  62. fmt.Println("Email Sent Successfully!")
  63. }