From f3eadc64776c395b2018faf9e8fb88634323b88b Mon Sep 17 00:00:00 2001 From: flykhan Date: Wed, 22 Feb 2023 16:08:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B3=A8=E5=86=8C=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=89=8D=E7=AB=AF=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/account/RegisterServiceImpl.java | 26 +++--- web/src/components/NavBar.vue | 3 +- web/src/store/user.js | 41 +++++++++- .../user/account/UserAccountLoginView.vue | 40 ++++++---- .../user/account/UserAccountRegisterView.vue | 80 ++++++++++++++++++- 5 files changed, 157 insertions(+), 33 deletions(-) diff --git a/backend/src/main/java/com/kob/backend/service/impl/user/account/RegisterServiceImpl.java b/backend/src/main/java/com/kob/backend/service/impl/user/account/RegisterServiceImpl.java index 9998cab..e1d7507 100644 --- a/backend/src/main/java/com/kob/backend/service/impl/user/account/RegisterServiceImpl.java +++ b/backend/src/main/java/com/kob/backend/service/impl/user/account/RegisterServiceImpl.java @@ -44,15 +44,8 @@ public class RegisterServiceImpl implements RegisterService { map.put("error_message", "用户名过长"); return map; } - if (password.length() > 100 || confirmedPassword.length() > 100) { - map.put("error_message", "密码过长"); - return map; - } -// 密码验证是 String 类型比较,应该用 equals() 方法 - if (!confirmedPassword.equals(password)) { - map.put("error_message", "两次密码输入不一致"); - return map; - } + + /* 查询数据库里是否有用户名 this.username 已存在的用户,并将结果存入 users 中, @@ -65,6 +58,17 @@ public class RegisterServiceImpl implements RegisterService { map.put("error_message", "用户名已存在"); return map; } + // 密码验证是 String 类型比较,应该用 equals() 方法 + else if (!confirmedPassword.equals(password)) { + map.put("error_message", "两次密码输入不一致"); + return map; + } else if (password.length() < 6) { + map.put("error_message", "密码不能少于6位"); + return map; + } else if (password.length() > 100) { + map.put("error_message", "密码过长"); + return map; + } // 异常情况判断结束,开始将合法用户注册信息注入数据库 // 对密码进行加密 @@ -72,10 +76,10 @@ public class RegisterServiceImpl implements RegisterService { // 默认头像 String photo = "https://cdn.acwing.com/media/user/profile/photo/253652_lg_e3d8435b66.jpg"; // id 是数据库自增,这里生成新用户只需要将 id 参数写为 null 即可 - User user = new User(null,username,encodedPassword,photo); + User user = new User(null, username, encodedPassword, photo); userMapper.insert(user); - map.put("error_message","成功注册"); + map.put("error_message", "successRegister"); return map; } } diff --git a/web/src/components/NavBar.vue b/web/src/components/NavBar.vue index eead2bf..fc40a02 100644 --- a/web/src/components/NavBar.vue +++ b/web/src/components/NavBar.vue @@ -58,7 +58,8 @@ -