diff --git a/main.go b/main.go index 21a0643..653cbdf 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,8 @@ func config() gloableConfig { if err != nil { log.Fatal().Err(err).Msg("cant parse config") } + + fmt.Printf("%+v\r\n", c) return c } diff --git a/pkg/miniauth/miniauth.go b/pkg/miniauth/miniauth.go index c135c22..8ed0bbc 100644 --- a/pkg/miniauth/miniauth.go +++ b/pkg/miniauth/miniauth.go @@ -10,6 +10,7 @@ import ( "git.keks.cloud/kekskurse/miniauth/pkg/utils" "github.com/go-passwd/validator" "github.com/rs/zerolog" + "github.com/rs/zerolog/log" ) type MiniauthConfig struct { @@ -27,6 +28,8 @@ func NewMiniauth(conf MiniauthConfig, us userstore.Store, sm smtpclient.SMTPClie m := Miniauth{} m.store = us m.smtp = sm + m.config = conf + m.log = log.With().Str("pkg", "miniauth").Logger() return m } diff --git a/pkg/web/web.go b/pkg/web/web.go index 45352e3..9537f93 100644 --- a/pkg/web/web.go +++ b/pkg/web/web.go @@ -26,6 +26,8 @@ func NewWeb(config WebConfig, ma miniauth.Miniauth) Web { func (w Web) RegisterRoutes(routing *gin.RouterGroup) error { routing.GET("/register", w.GetRegisterPage) routing.POST("/register", w.PostRegisterPage) + routing.GET("/login", w.GetLoginPage) + routing.POST("/login", w.PostLoginPage) return nil } @@ -56,3 +58,20 @@ func (w Web) PostRegisterPage(c *gin.Context) { c.HTML(403, "msg.html", gin.H{"msg": "Your account was created, you can login now"}) } + +func (w Web) GetLoginPage(c *gin.Context) { + c.HTML(http.StatusOK, "login.html", nil) +} + +func (w Web) PostLoginPage(c *gin.Context) { + username := c.PostForm("username") + password := c.PostForm("password") + + err := w.ma.UserLogin(username, password) + if err != nil { + c.HTML(http.StatusOK, "login.html", gin.H{"msg": err.Error()}) + return + } + + c.HTML(http.StatusOK, "msg.html", gin.H{"msg": "Login ok!"}) +} diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..14783fd --- /dev/null +++ b/templates/login.html @@ -0,0 +1,58 @@ + + + + + + + Registrierung + + + +
+

Login

+ {{ if .msg }} +
+ {{ .msg }} +
+ {{ end }} +
+
+ + +
+
+ + +
+ +
+ + + +

Need an Account? Register

+
+ + + diff --git a/templates/register.html b/templates/register.html index c497926..1ff1eb8 100644 --- a/templates/register.html +++ b/templates/register.html @@ -60,7 +60,7 @@ !--> -

Already have an account?? Login

+

Already have an account? Login