Browse Source

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

pull/84/head
panlinlin 4 years ago
parent
commit
123ce171d2
  1. 12
      src/main/java/com/genersoft/iot/vmp/service/IUserService.java
  2. 27
      src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
  3. 31
      src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
  4. 50
      src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java
  5. 13
      src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
  6. 14
      src/main/java/com/genersoft/iot/vmp/web/AuthController.java
  7. 7
      src/main/resources/application-dev.yml
  8. BIN
      src/main/resources/wvp.sqlite
  9. 3
      web_src/src/components/dialog/easyPlayer.vue

12
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);
}

27
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;
}
}

31
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);
}

50
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;
}
}

13
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";

14
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";

7
src/main/resources/application-dev.yml

@ -48,13 +48,6 @@ sip:
# [可选] 默认设备认证密码,后续扩展使用设备单独密码
password: admin123
# 登陆的用户名密码
auth:
# [可选] 用户名
username: admin
# [可选] 密码, 默认为admin
password: 21232f297a57a5a743894a0e4a801fc3
#zlm服务器配置
media:
# [必须修改] zlm服务器的内网IP

BIN
src/main/resources/wvp.sqlite

Binary file not shown.

3
web_src/src/components/dialog/easyPlayer.vue

@ -42,6 +42,9 @@ export default {
console.log(message)
}
},
destroyed() {
this.easyPlayer.destroy();
},
}
</script>

Loading…
Cancel
Save