panlinlin
2021-04-13 123ce171d2b8ca97d9f4011a33ce4e5e8d1cc339
使用数据库用户表代替配置文件
5个文件已修改
4个文件已添加
157 ■■■■ 已修改文件
src/main/java/com/genersoft/iot/vmp/service/IUserService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/web/AuthController.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-dev.yml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/wvp.sqlite 补丁 | 查看 | 原始文档 | blame | 历史
web_src/src/components/dialog/easyPlayer.vue 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/genersoft/iot/vmp/service/IUserService.java
New file
@@ -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);
}
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
New file
@@ -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;
    }
}
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
New file
@@ -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);
}
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java
New file
@@ -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;
    }
}
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 @@
@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 @@
    })
    @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";
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 @@
@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";
src/main/resources/application-dev.yml
@@ -48,13 +48,6 @@
    # [可选] 默认设备认证密码,后续扩展使用设备单独密码
    password: admin123
# 登陆的用户名密码
auth:
    # [可选] 用户名
    username: admin
    # [可选] 密码, 默认为admin
    password: 21232f297a57a5a743894a0e4a801fc3
#zlm服务器配置
media:
    # [必须修改] zlm服务器的内网IP
src/main/resources/wvp.sqlite
Binary files differ
web_src/src/components/dialog/easyPlayer.vue
@@ -42,6 +42,9 @@
            console.log(message)
        }
    },
    destroyed() {
      this.easyPlayer.destroy();
    },
}
</script>