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 b8a281f..eed6f75 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/ViewController.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/ViewController.class differ diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.class index bb67392..cf698d0 100644 Binary files a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.class and b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/handler/CustomAuthenticationSuccessHandler.class differ 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(); + }