Commit 123ce171d2b8ca97d9f4011a33ce4e5e8d1cc339

Authored by panlinlin
1 parent a56d8c70

使用数据库用户表代替配置文件

src/main/java/com/genersoft/iot/vmp/service/IUserService.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service;
  2 +
  3 +import com.genersoft.iot.vmp.storager.dao.dto.User;
  4 +
  5 +public interface IUserService {
  6 +
  7 + User getUser(String username, String password);
  8 +
  9 + boolean changePassword(int id, String password);
  10 +
  11 +
  12 +}
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.impl;
  2 +
  3 +import com.genersoft.iot.vmp.service.IUserService;
  4 +import com.genersoft.iot.vmp.storager.dao.UserMapper;
  5 +import com.genersoft.iot.vmp.storager.dao.dto.User;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +@Service
  10 +public class UserServiceImpl implements IUserService {
  11 +
  12 + @Autowired
  13 + private UserMapper userMapper;
  14 +
  15 +
  16 + @Override
  17 + public User getUser(String username, String password) {
  18 + return userMapper.select(username, password);
  19 + }
  20 +
  21 + @Override
  22 + public boolean changePassword(int id, String password) {
  23 + User user = userMapper.selectById(id);
  24 + user.setPassword(password);
  25 + return userMapper.update(user) > 0;
  26 + }
  27 +}
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java 0 → 100644
  1 +package com.genersoft.iot.vmp.storager.dao;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.GbStream;
  4 +import com.genersoft.iot.vmp.storager.dao.dto.User;
  5 +import org.apache.ibatis.annotations.*;
  6 +import org.springframework.stereotype.Repository;
  7 +
  8 +@Mapper
  9 +@Repository
  10 +public interface UserMapper {
  11 +
  12 + @Insert("INSERT INTO user (username, password, roleId, create_time) VALUES" +
  13 + "('${username}', '${password}', '${roleId}', datetime('now','localtime'))")
  14 + int add(User user);
  15 +
  16 + @Update("UPDATE user " +
  17 + "SET username=#{username}," +
  18 + "password=#{password}," +
  19 + "roleId=#{roleId}" +
  20 + "WHERE id=#{id}")
  21 + int update(User user);
  22 +
  23 + @Delete("DELETE FROM user WHERE app=#{app} AND id=#{id}")
  24 + int delete(User user);
  25 +
  26 + @Select("select * FROM user WHERE username= #{username} AND password=#{password}")
  27 + User select(String username, String password);
  28 +
  29 + @Select("select * FROM user WHERE id= #{id}")
  30 + User selectById(int id);
  31 +}
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java 0 → 100644
  1 +package com.genersoft.iot.vmp.storager.dao.dto;
  2 +
  3 +public class User {
  4 +
  5 + private int id;
  6 + private String username;
  7 + private String password;
  8 + private String createTime;
  9 + private int roleId;
  10 +
  11 + public int getId() {
  12 + return id;
  13 + }
  14 +
  15 + public void setId(int id) {
  16 + this.id = id;
  17 + }
  18 +
  19 + public String getUsername() {
  20 + return username;
  21 + }
  22 +
  23 + public void setUsername(String username) {
  24 + this.username = username;
  25 + }
  26 +
  27 + public String getPassword() {
  28 + return password;
  29 + }
  30 +
  31 + public void setPassword(String password) {
  32 + this.password = password;
  33 + }
  34 +
  35 + public String getCreateTime() {
  36 + return createTime;
  37 + }
  38 +
  39 + public void setCreateTime(String createTime) {
  40 + this.createTime = createTime;
  41 + }
  42 +
  43 + public int getRoleId() {
  44 + return roleId;
  45 + }
  46 +
  47 + public void setRoleId(int roleId) {
  48 + this.roleId = roleId;
  49 + }
  50 +}
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
1 package com.genersoft.iot.vmp.vmanager.user; 1 package com.genersoft.iot.vmp.vmanager.user;
2 2
  3 +import com.genersoft.iot.vmp.service.IUserService;
  4 +import com.genersoft.iot.vmp.storager.dao.dto.User;
3 import io.swagger.annotations.Api; 5 import io.swagger.annotations.Api;
4 import io.swagger.annotations.ApiImplicitParam; 6 import io.swagger.annotations.ApiImplicitParam;
5 import io.swagger.annotations.ApiImplicitParams; 7 import io.swagger.annotations.ApiImplicitParams;
6 import io.swagger.annotations.ApiOperation; 8 import io.swagger.annotations.ApiOperation;
  9 +import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.beans.factory.annotation.Value; 10 import org.springframework.beans.factory.annotation.Value;
8 import org.springframework.util.StringUtils; 11 import org.springframework.util.StringUtils;
9 import org.springframework.web.bind.annotation.CrossOrigin; 12 import org.springframework.web.bind.annotation.CrossOrigin;
@@ -17,11 +20,9 @@ import org.springframework.web.bind.annotation.RestController; @@ -17,11 +20,9 @@ import org.springframework.web.bind.annotation.RestController;
17 @RequestMapping("/api/user") 20 @RequestMapping("/api/user")
18 public class UserController { 21 public class UserController {
19 22
20 - @Value("${auth.username}")  
21 - private String usernameConfig; 23 + @Autowired
  24 + private IUserService userService;
22 25
23 - @Value("${auth.password}")  
24 - private String passwordConfig;  
25 26
26 @ApiOperation("登录") 27 @ApiOperation("登录")
27 @ApiImplicitParams({ 28 @ApiImplicitParams({
@@ -30,8 +31,8 @@ public class UserController { @@ -30,8 +31,8 @@ public class UserController {
30 }) 31 })
31 @GetMapping("/login") 32 @GetMapping("/login")
32 public String login(String username, String password){ 33 public String login(String username, String password){
33 - if (!StringUtils.isEmpty(username) && username.equals(usernameConfig)  
34 - && !StringUtils.isEmpty(password) && password.equals(passwordConfig)) { 34 + User user = userService.getUser(username, password);
  35 + if (user != null) {
35 return "success"; 36 return "success";
36 }else { 37 }else {
37 return "fail"; 38 return "fail";
src/main/java/com/genersoft/iot/vmp/web/AuthController.java
1 package com.genersoft.iot.vmp.web; 1 package com.genersoft.iot.vmp.web;
2 2
  3 +import com.genersoft.iot.vmp.service.IUserService;
  4 +import com.genersoft.iot.vmp.storager.dao.dto.User;
  5 +import org.springframework.beans.factory.annotation.Autowired;
3 import org.springframework.beans.factory.annotation.Value; 6 import org.springframework.beans.factory.annotation.Value;
4 import org.springframework.util.StringUtils; 7 import org.springframework.util.StringUtils;
5 import org.springframework.web.bind.annotation.*; 8 import org.springframework.web.bind.annotation.*;
@@ -9,16 +12,13 @@ import org.springframework.web.bind.annotation.*; @@ -9,16 +12,13 @@ import org.springframework.web.bind.annotation.*;
9 @RequestMapping(value = "/auth") 12 @RequestMapping(value = "/auth")
10 public class AuthController { 13 public class AuthController {
11 14
12 - @Value("${auth.username}")  
13 - private String username;  
14 -  
15 - @Value("${auth.password}")  
16 - private String password; 15 + @Autowired
  16 + private IUserService userService;
17 17
18 @RequestMapping("/login") 18 @RequestMapping("/login")
19 public String devices(String name, String passwd){ 19 public String devices(String name, String passwd){
20 - if (!StringUtils.isEmpty(name) && name.equals(username)  
21 - && !StringUtils.isEmpty(passwd) && passwd.equals(password)) { 20 + User user = userService.getUser(name, passwd);
  21 + if (user != null) {
22 return "success"; 22 return "success";
23 }else { 23 }else {
24 return "fail"; 24 return "fail";
src/main/resources/application-dev.yml
@@ -48,13 +48,6 @@ sip: @@ -48,13 +48,6 @@ sip:
48 # [可选] 默认设备认证密码,后续扩展使用设备单独密码 48 # [可选] 默认设备认证密码,后续扩展使用设备单独密码
49 password: admin123 49 password: admin123
50 50
51 -# 登陆的用户名密码  
52 -auth:  
53 - # [可选] 用户名  
54 - username: admin  
55 - # [可选] 密码, 默认为admin  
56 - password: 21232f297a57a5a743894a0e4a801fc3  
57 -  
58 #zlm服务器配置 51 #zlm服务器配置
59 media: 52 media:
60 # [必须修改] zlm服务器的内网IP 53 # [必须修改] zlm服务器的内网IP
src/main/resources/wvp.sqlite
No preview for this file type
web_src/src/components/dialog/easyPlayer.vue
@@ -42,6 +42,9 @@ export default { @@ -42,6 +42,9 @@ export default {
42 console.log(message) 42 console.log(message)
43 } 43 }
44 }, 44 },
  45 + destroyed() {
  46 + this.easyPlayer.destroy();
  47 + },
45 } 48 }
46 </script> 49 </script>
47 50