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 @@ + +<!DOCTYPE html> +<html lang="de"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Registrierung</title> + <script src="https://cdn.tailwindcss.com"></script> +</head> +<body class="bg-gray-100 flex items-center justify-center min-h-screen"> + <div class="bg-white p-8 shadow-xl w-full max-w-md"> + <h2 class="text-2xl font-semibold text-gray-900 text-center mb-6">Login</h2> + {{ if .msg }} + <div id="global-error" class=" bg-red-100 text-red-700 p-3 text-center mb-4 border border-red-400"> + {{ .msg }} + </div> + {{ end }} + <form action="#" method="POST" class="space-y-4"> + <div> + <label for="username" class="block text-sm font-medium text-gray-700">Username</label> + <input type="text" id="username" name="username" required + class="mt-1 p-3 w-full border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none"> + </div> + <div> + <label for="password" class="block text-sm font-medium text-gray-700">Password</label> + <input type="password" id="password" name="password" required + class="mt-1 p-3 w-full border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none"> + </div> + <button type="submit" + class="w-full bg-blue-600 text-white py-3 text-lg font-medium hover:bg-blue-700 focus:ring-4 focus:ring-blue-300"> + Login + </button> + </form> + + <!-- + <div class="mt-6 border-t border-gray-300 pt-6 space-y-3"> + <button class="w-full flex items-center justify-center gap-2 bg-gray-900 text-white py-3 text-lg font-medium hover:bg-gray-800 focus:ring-4 focus:ring-gray-500"> + <svg class="w-5 h-5" viewBox="0 0 24 24" fill="white" xmlns="http://www.w3.org/2000/svg"> + <path d="M12 .296c-6.63 0-12 5.373-12 12 0 5.292 3.438 9.793 8.206 11.385.6.11.82-.261.82-.58 0-.287-.01-1.05-.015-2.06-3.338.724-4.042-1.607-4.042-1.607-.546-1.387-1.333-1.756-1.333-1.756-1.089-.744.083-.729.083-.729 1.205.085 1.84 1.238 1.84 1.238 1.07 1.835 2.805 1.305 3.49.998.108-.775.42-1.305.763-1.604-2.665-.3-5.467-1.33-5.467-5.93 0-1.308.465-2.38 1.235-3.22-.125-.302-.535-1.522.116-3.17 0 0 1.007-.322 3.3 1.23a11.54 11.54 0 0 1 3-.404c1.017.005 2.043.137 3 .404 2.292-1.552 3.296-1.23 3.296-1.23.654 1.648.244 2.868.12 3.17.77.84 1.23 1.912 1.23 3.22 0 4.61-2.807 5.625-5.478 5.92.43.37.814 1.102.814 2.22 0 1.606-.015 2.896-.015 3.293 0 .322.216.696.825.578 4.765-1.594 8.2-6.095 8.2-11.387 0-6.627-5.373-12-12-12Z"/> + </svg> + Mit GitHub anmelden + </button> + <button class="w-full flex items-center justify-center gap-2 bg-red-600 text-white py-3 text-lg font-medium hover:bg-red-700 focus:ring-4 focus:ring-red-300"> + <svg class="w-5 h-5" viewBox="0 0 24 24" fill="white" xmlns="http://www.w3.org/2000/svg"> + <path d="M23.994 12.263c0-.81-.072-1.585-.18-2.32H12v4.59h6.785c-.31 1.576-1.237 2.916-2.64 3.829v3.19h4.28c2.51-2.325 3.97-5.744 3.97-9.29z"/> + <path d="M12 24c3.24 0 5.953-1.08 7.94-2.91l-3.97-3.19c-1.09.74-2.48 1.18-3.97 1.18-3.05 0-5.64-2.05-6.57-4.81H.33v3.25C2.32 20.445 6.83 24 12 24z"/> + <path d="M5.43 14.23A7.97 7.97 0 0 1 4 12c0-.77.127-1.52.33-2.23V6.52H.33A11.998 11.998 0 0 0 0 12c0 1.94.467 3.77 1.28 5.48l4.15-3.25z"/> + </svg> + Mit Google anmelden + </button> + </div> + !--> + + <p class="text-sm text-gray-600 text-center mt-4">Need an Account? <a href="/web/register" class="text-blue-500 hover:underline">Register</a></p> + </div> +</body> +</html> + 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 @@ </div> !--> - <p class="text-sm text-gray-600 text-center mt-4">Already have an account?? <a href="#" class="text-blue-500 hover:underline">Login</a></p> + <p class="text-sm text-gray-600 text-center mt-4">Already have an account? <a href="/web/login" class="text-blue-500 hover:underline">Login</a></p> </div> </body> </html>