mirror of
https://github.com/ysoftdevs/oauth-playground-server.git
synced 2026-01-17 09:07:12 +01:00
Login submit
This commit is contained in:
@@ -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<String> 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";
|
||||
// }
|
||||
}
|
||||
|
||||
81
src/main/resources/templates/OAuthResource/consents.html
Normal file
81
src/main/resources/templates/OAuthResource/consents.html
Normal file
@@ -0,0 +1,81 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Login Page</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.login-container {
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.login-container h2 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
font-weight: bold;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.form-group input {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.login-button {
|
||||
width: 100%;
|
||||
background-color: #007BFF;
|
||||
color: #fff;
|
||||
border: none;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.login-button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
|
||||
.error-popup {
|
||||
background-color: #ff6b6b;
|
||||
color: #fff;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
border-radius: 5px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<h2>Consents</h2>
|
||||
{#if error == "invalid_credentials"}
|
||||
<div class="error-popup" id="error-popup">Invalid credentials</div>
|
||||
{/if}
|
||||
<form action="" method="post">
|
||||
<button type="submit" class="login-button">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</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;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<h2>Login</h2>
|
||||
{#if error == "invalid_credentials"}
|
||||
<div class="error-popup" id="error-popup">Invalid credentials</div>
|
||||
{/if}
|
||||
<form action="" method="post">
|
||||
<div class="form-group">
|
||||
<label for="username">Username:</label>
|
||||
@@ -68,6 +80,7 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password:</label>
|
||||
(try "Password1")
|
||||
<input type="password" id="password" name="password" required>
|
||||
</div>
|
||||
<button type="submit" class="login-button">Login</button>
|
||||
Reference in New Issue
Block a user