This commit is contained in:
parent
2d39757d71
commit
16292a3b74
3 changed files with 14 additions and 8 deletions
9
main.go
9
main.go
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"embed"
|
"embed"
|
||||||
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/sample"
|
"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/user"
|
||||||
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/webpage"
|
"git.keks.cloud/kekskurse/go-sample-webpage/pkg/webpage"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/jwtauth/v5"
|
"github.com/go-chi/jwtauth/v5"
|
||||||
|
gomail "gopkg.in/mail.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// content holds our static web server content.
|
// content holds our static web server content.
|
||||||
|
@ -23,10 +25,13 @@ func main() {
|
||||||
Migrations: migrationFS,
|
Migrations: migrationFS,
|
||||||
Bootstrap: func(router chi.Router) {
|
Bootstrap: func(router chi.Router) {
|
||||||
tokenAuth := jwtauth.New("HS256", []byte("secret"), nil)
|
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)
|
sample.Register(router)
|
||||||
user.Register(router, tokenAuth, uc)
|
user.Register(router, tokenAuth, uc, d)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
@ -24,7 +23,9 @@ var uc UserClient
|
||||||
|
|
||||||
var tokenAuth *jwtauth.JWTAuth
|
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
|
uc = userClient
|
||||||
ren = render.New(render.Options{
|
ren = render.New(render.Options{
|
||||||
//Layout: "layout",
|
//Layout: "layout",
|
||||||
|
@ -39,9 +40,10 @@ func Register(router chi.Router, token *jwtauth.JWTAuth, userClient UserClient)
|
||||||
router.Post("/register", register)
|
router.Post("/register", register)
|
||||||
router.Get("/logout", logout)
|
router.Get("/logout", logout)
|
||||||
|
|
||||||
//tokenAuth = jwtauth.New("HS256", []byte("secret"), nil)
|
|
||||||
tokenAuth = token
|
tokenAuth = token
|
||||||
|
|
||||||
|
d = dialer
|
||||||
|
|
||||||
router.Group(func(r chi.Router) {
|
router.Group(func(r chi.Router) {
|
||||||
r.Use(jwtauth.Verifier(tokenAuth))
|
r.Use(jwtauth.Verifier(tokenAuth))
|
||||||
r.Get("/me", func(w http.ResponseWriter, r *http.Request) {
|
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/plain", "This is Gomail test body")
|
||||||
m.SetBody("text/html", string(content))
|
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 {
|
if err := d.DialAndSend(m); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
|
@ -18,7 +18,7 @@ type UserClientMemory struct {
|
||||||
|
|
||||||
var u *UserClientMemory
|
var u *UserClientMemory
|
||||||
|
|
||||||
func GetUserClient() *UserClientMemory {
|
func GetUserMemmoryClient() *UserClientMemory {
|
||||||
if u == nil {
|
if u == nil {
|
||||||
uc := UserClientMemory{}
|
uc := UserClientMemory{}
|
||||||
uc.users = make(map[string]string)
|
uc.users = make(map[string]string)
|
||||||
|
|
Loading…
Reference in a new issue