修改数据结构
This commit is contained in:
parent
3917956ccb
commit
06620dd5d2
@ -1,7 +1,7 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>io.renren</groupId>
|
<groupId>io.renren</groupId>
|
||||||
<artifactId>security</artifactId>
|
<artifactId>java-admin-template</artifactId>
|
||||||
<version>5.4.0</version>
|
<version>5.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
package io.modules.security.controller;
|
package io.modules.security.controller;
|
||||||
|
|
||||||
import io.common.exception.ErrorCode;
|
|
||||||
import io.common.exception.RenException;
|
import io.common.exception.RenException;
|
||||||
import io.common.utils.IpUtils;
|
import io.common.utils.IpUtils;
|
||||||
import io.common.utils.Result;
|
import io.common.utils.Result;
|
||||||
@ -33,14 +30,12 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@Tag(name = "登录管理")
|
@Tag(name = "登录管理")
|
||||||
@ -56,7 +51,7 @@ public class LoginController {
|
|||||||
@Parameter(in = ParameterIn.QUERY, ref = "string", name = "uuid", required = true)
|
@Parameter(in = ParameterIn.QUERY, ref = "string", name = "uuid", required = true)
|
||||||
public void captcha(HttpServletResponse response, String uuid) throws IOException {
|
public void captcha(HttpServletResponse response, String uuid) throws IOException {
|
||||||
//uuid不能为空
|
//uuid不能为空
|
||||||
AssertUtils.isBlank(uuid, "UUID不能为空!");
|
AssertUtils.isBlank(uuid, "UUID不能为空~");
|
||||||
//生成验证码
|
//生成验证码
|
||||||
captchaService.create(response, uuid);
|
captchaService.create(response, uuid);
|
||||||
}
|
}
|
||||||
@ -68,7 +63,7 @@ public class LoginController {
|
|||||||
//验证码是否正确
|
//验证码是否正确
|
||||||
boolean flag = captchaService.validate(login.getUuid(), login.getCaptcha());
|
boolean flag = captchaService.validate(login.getUuid(), login.getCaptcha());
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
return new Result().error("验证码不正确!");
|
return new Result().error("验证码不正确~");
|
||||||
}
|
}
|
||||||
//用户信息
|
//用户信息
|
||||||
SysUserDTO user = sysUserService.getByUsername(login.getUsername());
|
SysUserDTO user = sysUserService.getByUsername(login.getUsername());
|
||||||
@ -82,7 +77,7 @@ public class LoginController {
|
|||||||
log.setStatus(LoginStatusEnum.FAIL.value());
|
log.setStatus(LoginStatusEnum.FAIL.value());
|
||||||
log.setCreatorName(login.getUsername());
|
log.setCreatorName(login.getUsername());
|
||||||
sysLogLoginService.save(log);
|
sysLogLoginService.save(log);
|
||||||
throw new RenException("用户不存在");
|
throw new RenException("用户不存在~");
|
||||||
}
|
}
|
||||||
//密码错误
|
//密码错误
|
||||||
if (!PasswordUtils.matches(login.getPassword(), user.getPassword())) {
|
if (!PasswordUtils.matches(login.getPassword(), user.getPassword())) {
|
||||||
@ -90,7 +85,7 @@ public class LoginController {
|
|||||||
log.setCreator(user.getId());
|
log.setCreator(user.getId());
|
||||||
log.setCreatorName(user.getUsername());
|
log.setCreatorName(user.getUsername());
|
||||||
sysLogLoginService.save(log);
|
sysLogLoginService.save(log);
|
||||||
throw new RenException("密码错误!");
|
throw new RenException("密码错误~");
|
||||||
}
|
}
|
||||||
//账号停用
|
//账号停用
|
||||||
if (user.getStatus() == UserStatusEnum.DISABLE.value()) {
|
if (user.getStatus() == UserStatusEnum.DISABLE.value()) {
|
||||||
@ -98,7 +93,7 @@ public class LoginController {
|
|||||||
log.setCreator(user.getId());
|
log.setCreator(user.getId());
|
||||||
log.setCreatorName(user.getUsername());
|
log.setCreatorName(user.getUsername());
|
||||||
sysLogLoginService.save(log);
|
sysLogLoginService.save(log);
|
||||||
throw new RenException("账号停用");
|
throw new RenException("账号停用~");
|
||||||
}
|
}
|
||||||
//登录成功
|
//登录成功
|
||||||
log.setStatus(LoginStatusEnum.SUCCESS.value());
|
log.setStatus(LoginStatusEnum.SUCCESS.value());
|
||||||
@ -112,10 +107,8 @@ public class LoginController {
|
|||||||
@Operation(summary = "退出")
|
@Operation(summary = "退出")
|
||||||
public Result logout(HttpServletRequest request) {
|
public Result logout(HttpServletRequest request) {
|
||||||
UserDetail user = SecurityUser.getUser();
|
UserDetail user = SecurityUser.getUser();
|
||||||
|
|
||||||
//退出
|
//退出
|
||||||
sysUserTokenService.logout(user.getId());
|
sysUserTokenService.logout(user.getId());
|
||||||
|
|
||||||
//用户信息
|
//用户信息
|
||||||
SysLogLoginEntity log = new SysLogLoginEntity();
|
SysLogLoginEntity log = new SysLogLoginEntity();
|
||||||
log.setOperation(LoginOperationEnum.LOGOUT.value());
|
log.setOperation(LoginOperationEnum.LOGOUT.value());
|
||||||
@ -127,8 +120,6 @@ public class LoginController {
|
|||||||
log.setCreatorName(user.getUsername());
|
log.setCreatorName(user.getUsername());
|
||||||
log.setCreateDate(new Date());
|
log.setCreateDate(new Date());
|
||||||
sysLogLoginService.save(log);
|
sysLogLoginService.save(log);
|
||||||
|
|
||||||
return new Result();
|
return new Result();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class LoginDTO implements Serializable {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Schema(title = "用户名", required = true)
|
@Schema(title = "用户名", required = true)
|
||||||
@NotBlank(message="{sysuser.username.require}")
|
@NotBlank(message="用户名不能为空~")
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@Schema(title = "密码")
|
@Schema(title = "密码")
|
||||||
|
@ -23,7 +23,6 @@ import java.io.IOException;
|
|||||||
/**
|
/**
|
||||||
* oauth2过滤器
|
* oauth2过滤器
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class Oauth2Filter extends AuthenticatingFilter {
|
public class Oauth2Filter extends AuthenticatingFilter {
|
||||||
|
|
||||||
@ -31,11 +30,9 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||||||
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
|
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
|
||||||
//获取请求token
|
//获取请求token
|
||||||
String token = getRequestToken((HttpServletRequest) request);
|
String token = getRequestToken((HttpServletRequest) request);
|
||||||
|
|
||||||
if (StrUtil.isBlank(token)) {
|
if (StrUtil.isBlank(token)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Oauth2Token(token);
|
return new Oauth2Token(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,11 +54,8 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||||||
httpResponse.setContentType("application/json;charset=utf-8");
|
httpResponse.setContentType("application/json;charset=utf-8");
|
||||||
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
httpResponse.setHeader("Access-Control-Allow-Credentials", "true");
|
||||||
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
|
httpResponse.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
|
||||||
|
|
||||||
String json = JsonUtils.toJsonString(new Result().error("未授权访问!"));
|
String json = JsonUtils.toJsonString(new Result().error("未授权访问!"));
|
||||||
|
|
||||||
httpResponse.getWriter().print(json);
|
httpResponse.getWriter().print(json);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,12 +88,10 @@ public class Oauth2Filter extends AuthenticatingFilter {
|
|||||||
private String getRequestToken(HttpServletRequest httpRequest) {
|
private String getRequestToken(HttpServletRequest httpRequest) {
|
||||||
//从header中获取token
|
//从header中获取token
|
||||||
String token = httpRequest.getHeader(Constant.TOKEN_HEADER);
|
String token = httpRequest.getHeader(Constant.TOKEN_HEADER);
|
||||||
|
|
||||||
//如果header中不存在token,则从参数中获取token
|
//如果header中不存在token,则从参数中获取token
|
||||||
if (StrUtil.isBlank(token)) {
|
if (StrUtil.isBlank(token)) {
|
||||||
token = httpRequest.getParameter(Constant.TOKEN_HEADER);
|
token = httpRequest.getParameter(Constant.TOKEN_HEADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import org.apache.shiro.authc.AuthenticationToken;
|
|||||||
/**
|
/**
|
||||||
* token
|
* token
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class Oauth2Token implements AuthenticationToken {
|
public class Oauth2Token implements AuthenticationToken {
|
||||||
private String token;
|
private String token;
|
||||||
|
@ -10,7 +10,6 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* 生成token
|
* 生成token
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public class TokenGenerator {
|
public class TokenGenerator {
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ spring:
|
|||||||
druid:
|
druid:
|
||||||
#MySQL
|
#MySQL
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/wenhua?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://localhost:3306/admin-template?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: 123456
|
||||||
initial-size: 10
|
initial-size: 10
|
||||||
|
@ -5,9 +5,9 @@ server:
|
|||||||
threads:
|
threads:
|
||||||
max: 1000
|
max: 1000
|
||||||
min-spare: 30
|
min-spare: 30
|
||||||
port: 8080
|
port: 18080
|
||||||
servlet:
|
servlet:
|
||||||
context-path: /admin
|
context-path: /
|
||||||
session:
|
session:
|
||||||
cookie:
|
cookie:
|
||||||
http-only: true
|
http-only: true
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>io.renren</groupId>
|
<groupId>io.renren</groupId>
|
||||||
<artifactId>security</artifactId>
|
<artifactId>java-admin-template</artifactId>
|
||||||
<version>5.4.0</version>
|
<version>5.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>io.renren</groupId>
|
<groupId>io.renren</groupId>
|
||||||
<artifactId>security</artifactId>
|
<artifactId>java-admin-template</artifactId>
|
||||||
<version>5.4.0</version>
|
<version>5.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -34,10 +34,13 @@ public class UserController {
|
|||||||
@PostMapping("register")
|
@PostMapping("register")
|
||||||
@Operation(summary = "注册")
|
@Operation(summary = "注册")
|
||||||
public Result register(@RequestBody RegisterDTO dto) {
|
public Result register(@RequestBody RegisterDTO dto) {
|
||||||
|
if (userService.getByUsername(dto.getUsername()) != null) {
|
||||||
|
return new Result().error("用户名已经存在~");
|
||||||
|
}
|
||||||
//表单校验
|
//表单校验
|
||||||
ValidatorUtils.validateEntity(dto);
|
ValidatorUtils.validateEntity(dto);
|
||||||
UserEntity user = new UserEntity();
|
UserEntity user = new UserEntity();
|
||||||
user.setMobile(dto.getMobile());
|
user.setUsername(dto.getUsername());
|
||||||
user.setNickName(dto.getNickName());
|
user.setNickName(dto.getNickName());
|
||||||
user.setPassword(DigestUtil.sha256Hex(dto.getPassword()));
|
user.setPassword(DigestUtil.sha256Hex(dto.getPassword()));
|
||||||
user.setCreateDate(new Date());
|
user.setCreateDate(new Date());
|
||||||
@ -56,14 +59,14 @@ public class UserController {
|
|||||||
return new Result().ok(map);
|
return new Result().ok(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("updateInfo")
|
@PutMapping("update")
|
||||||
@Operation(summary = "修改信息")
|
@Operation(summary = "修改信息")
|
||||||
public Result update(@RequestBody RegisterDTO dto) {
|
public Result update(@RequestBody RegisterDTO dto) {
|
||||||
//表单校验
|
//表单校验
|
||||||
ValidatorUtils.validateEntity(dto);
|
ValidatorUtils.validateEntity(dto);
|
||||||
UserEntity user = new UserEntity();
|
UserEntity user = new UserEntity();
|
||||||
user.setId(dto.getId());
|
user.setId(dto.getId());
|
||||||
user.setMobile(dto.getMobile());
|
user.setUsername(dto.getUsername());
|
||||||
user.setNickName(dto.getNickName());
|
user.setNickName(dto.getNickName());
|
||||||
user.setIntroduce(dto.getIntroduce());
|
user.setIntroduce(dto.getIntroduce());
|
||||||
user.setPassword(DigestUtil.sha256Hex(dto.getPassword()));
|
user.setPassword(DigestUtil.sha256Hex(dto.getPassword()));
|
||||||
@ -93,11 +96,4 @@ public class UserController {
|
|||||||
public Result<Long> userInfo(@Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
public Result<Long> userInfo(@Parameter(hidden = true) @RequestAttribute("userId") Long userId) {
|
||||||
return new Result<Long>().ok(userId);
|
return new Result<Long>().ok(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("notToken")
|
|
||||||
@Operation(summary = "忽略Token验证测试")
|
|
||||||
public Result<String> notToken() {
|
|
||||||
return new Result<String>().ok("无需token也能访问。。。");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserDao extends BaseDao<UserEntity> {
|
public interface UserDao extends BaseDao<UserEntity> {
|
||||||
UserEntity getUserByMobile(String mobile);
|
UserEntity getUserByUsername(String username);
|
||||||
|
|
||||||
UserEntity getUserByUserId(Long userId);
|
UserEntity getUserByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
@ -3,31 +3,20 @@ package io.dto;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
|
|
||||||
package io.dto;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录表单
|
* 登录表单
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Schema(title = "登录表单")
|
@Schema(title = "登录表单")
|
||||||
public class LoginDTO {
|
public class LoginDTO {
|
||||||
@Schema(title = "手机号")
|
@Schema(title = "用户名")
|
||||||
@NotBlank(message="手机号不能为空")
|
@NotBlank(message="用户名不能为空~")
|
||||||
private String mobile;
|
private String username;
|
||||||
|
|
||||||
@Schema(title = "密码")
|
@Schema(title = "密码")
|
||||||
@NotBlank(message="密码不能为空")
|
@NotBlank(message="密码不能为空~")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,21 +10,19 @@ import lombok.Data;
|
|||||||
/**
|
/**
|
||||||
* 注册表单
|
* 注册表单
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Schema(title = "注册表单")
|
@Schema(title = "注册表单")
|
||||||
public class RegisterDTO {
|
public class RegisterDTO {
|
||||||
private Long id;
|
private Long id;
|
||||||
@Schema(title = "手机号")
|
@Schema(title = "用户名")
|
||||||
@NotBlank(message="手机号不能为空")
|
@NotBlank(message="用户名不能为空")
|
||||||
private String mobile;
|
private String username;
|
||||||
|
|
||||||
@Schema(title = "密码")
|
@Schema(title = "密码")
|
||||||
@NotBlank(message="密码不能为空")
|
@NotBlank(message="密码不能为空")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
@Schema(title = "昵称")
|
@Schema(title = "昵称")
|
||||||
private String nickName;
|
private String nickName;
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ public class UserEntity implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String introduce;
|
private String introduce;
|
||||||
/**
|
/**
|
||||||
* 手机号
|
* 用户名
|
||||||
*/
|
*/
|
||||||
private String mobile;
|
private String username;
|
||||||
/**
|
/**
|
||||||
* 密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
|
@ -37,28 +37,22 @@ public class AuthorizationInterceptor implements HandlerInterceptor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//从header中获取token
|
//从header中获取token
|
||||||
String token = request.getHeader("token");
|
String token = request.getHeader("Authorization");
|
||||||
|
|
||||||
|
|
||||||
//如果header中不存在token,则从参数中获取token
|
//如果header中不存在token,则从参数中获取token
|
||||||
if (StrUtil.isBlank(token)) {
|
if (StrUtil.isBlank(token)) {
|
||||||
token = request.getParameter("token");
|
token = request.getParameter("Authorization");
|
||||||
}
|
}
|
||||||
|
|
||||||
//token为空
|
//token为空
|
||||||
if (StrUtil.isBlank(token)) {
|
if (StrUtil.isBlank(token)) {
|
||||||
throw new RenException("token为空!");
|
throw new RenException("登录失效~");
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询token信息
|
//查询token信息
|
||||||
TokenEntity tokenEntity = tokenService.getByToken(token);
|
TokenEntity tokenEntity = tokenService.getByToken(token);
|
||||||
if (tokenEntity == null || tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()) {
|
if (tokenEntity == null || tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()) {
|
||||||
throw new RenException(401,"登录失效!");
|
throw new RenException(401,"登录失效~");
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置userId到request里,后续根据userId,获取用户信息
|
//设置userId到request里,后续根据userId,获取用户信息
|
||||||
request.setAttribute(USER_KEY, tokenEntity.getUserId());
|
request.setAttribute(USER_KEY, tokenEntity.getUserId());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* 用户
|
* 用户
|
||||||
*
|
*
|
||||||
|
|
||||||
*/
|
*/
|
||||||
public interface UserService extends BaseService<UserEntity> {
|
public interface UserService extends BaseService<UserEntity> {
|
||||||
|
|
||||||
UserEntity getByMobile(String mobile);
|
UserEntity getByUsername(String username);
|
||||||
|
|
||||||
UserEntity getUserByUserId(Long userId);
|
UserEntity getUserByUserId(Long userId);
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
|
|||||||
private final TokenService tokenService;
|
private final TokenService tokenService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserEntity getByMobile(String mobile) {
|
public UserEntity getByUsername(String username){
|
||||||
return baseDao.getUserByMobile(mobile);
|
return baseDao.getUserByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,21 +33,18 @@ public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> login(LoginDTO dto) {
|
public Map<String, Object> login(LoginDTO dto) {
|
||||||
UserEntity user = getByMobile(dto.getMobile());
|
UserEntity user = getByUsername(dto.getUsername());
|
||||||
AssertUtils.isNull(user, ErrorCode.ACCOUNT_PASSWORD_ERROR);
|
AssertUtils.isNull(user, "用户名不存在~");
|
||||||
|
|
||||||
//密码错误
|
//密码错误
|
||||||
if (!user.getPassword().equals(DigestUtil.sha256Hex(dto.getPassword()))) {
|
if (!user.getPassword().equals(DigestUtil.sha256Hex(dto.getPassword()))) {
|
||||||
throw new RenException("密码错误!");
|
throw new RenException("密码输入错误~");
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取登录token
|
//获取登录token
|
||||||
TokenEntity tokenEntity = tokenService.createToken(user.getId());
|
TokenEntity tokenEntity = tokenService.createToken(user.getId());
|
||||||
|
|
||||||
Map<String, Object> map = new HashMap<>(2);
|
Map<String, Object> map = new HashMap<>(2);
|
||||||
map.put("token", tokenEntity.getToken());
|
map.put("token", tokenEntity.getToken());
|
||||||
map.put("expire", tokenEntity.getExpireDate().getTime() - System.currentTimeMillis());
|
map.put("expire", tokenEntity.getExpireDate().getTime() - System.currentTimeMillis());
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
druid:
|
druid:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/wenhua?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
url: jdbc:mysql://localhost:3306/admin-template?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: 123456
|
||||||
initial-size: 10
|
initial-size: 10
|
||||||
|
@ -5,9 +5,9 @@ server:
|
|||||||
threads:
|
threads:
|
||||||
max: 1000
|
max: 1000
|
||||||
min-spare: 30
|
min-spare: 30
|
||||||
port: 8081
|
port: 18081
|
||||||
servlet:
|
servlet:
|
||||||
context-path: /front
|
context-path: /
|
||||||
session:
|
session:
|
||||||
cookie:
|
cookie:
|
||||||
http-only: true
|
http-only: true
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
<mapper namespace="io.dao.UserDao">
|
<mapper namespace="io.dao.UserDao">
|
||||||
|
|
||||||
<select id="getUserByMobile" resultType="io.entity.UserEntity">
|
<select id="getUserByUsername" resultType="io.entity.UserEntity">
|
||||||
select * from tb_user where mobile = #{value}
|
select * from tb_user where username = #{value}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getUserByUserId" resultType="io.entity.UserEntity">
|
<select id="getUserByUserId" resultType="io.entity.UserEntity">
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>io.renren</groupId>
|
<groupId>io.renren</groupId>
|
||||||
<artifactId>security</artifactId>
|
<artifactId>java-admin-template</artifactId>
|
||||||
<version>5.4.0</version>
|
<version>5.4.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
26
pom.xml
26
pom.xml
@ -2,7 +2,7 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>io.renren</groupId>
|
<groupId>io.renren</groupId>
|
||||||
<artifactId>security</artifactId>
|
<artifactId>java-admin-template</artifactId>
|
||||||
<version>5.4.0</version>
|
<version>5.4.0</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
@ -73,29 +73,7 @@
|
|||||||
<groupId>com.mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-j</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- oracle驱动 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.oracle</groupId>
|
|
||||||
<artifactId>ojdbc6</artifactId>
|
|
||||||
<version>${oracle.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- sqlserver驱动 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.microsoft.sqlserver</groupId>
|
|
||||||
<artifactId>sqljdbc4</artifactId>
|
|
||||||
<version>${sqlserver.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- postgresql驱动 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.postgresql</groupId>
|
|
||||||
<artifactId>postgresql</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- 达梦驱动 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.dameng</groupId>
|
|
||||||
<artifactId>DmJdbcDriver18</artifactId>
|
|
||||||
<version>${dameng.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>druid-spring-boot-3-starter</artifactId>
|
<artifactId>druid-spring-boot-3-starter</artifactId>
|
||||||
|
Loading…
Reference in New Issue
Block a user