From 123ce171d2b8ca97d9f4011a33ce4e5e8d1cc339 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Tue, 13 Apr 2021 15:08:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A1=A8=E4=BB=A3=E6=9B=BF=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/service/IUserService.java | 12 +++++ .../iot/vmp/service/impl/UserServiceImpl.java | 27 ++++++++++ .../iot/vmp/storager/dao/UserMapper.java | 31 +++++++++++ .../iot/vmp/storager/dao/dto/User.java | 50 ++++++++++++++++++ .../iot/vmp/vmanager/user/UserController.java | 13 ++--- .../genersoft/iot/vmp/web/AuthController.java | 14 ++--- src/main/resources/application-dev.yml | 7 --- src/main/resources/wvp.sqlite | Bin 98304 -> 98304 bytes web_src/src/components/dialog/easyPlayer.vue | 3 ++ 9 files changed, 137 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/service/IUserService.java create mode 100644 src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java create mode 100644 src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java create mode 100644 src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java diff --git a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java new file mode 100644 index 00000000..868118b2 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java @@ -0,0 +1,12 @@ +package com.genersoft.iot.vmp.service; + +import com.genersoft.iot.vmp.storager.dao.dto.User; + +public interface IUserService { + + User getUser(String username, String password); + + boolean changePassword(int id, String password); + + +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..0a67a018 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java @@ -0,0 +1,27 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.genersoft.iot.vmp.service.IUserService; +import com.genersoft.iot.vmp.storager.dao.UserMapper; +import com.genersoft.iot.vmp.storager.dao.dto.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl implements IUserService { + + @Autowired + private UserMapper userMapper; + + + @Override + public User getUser(String username, String password) { + return userMapper.select(username, password); + } + + @Override + public boolean changePassword(int id, String password) { + User user = userMapper.selectById(id); + user.setPassword(password); + return userMapper.update(user) > 0; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java new file mode 100644 index 00000000..4608a29e --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java @@ -0,0 +1,31 @@ +package com.genersoft.iot.vmp.storager.dao; + +import com.genersoft.iot.vmp.gb28181.bean.GbStream; +import com.genersoft.iot.vmp.storager.dao.dto.User; +import org.apache.ibatis.annotations.*; +import org.springframework.stereotype.Repository; + +@Mapper +@Repository +public interface UserMapper { + + @Insert("INSERT INTO user (username, password, roleId, create_time) VALUES" + + "('${username}', '${password}', '${roleId}', datetime('now','localtime'))") + int add(User user); + + @Update("UPDATE user " + + "SET username=#{username}," + + "password=#{password}," + + "roleId=#{roleId}" + + "WHERE id=#{id}") + int update(User user); + + @Delete("DELETE FROM user WHERE app=#{app} AND id=#{id}") + int delete(User user); + + @Select("select * FROM user WHERE username= #{username} AND password=#{password}") + User select(String username, String password); + + @Select("select * FROM user WHERE id= #{id}") + User selectById(int id); +} diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java new file mode 100644 index 00000000..697df043 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java @@ -0,0 +1,50 @@ +package com.genersoft.iot.vmp.storager.dao.dto; + +public class User { + + private int id; + private String username; + private String password; + private String createTime; + private int roleId; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public int getRoleId() { + return roleId; + } + + public void setRoleId(int roleId) { + this.roleId = roleId; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java index 306a1589..cf781c07 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java @@ -1,9 +1,12 @@ package com.genersoft.iot.vmp.vmanager.user; +import com.genersoft.iot.vmp.service.IUserService; +import com.genersoft.iot.vmp.storager.dao.dto.User; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.CrossOrigin; @@ -17,11 +20,9 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/api/user") public class UserController { - @Value("${auth.username}") - private String usernameConfig; + @Autowired + private IUserService userService; - @Value("${auth.password}") - private String passwordConfig; @ApiOperation("登录") @ApiImplicitParams({ @@ -30,8 +31,8 @@ public class UserController { }) @GetMapping("/login") public String login(String username, String password){ - if (!StringUtils.isEmpty(username) && username.equals(usernameConfig) - && !StringUtils.isEmpty(password) && password.equals(passwordConfig)) { + User user = userService.getUser(username, password); + if (user != null) { return "success"; }else { return "fail"; diff --git a/src/main/java/com/genersoft/iot/vmp/web/AuthController.java b/src/main/java/com/genersoft/iot/vmp/web/AuthController.java index 702387cb..1a02c1ee 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/AuthController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/AuthController.java @@ -1,5 +1,8 @@ package com.genersoft.iot.vmp.web; +import com.genersoft.iot.vmp.service.IUserService; +import com.genersoft.iot.vmp.storager.dao.dto.User; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; @@ -9,16 +12,13 @@ import org.springframework.web.bind.annotation.*; @RequestMapping(value = "/auth") public class AuthController { - @Value("${auth.username}") - private String username; - - @Value("${auth.password}") - private String password; + @Autowired + private IUserService userService; @RequestMapping("/login") public String devices(String name, String passwd){ - if (!StringUtils.isEmpty(name) && name.equals(username) - && !StringUtils.isEmpty(passwd) && passwd.equals(password)) { + User user = userService.getUser(name, passwd); + if (user != null) { return "success"; }else { return "fail"; diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index d4abf207..fad47f9c 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -48,13 +48,6 @@ sip: # [可选] 默认设备认证密码,后续扩展使用设备单独密码 password: admin123 -# 登陆的用户名密码 -auth: - # [可选] 用户名 - username: admin - # [可选] 密码, 默认为admin - password: 21232f297a57a5a743894a0e4a801fc3 - #zlm服务器配置 media: # [必须修改] zlm服务器的内网IP diff --git a/src/main/resources/wvp.sqlite b/src/main/resources/wvp.sqlite index 2e73cdb642a67e86b9a1c01c2634c86f72746aaa..eb4e08bb2b99d6ee259fa6064e0c8ccdac7253cc 100644 GIT binary patch delta 455 zcmZo@U~6b#n;JapnkSk9QKGqtv4y2cqCu)jqJ@EBTC%Z`fsvuEfr+l6v4WwA6%d)4FLF>=tWY4Z zNI_sx08VmS0warn91pu01OFyIUp`?TEAB6xr+Dvk{pC8!{*QM)yBV9u#zuCw>6&GX z@+@4N7`IJqyuie@X|jU6M17-6Ge5hys3>Doc1dDVPAbSFAk66;^z;jHb$1O?2nh1@bqtDB@OF( zO;zFyag7L3@bd@aP#+(VR6$~Kae00b&?IpTxuX1>RL_*@4fTwovP#KCsfi`2@g1yr6;DRsw5HVcjwgg5N0Xc5=e+>Ma z_