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 2e73cdb6..eb4e08bb 100644 Binary files a/src/main/resources/wvp.sqlite and b/src/main/resources/wvp.sqlite differ diff --git a/web_src/src/components/dialog/easyPlayer.vue b/web_src/src/components/dialog/easyPlayer.vue index f6a7b478..71d858e5 100644 --- a/web_src/src/components/dialog/easyPlayer.vue +++ b/web_src/src/components/dialog/easyPlayer.vue @@ -42,6 +42,9 @@ export default { console.log(message) } }, + destroyed() { + this.easyPlayer.destroy(); + }, }