From 58d5eec5cada9bb867dd69ecde884e5451758caf Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Thu, 8 Jun 2023 15:17:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Spring=20Security=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=BF=9B=E8=A1=8C=E9=AA=8C=E8=AF=81=20*=E8=BF=98?= =?UTF-8?q?=E6=B2=A1=E4=BF=AE=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chenx221 --- .../WEB-INF/classes/applicationContext.xml | 14 +------ .../chenx221/controller/UserController.class | Bin 4206 -> 3782 bytes .../classes/cyou/chenx221/pojo/User.class | Bin 1310 -> 1495 bytes .../WEB-INF/views/login.jsp | 4 +- .../project2_war_exploded/WEB-INF/web.xml | 10 ++++- .../chenx221/controller/UserController.java | 35 ++++++++++-------- .../main/java/cyou/chenx221/pojo/User.java | 12 +++++- .../src/main/resources/applicationContext.xml | 14 +------ project2/web/WEB-INF/views/login.jsp | 4 +- project2/web/WEB-INF/web.xml | 10 ++++- 10 files changed, 53 insertions(+), 50 deletions(-) diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/applicationContext.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/applicationContext.xml index e411ed4..1af98d1 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/applicationContext.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/applicationContext.xml @@ -45,19 +45,7 @@ - - - - - - - - - - - - - + \ No newline at end of file diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/UserController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/UserController.class index 15d763082f650ae0dd2f27a483c229ac26409407..63cbc8d59fcb98159f0510bf7c07ec92826af2c4 100644 GIT binary patch delta 1489 zcmZ8hTT@e46#jNjPWH*k;bH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_Pp4g^sdBzMdi~NIx7j=W{Gh*5Dttw74u^ zFrQ}-72~CgP~yOSWo*atI&BQi~CY%W@OXnGg>R15lSTkZ9 zS(J`3xV)d@(WtA(@H%7!@FtF<2R3YG3Qpi8F{+8#aEg$Kt;~vELK3;Ij8n#DwD2k4 z2#xWL&=}nay+QuXaXW)}0=#TRQJi@RzLjBI?(djJgiC!w;M1& diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/User.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/pojo/User.class index c324c8a39fa2761caabf81a7de62e5c884a90605..a938941a2419c3e3feb3195bc4f93d995d166fc7 100644 GIT binary patch literal 1495 zcmZ`&+iuf96dXIZrgfVpaZ*YzG(g)Vy+kd72MT>bLaG!2qELxPH?>knsa-h=^txIRBLBh%pjY=tbsWg8kSn$yg{RNX}ez!4-XpGUdL;E?AgACl<#%z zo`ynm%y`=O9k+cX918|=Sk$097aEEY%!%8#+qSPj1p`G!8-49r_l6TR`<;E9a)E)$^NB7W6RAuydP1pZTH^? z{>^GF;x4=a5xo(jRGkLY&NMua?hmgu4V~VR;_Ya0s2Yz<(d!9ADBUtT)MF#)RL;v$ z#^JF@&5=NQCINFrcx1)1ccYx;Y`mI1^#*>+e(gxoS*h8VR-?iu>3m#Cj_fhNbZMiS z**P`y@o=64?IF!^iK{1^HO{H}FK9m$>>fvXpfV;2U*?w)fN&oxTxnRv8b={$a1IE5 zBJ-UaI)p&@frZ%Obvy`*kBJtcbbaRrnMwHqeHIl%IY5Q-!Y+3a;S@GPt}Zc2a+z`y z;hV4T-XLG!yMZ}oF0%qC5m`o-7g(TM(U42lgZhz*sgjg?m?}$gYRZ3rgi@}A%Acs5 z;8|{{oEPPYXh9LLa9pM68b#NY;6_k363i(X5zHwWodOT>D3pmNJwKUrMG;Q6=`l9L z;#*12kMjr`y~$Lz6vK4V@|q;+t=N|5Cymr%jcmuaJU?k>vr#&B{sW+H*3JL` literal 1310 zcmaJ<+iuf96r9bqNu8#-meN97TF9jZi}FUHFGxt0DnKek;?YU1)KO|zPQvA{Kq5lo zfe+xL5OdZ}VnTu}?Rt0T%*@W&U%!9+1n?ZSEMkbKkuZ=%N@2ZceXz{F<#x^2?VjBk zDx{t{t}{GUh}Rpf3|5dyBWqw4hQdbYvo|t3SGN1<`1rAT3l|a z<__(y?Vkw4nt?pl6;?*Xy4JO=P>et?hQ8x=HL_@+q>(q)VDQoNNt$@!U9up5?zr}= z(RJJQ-&*ayrtmsezh(K3ti#R3@X8q|Y@RQ1dZO^O9?_oIjBJH={@rP`6l&4p|00uJ zdw53wm3kvWHPKT@4ubP)lyPz_QmZ78aD%|gf6;`>1d(M1szkX$%!KOAG*PLUt+E&1 z$nV%M9mzB!T#uxS*kj{jd^B;6Y(D>D(nUS9N1QX@Es)|^=IRM&#W~sh4)s;TDjem( zfm8{?tNb$p5H@g&Dp2*L*leVa8Ww1!yQirVMge<5!|F z;cf=?Avc+{aWPfa*2PI#9vCkr%C|%1_f(GaEI(1siE>1=sEG?4ixe$UvaAJngR-e$ zUdxDJUdzNNu!ZeV#^f9%^bP4R1jQf;Nq`{5qIB-yZdiOuwD?cyWM+8;`EKzx+nS*o zpr)2mVFn62*bTX&Mso8;b`~1h!@WgDa`Q&^Y2;vu5qUk5!2Uubg?S^jg+>k*8;LY4 UNaT=4j+Pja7a&IN>mEG#1Kx_o
-
+

用户登录

@@ -115,8 +115,6 @@
- <%-- 显示错误信息 --%> -

还没有账号? 注册一个

diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/web.xml b/project2/out/artifacts/project2_war_exploded/WEB-INF/web.xml index 34748a5..9d7d1ee 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/web.xml +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/web.xml @@ -28,9 +28,17 @@ true - encodingFilter /* + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + springSecurityFilterChain + /* + + \ No newline at end of file diff --git a/project2/src/main/java/cyou/chenx221/controller/UserController.java b/project2/src/main/java/cyou/chenx221/controller/UserController.java index a4102e6..0f0bee6 100644 --- a/project2/src/main/java/cyou/chenx221/controller/UserController.java +++ b/project2/src/main/java/cyou/chenx221/controller/UserController.java @@ -18,26 +18,31 @@ public class UserController { @Autowired private UserMapper userMapper; - @RequestMapping(path = "/signin", method = {RequestMethod.GET, RequestMethod.POST}) //登录 - public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model) throws NoSuchAlgorithmException { - User user = userMapper.getUserByUsername(username); - Password pw = new Password(password); -// System.out.println("username:" + username + " try to login with password: " + password + " encrypted-password:"+pw.getEncryptedPassword()); - if (user != null && user.getPassword().equals(pw.getEncryptedPassword())) { - model.addAttribute("message", "登陆成功"); - return "redirect:/dashboard"; // 重定向到 dashboard 页面 - } else { - model.addAttribute("errorMessage", "用户名或密码不正确,请重新输入。"); - return "login"; - } + // @RequestMapping(path = "/signin", method = {RequestMethod.GET, RequestMethod.POST}) //登录 +// public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model) throws NoSuchAlgorithmException { +// User user = userMapper.getUserByUsername(username); +// Password pw = new Password(password); +//// System.out.println("username:" + username + " try to login with password: " + password + " encrypted-password:"+pw.getEncryptedPassword()); +// if (user != null && user.getPassword().equals(pw.getEncryptedPassword())) { +// model.addAttribute("message", "登陆成功"); +// return "redirect:/dashboard"; // 重定向到 dashboard 页面 +// } else { +// model.addAttribute("errorMessage", "用户名或密码不正确,请重新输入。"); +// return "login"; +// } +// } + @RequestMapping(path = "/login", method = {RequestMethod.GET, RequestMethod.POST}) //登录 + public String login() { + return "login"; } + @RequestMapping(path = "/signup", method = {RequestMethod.GET, RequestMethod.POST}) //注册 public String register(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("re-password") String repassword, Model model) throws NoSuchAlgorithmException { //debug start // System.out.println("username:" + username); //debug end - model.addAttribute("comeFrom","reg"); + model.addAttribute("comeFrom", "reg"); //检查两次输入的密码是否相同 if (!password.equals(repassword)) { model.addAttribute("errorMessage", "两次输入的密码不一致,请重新输入。"); @@ -72,11 +77,11 @@ public class UserController { return "login"; } // start to register - Password pw=new Password(password); + Password pw = new Password(password); System.out.println("username:" + username + " password:" + pw.getEncryptedPassword()); //debug user = new User(username, pw.getEncryptedPassword()); userMapper.insertUser(user); - model.addAttribute("comeFrom","log"); + model.addAttribute("comeFrom", "log"); model.addAttribute("successMessage", "注册成功"); return "login"; } diff --git a/project2/src/main/java/cyou/chenx221/pojo/User.java b/project2/src/main/java/cyou/chenx221/pojo/User.java index 0e84ede..5eb6e25 100644 --- a/project2/src/main/java/cyou/chenx221/pojo/User.java +++ b/project2/src/main/java/cyou/chenx221/pojo/User.java @@ -1,13 +1,23 @@ package cyou.chenx221.pojo; +import java.util.List; + public class User { private Integer id; private String username; private String password; - + private String roles; public User() { } + public String getRoles() { + return roles; + } + + public void setRoles(String roles) { + this.roles = roles; + } + public User(Integer id, String username, String password) { this.id = id; this.username = username; diff --git a/project2/src/main/resources/applicationContext.xml b/project2/src/main/resources/applicationContext.xml index e411ed4..1af98d1 100644 --- a/project2/src/main/resources/applicationContext.xml +++ b/project2/src/main/resources/applicationContext.xml @@ -45,19 +45,7 @@ - - - - - - - - - - - - - + \ 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 8dd3c4c..6a94812 100644 --- a/project2/web/WEB-INF/views/login.jsp +++ b/project2/web/WEB-INF/views/login.jsp @@ -90,7 +90,7 @@
- +

用户登录

@@ -115,8 +115,6 @@
- <%-- 显示错误信息 --%> -

还没有账号? 注册一个

diff --git a/project2/web/WEB-INF/web.xml b/project2/web/WEB-INF/web.xml index 34748a5..9d7d1ee 100644 --- a/project2/web/WEB-INF/web.xml +++ b/project2/web/WEB-INF/web.xml @@ -28,9 +28,17 @@ true - encodingFilter /* + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + springSecurityFilterChain + /* + + \ No newline at end of file