From 16292a3b742253f9b0e6ecb83241ec1ea85c9e74 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Mon, 22 Nov 2021 23:46:01 +0100 Subject: [PATCH] Register Stuff --- main.go | 9 +++++++-- pkg/user/user.go | 11 ++++++----- pkg/user/userclient.go | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index a372b0b..d5b9f9f 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,14 @@ package main import ( + "crypto/tls" "embed" "git.keks.cloud/kekskurse/go-sample-webpage/pkg/sample" "git.keks.cloud/kekskurse/go-sample-webpage/pkg/user" "git.keks.cloud/kekskurse/go-sample-webpage/pkg/webpage" "github.com/go-chi/chi/v5" "github.com/go-chi/jwtauth/v5" + gomail "gopkg.in/mail.v2" ) // content holds our static web server content. @@ -23,10 +25,13 @@ func main() { Migrations: migrationFS, Bootstrap: func(router chi.Router) { tokenAuth := jwtauth.New("HS256", []byte("secret"), nil) - uc := user.GetUserClient() + uc := user.GetUserMemmoryClient() + + d := gomail.NewDialer("localhost", 1025, "from@gmail.com", "email_password") + d.TLSConfig = &tls.Config{InsecureSkipVerify: true} sample.Register(router) - user.Register(router, tokenAuth, uc) + user.Register(router, tokenAuth, uc, d) }, } diff --git a/pkg/user/user.go b/pkg/user/user.go index e707d5f..8a5ab1a 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -2,7 +2,6 @@ package user import ( "bytes" - "crypto/tls" "embed" "fmt" "github.com/go-chi/chi/v5" @@ -24,7 +23,9 @@ var uc UserClient var tokenAuth *jwtauth.JWTAuth -func Register(router chi.Router, token *jwtauth.JWTAuth, userClient UserClient) { +var d *gomail.Dialer + +func Register(router chi.Router, token *jwtauth.JWTAuth, userClient UserClient, dialer *gomail.Dialer) { uc = userClient ren = render.New(render.Options{ //Layout: "layout", @@ -39,9 +40,10 @@ func Register(router chi.Router, token *jwtauth.JWTAuth, userClient UserClient) router.Post("/register", register) router.Get("/logout", logout) - //tokenAuth = jwtauth.New("HS256", []byte("secret"), nil) tokenAuth = token + d = dialer + router.Group(func(r chi.Router) { r.Use(jwtauth.Verifier(tokenAuth)) r.Get("/me", func(w http.ResponseWriter, r *http.Request) { @@ -123,8 +125,7 @@ func register(w http.ResponseWriter, r *http.Request) { m.SetBody("text/plain", "This is Gomail test body") m.SetBody("text/html", string(content)) - d := gomail.NewDialer("localhost", 1025, "from@gmail.com", "email_password") - d.TLSConfig = &tls.Config{InsecureSkipVerify: true} + if err := d.DialAndSend(m); err != nil { fmt.Println(err) diff --git a/pkg/user/userclient.go b/pkg/user/userclient.go index 5a44357..f73014b 100644 --- a/pkg/user/userclient.go +++ b/pkg/user/userclient.go @@ -18,7 +18,7 @@ type UserClientMemory struct { var u *UserClientMemory -func GetUserClient() *UserClientMemory { +func GetUserMemmoryClient() *UserClientMemory { if u == nil { uc := UserClientMemory{} uc.users = make(map[string]string)