From ea1cc69f8dfdebb44d9b278fc9f9023a53338af1 Mon Sep 17 00:00:00 2001 From: Dusan Jakub Date: Mon, 11 Sep 2023 16:53:09 +0200 Subject: [PATCH] Login submit --- .../java/com/ysoft/geecon/OAuthResource.java | 40 +++++---- .../templates/OAuthResource/consents.html | 81 +++++++++++++++++++ .../{hello.html => OAuthResource/login.html} | 13 +++ 3 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/templates/OAuthResource/consents.html rename src/main/resources/templates/{hello.html => OAuthResource/login.html} (83%) diff --git a/src/main/java/com/ysoft/geecon/OAuthResource.java b/src/main/java/com/ysoft/geecon/OAuthResource.java index ad79717..519e724 100644 --- a/src/main/java/com/ysoft/geecon/OAuthResource.java +++ b/src/main/java/com/ysoft/geecon/OAuthResource.java @@ -1,28 +1,38 @@ package com.ysoft.geecon; -import io.quarkus.qute.Template; +import io.quarkus.qute.CheckedTemplate; import io.quarkus.qute.TemplateInstance; -import jakarta.inject.Inject; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.QueryParam; +import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; +import java.util.List; + @Path("/auth") public class OAuthResource { - @Inject - Template hello; + + @CheckedTemplate + public static class Templates { + public static native TemplateInstance login(String loginHint, String error); + public static native TemplateInstance consents(List scopes, String error); + } + + @GET @Produces(MediaType.TEXT_HTML) public TemplateInstance get(@QueryParam("login_hint") String loginHint) { - return hello.data("loginHint", loginHint); + return Templates.login(loginHint, ""); + } + + @POST + @Produces(MediaType.TEXT_HTML) + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public TemplateInstance post(@FormParam("username") String username, + @FormParam("password") String password ) { + if ("Password1".equals(password)) { + return Templates.consents(List.of("scope1"), ""); + } else { + return Templates.login(username, "invalid_credentials"); + } } -// -// @GET -// @Produces(MediaType.TEXT_PLAIN) -// public String hello() { -// return "Auth"; -// } } diff --git a/src/main/resources/templates/OAuthResource/consents.html b/src/main/resources/templates/OAuthResource/consents.html new file mode 100644 index 0000000..603d557 --- /dev/null +++ b/src/main/resources/templates/OAuthResource/consents.html @@ -0,0 +1,81 @@ + + + + + + Login Page + + + + + + diff --git a/src/main/resources/templates/hello.html b/src/main/resources/templates/OAuthResource/login.html similarity index 83% rename from src/main/resources/templates/hello.html rename to src/main/resources/templates/OAuthResource/login.html index 5a16293..398dbf5 100644 --- a/src/main/resources/templates/hello.html +++ b/src/main/resources/templates/OAuthResource/login.html @@ -56,11 +56,23 @@ .login-button:hover { background-color: #0056b3; } + + .error-popup { + background-color: #ff6b6b; + color: #fff; + padding: 10px; + text-align: center; + border-radius: 5px; + margin-top: 10px; + }