From d3aea486afe067b76a89b7cd20a6c5fbcab655f0 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sat, 17 Jun 2023 11:39:21 +0800 Subject: [PATCH] dashboard for student/teacher Signed-off-by: Chenx221 --- .../chenx221/controller/ViewController.class | Bin 1414 -> 1842 bytes .../CustomAuthenticationSuccessHandler.class | Bin 1282 -> 2351 bytes .../WEB-INF/classes/spring-security.xml | 2 + .../WEB-INF/views/dashboard_s.jsp | 113 +++++++++++++++++ .../WEB-INF/views/dashboard_t.jsp | 116 ++++++++++++++++++ .../WEB-INF/views/login.jsp | 28 +++-- .../chenx221/controller/ViewController.java | 19 +++ .../CustomAuthenticationSuccessHandler.java | 18 +++ .../src/main/resources/spring-security.xml | 2 + project2/web/WEB-INF/views/dashboard_s.jsp | 113 +++++++++++++++++ project2/web/WEB-INF/views/dashboard_t.jsp | 116 ++++++++++++++++++ project2/web/WEB-INF/views/login.jsp | 28 +++-- 12 files changed, 537 insertions(+), 18 deletions(-) create mode 100644 project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_s.jsp create mode 100644 project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_t.jsp create mode 100644 project2/web/WEB-INF/views/dashboard_s.jsp create mode 100644 project2/web/WEB-INF/views/dashboard_t.jsp diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/ViewController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/ViewController.class index b8a281fe45c3beaa97b44a14ca5575299341d592..eed6f7527eac2c543b7413be5b28e47976ab7554 100644 GIT binary patch literal 1842 zcmb_cTT|0O6#lj;H1xtHpil+mqS$f^)C*`qMey=a#G#1e@ZhBB(gxC`CL54{r7tq- zjE_F}n;gfJwp>a(49t+sWcTcz^X+%e`8I$4{rCl75zoU2KnfukMGIOPI(M`^O*J*E zpswY1xGor47Yxe~PZ*>`a#M!P5Zg2OzN@;Pu5;Iw5oQQim$o&-3?a%esvp>%su#KS z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_!E`h3z>$_Q=b~Jq_Lyn4zS|ZDg13bE{%IotVX28s66N4sJ4> z4n2Avz1x}xJltTGI` zPBeiU<;L(sJwIDkQ~LPgi8zzawvJ=e6ezcg0#ibqW8(>_OYzpaI_Wxd(W;n$gwMV%& zdjgk_rY@<_WV26=wd6KzXe5)62RYL^ZuRUUsqVno!xl`nb^?o|jFXmR)8(+;4Ak4& z(Pl&4BTD&RwMqNhOC{!0C$QxO_A+EoS6*@R(HgHd!rHmCYl>>n@;nU%hBIL~+pe*) zaqvZh^+FeKOpSvxRMC0Ym!`O52PrhxIsvZ*H!%$7d>V5Vv1NNUW!r+|xGJ1^lx&kP z_mX<6a20Vx4ZA|kfP$39C1j~|gI^3Rn6k94)6SqLqi6f%Gq9)O=M7qe&p;18qE)XS zz{kkZjs?X}N=TTkA`XqP{ZtJa6-HMLJuytz&`*^RACA{>j$Yb_+iSSQ@C4hz+Ze;| zNX>N&choRVLN|WFn@^xm^}bs}I)q8I}X{;|R>p zkm*1lx@aW!V~|?%5Ef}HuHr25a1Ni-_%d+;7DnLF2>TWn@f{78?{OJF(kKet&JYQ+ zSVkWA=#89g5D>g=Vk;zNAD`gUkk@^DhHbRbZIZNqL3VseG68jUrrqB+~Uw78Z@r6(lQlzvH89)$58 zUlHW@6dj^?H2x+`WZ{s)3S>k}f(xinw$SJt{D%sH8`}2JG^E3={aZ+vo`m}n_rw`6 O6pbx-#Mruud-ww(IUdvi diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml index 28a1779..09233b1 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/spring-security.xml @@ -21,6 +21,8 @@ + + diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_s.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_s.jsp new file mode 100644 index 0000000..6e7d9ff --- /dev/null +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_s.jsp @@ -0,0 +1,113 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + + + + + 面板 + + + + + + + + + +
+ +
+ + + + +
+
+
+
+
+ + +
+ + + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_t.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_t.jsp new file mode 100644 index 0000000..88f6134 --- /dev/null +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/dashboard_t.jsp @@ -0,0 +1,116 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + + + + + 面板 + + + + + + + + + +
+ +
+ + + + +
+
+
+
+
+ + +
+ + + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/login.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/login.jsp index 4898356..707a07b 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/login.jsp +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/login.jsp @@ -21,7 +21,7 @@ <% - if(new UsernameHelper().getCurrentUsername()!=null){ + if (new UsernameHelper().getCurrentUsername() != null) { //redirect /dashboard //note: 登陆了的就别乱访问了 response.sendRedirect("dashboard"); @@ -101,11 +101,13 @@

用户登录

- +
- +
@@ -118,12 +120,12 @@
-

还没有账号? 注册一个

+

还没有账号? 注册一个

@@ -133,15 +135,18 @@

用户注册

- +
- +
- +
@@ -234,7 +239,12 @@ $('#exampleModal2').modal('show'); }); - + function showNote() { + alert("功能尚未实现,请联系管理员重置密码"); + } + function showReg(){ + document.getElementById("tab-register").click(); + } diff --git a/project2/src/main/java/cyou/chenx221/controller/ViewController.java b/project2/src/main/java/cyou/chenx221/controller/ViewController.java index b1d25e6..b4b0b70 100644 --- a/project2/src/main/java/cyou/chenx221/controller/ViewController.java +++ b/project2/src/main/java/cyou/chenx221/controller/ViewController.java @@ -28,4 +28,23 @@ public class ViewController { return "dashboard"; // 返回 dashboard 视图名 } + @RequestMapping(path = "/dashboard-t", method = {RequestMethod.GET, RequestMethod.POST}) + public String showDashboardT(Model model) { + String username = new UsernameHelper().getCurrentUsername(); + if (username != null) { + model.addAttribute("username", username); + } +// model.addAttribute("errorMessage","null"); + return "dashboard_t"; // 返回 dashboard 视图名 + } + + @RequestMapping(path = "/dashboard-s", method = {RequestMethod.GET, RequestMethod.POST}) + public String showDashboardS(Model model) { + String username = new UsernameHelper().getCurrentUsername(); + if (username != null) { + model.addAttribute("username", username); + } +// model.addAttribute("errorMessage","null"); + return "dashboard_s"; // 返回 dashboard 视图名 + } } diff --git a/project2/src/main/java/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.java b/project2/src/main/java/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.java index c7f06db..766e212 100644 --- a/project2/src/main/java/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.java +++ b/project2/src/main/java/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.java @@ -1,6 +1,7 @@ package cyou.chenx221.handler; import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; import org.springframework.stereotype.Component; @@ -8,13 +9,30 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.Collection; @Component public class CustomAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { + // 移除 errorMessage 属性 request.getSession().removeAttribute("errorMessage"); + + Collection authorities = authentication.getAuthorities(); + for (GrantedAuthority authority : authorities) { + if (authority.getAuthority().equals("ROLE_admin")) { + response.sendRedirect("/dashboard"); + return; + } else if (authority.getAuthority().equals("ROLE_teacher")) { + response.sendRedirect("/dashboard-t"); + return; + } else if (authority.getAuthority().equals("ROLE_student")) { + response.sendRedirect("/dashboard-s"); + return; + } + } + // 如果没有匹配的角色,或者无法确定跳转的目标页面,则默认跳转到 "/dashboard" super.onAuthenticationSuccess(request, response, authentication); } } \ No newline at end of file diff --git a/project2/src/main/resources/spring-security.xml b/project2/src/main/resources/spring-security.xml index 28a1779..09233b1 100644 --- a/project2/src/main/resources/spring-security.xml +++ b/project2/src/main/resources/spring-security.xml @@ -21,6 +21,8 @@ + + diff --git a/project2/web/WEB-INF/views/dashboard_s.jsp b/project2/web/WEB-INF/views/dashboard_s.jsp new file mode 100644 index 0000000..6e7d9ff --- /dev/null +++ b/project2/web/WEB-INF/views/dashboard_s.jsp @@ -0,0 +1,113 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + + + + + 面板 + + + + + + + + + +
+ +
+ + + + +
+
+
+
+
+ + +
+ + + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/dashboard_t.jsp b/project2/web/WEB-INF/views/dashboard_t.jsp new file mode 100644 index 0000000..88f6134 --- /dev/null +++ b/project2/web/WEB-INF/views/dashboard_t.jsp @@ -0,0 +1,116 @@ +<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> + + + + + + + + 面板 + + + + + + + + + +
+ +
+ + + + +
+
+
+
+
+ + +
+ + + +
+
+ + + + + + + + + \ No newline at end of file diff --git a/project2/web/WEB-INF/views/login.jsp b/project2/web/WEB-INF/views/login.jsp index 4898356..707a07b 100644 --- a/project2/web/WEB-INF/views/login.jsp +++ b/project2/web/WEB-INF/views/login.jsp @@ -21,7 +21,7 @@ <% - if(new UsernameHelper().getCurrentUsername()!=null){ + if (new UsernameHelper().getCurrentUsername() != null) { //redirect /dashboard //note: 登陆了的就别乱访问了 response.sendRedirect("dashboard"); @@ -101,11 +101,13 @@

用户登录

- +
- +
@@ -118,12 +120,12 @@
-

还没有账号? 注册一个

+

还没有账号? 注册一个

@@ -133,15 +135,18 @@

用户注册

- +
- +
- +
@@ -234,7 +239,12 @@ $('#exampleModal2').modal('show'); }); - + function showNote() { + alert("功能尚未实现,请联系管理员重置密码"); + } + function showReg(){ + document.getElementById("tab-register").click(); + }