Skip to content

Commit

Permalink
feat: improve UI (#7)
Browse files Browse the repository at this point in the history
* feat: testCI

Test the CI

* Update MenuService.java

* feat: Improve user friendliness

feat: Improve user friendliness
  • Loading branch information
amikecoXu authored Feb 2, 2024
1 parent 0c18cc2 commit 53beb3f
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 149 deletions.
29 changes: 26 additions & 3 deletions src/main/java/org/casbin/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,37 @@

package org.casbin;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;

import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
@Slf4j
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
public static void main(String[] args) throws UnknownHostException {
ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
Environment env = application.getEnvironment();
String ip = InetAddress.getLocalHost().getHostAddress();
String port = env.getProperty("server.port");
String path = env.getProperty("server.servlet.context-path");
if (StringUtils.isEmpty(path)) {
path = "";
}
log.info("\n----------------------------------------------------------\n\t" +
"Application is running! Access URLs:\n\t" +
"Local access website: \t\thttp://localhost:" + port + path + "\n\t" +
"External access website: \thttp://" + ip + ":" + port + path + "\n\t" +
"----------------------------------------------------------");
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
log.info("Current project progress number:" + jvmName.split("@")[0]);
}

}

26 changes: 6 additions & 20 deletions src/main/java/org/casbin/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,29 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.casbin.service.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class LoginController {

@Autowired
private AuthenticationService authenticationService;

@RequestMapping(value = {"/"}, method = RequestMethod.GET)
public String index() {
return "main/login";
}

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestParam String username, @RequestParam String password, HttpSession session, HttpServletRequest request, RedirectAttributes redirectAttributes) {
boolean isAuthenticated = authenticationService.authenticate(username, password);

if (isAuthenticated) {
session.invalidate();
session = request.getSession(true);
session.setAttribute("username", username);
return "redirect:/menu";
} else {
redirectAttributes.addAttribute("error", true);
return "redirect:/login";
}
public String login(@RequestParam String username, HttpSession session, HttpServletRequest request) {
session.invalidate();
session = request.getSession(true);
session.setAttribute("username", username);
return "redirect:/menu";
}

@RequestMapping(value = {"/denied"}, method = RequestMethod.GET)
public String denied() {
return "main/denied";
}
}

}
29 changes: 0 additions & 29 deletions src/main/java/org/casbin/service/AuthenticationService.java

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,4 @@ spring:
max-file-size: 2048MB

server:
port: 8080
servlet:
context-path: /casbin
port: 8080
12 changes: 12 additions & 0 deletions src/main/resources/templates/AdminMenu/AdminMenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<head>
<meta charset="UTF-8">
<title>AdminMenu</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/AdminMenu/AdminSubMenu_allow.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<head>
<meta charset="UTF-8">
<title>AdminSubMenu_allow</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/AdminMenu/AdminSubMenu_deny.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<head>
<meta charset="UTF-8">
<title>AdminSubMenu_deny</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
Expand Down
17 changes: 14 additions & 3 deletions src/main/resources/templates/OtherMenu/OtherMenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SystemMenu</title>
<title>OtherMenu</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
OtherMenu
</div>

</body>
</html>
</html>
12 changes: 12 additions & 0 deletions src/main/resources/templates/UserMenu/UserMenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<head>
<meta charset="UTF-8">
<title>UserMenu</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/UserMenu/UserSubMenu_allow.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<head>
<meta charset="UTF-8">
<title>UserSubMenu_allow</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/UserMenu/UserSubMenu_deny.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<head>
<meta charset="UTF-8">
<title>UserSubMenu_deny</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/UserMenu/UserSubSubMenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
<head>
<meta charset="UTF-8">
<title>UserSubSubMenu</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
div {
font-size: 24px;
}
</style>
</head>
<body>
<div>
Expand Down
32 changes: 14 additions & 18 deletions src/main/resources/templates/main/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>login</title>
<title>Login</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<div class="panel panel-primary" style="width: 500px; margin: 5% auto;">
<div class="panel-heading">login</div>
<div class="panel-body">
<form action="login" method="post" class="form-horizontal">
<div class="input-group input-sm" style="margin-bottom: 10px">
<label class="input-group-addon"><i class="glyphicon glyphicon-user"></i></label>
<input type="text" class="form-control" name="username" placeholder="username">
</div>
<div class="input-group input-sm" style="margin-bottom: 10px">
<label class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></label>
<input type="password" class="form-control" name="password" placeholder="password">
</div>
<div class="form-actions">
<input type="submit" class="btn btn-block btn-primary btn-default" value="sign in">
</div>
<body class="flex h-screen bg-gray-200">
<div class="m-auto w-full max-w-xs">
<div class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
<div class="mb-4">
<h1 class="block text-gray-700 text-sm font-bold mb-2">Login as:</h1>
</div>
<form action="login" method="post">
<input type="hidden" name="password" value="dummy">
<button type="submit" name="username" value="root" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline mb-3 w-full">Root</button>
<button type="submit" name="username" value="admin" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline mb-3 w-full">Admin</button>
<button type="submit" name="username" value="user" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline w-full">User</button>
</form>
</div>
</div>
</body>
</html>
</html>
Loading

0 comments on commit 53beb3f

Please sign in to comment.