main
parent
e9b9b61016
commit
fce07eaa2d
|
|
@ -164,39 +164,30 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
|
|||
.eq("id", Integer.parseInt(id.toString()))
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
AppUser appUser = appUserMapper.selectOne(
|
||||
new QueryWrapper<AppUser>()
|
||||
.select("id,username")
|
||||
.eq("id", Integer.parseInt(id.toString()))
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
// 删除校验
|
||||
if (StringUtils.isNull(adminUser) && StringUtils.isNull(appUser)) {
|
||||
if (StringUtils.isNull(adminUser)) {
|
||||
Integer errCode = ErrorEnum.TOKEN_INVALID.getCode();
|
||||
String errMsg = ErrorEnum.TOKEN_INVALID.getMsg();
|
||||
throw new LoginException(errCode, errMsg);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotNull(adminUser)) {
|
||||
// 禁用校验
|
||||
if (adminUser.getIsDisable().equals(1)) {
|
||||
Integer errCode = ErrorEnum.LOGIN_DISABLE_ERROR.getCode();
|
||||
String errMsg = ErrorEnum.LOGIN_DISABLE_ERROR.getMsg();
|
||||
throw new LoginException(errCode, errMsg);
|
||||
}
|
||||
// 禁用校验
|
||||
if (adminUser.getIsDisable().equals(1)) {
|
||||
Integer errCode = ErrorEnum.LOGIN_DISABLE_ERROR.getCode();
|
||||
String errMsg = ErrorEnum.LOGIN_DISABLE_ERROR.getMsg();
|
||||
throw new LoginException(errCode, errMsg);
|
||||
}
|
||||
|
||||
// 写入线程
|
||||
LikeAdminThreadLocal.put("adminId", id);
|
||||
LikeAdminThreadLocal.put("username", adminUser.getUsername());
|
||||
LikeAdminThreadLocal.put("roleIds", adminUser.getRoleIds());
|
||||
LikeAdminThreadLocal.put("deptIds", adminUser.getDeptIds());
|
||||
LikeAdminThreadLocal.put("postIds", adminUser.getPostIds());
|
||||
// 写入线程
|
||||
LikeAdminThreadLocal.put("adminId", id);
|
||||
LikeAdminThreadLocal.put("username", adminUser.getUsername());
|
||||
LikeAdminThreadLocal.put("roleIds", adminUser.getRoleIds());
|
||||
LikeAdminThreadLocal.put("deptIds", adminUser.getDeptIds());
|
||||
LikeAdminThreadLocal.put("postIds", adminUser.getPostIds());
|
||||
|
||||
// 权限校验
|
||||
if (!adminUser.getId().equals(1)) {
|
||||
this.checkAuth(method, reqUri);
|
||||
}
|
||||
// 权限校验
|
||||
if (!adminUser.getId().equals(1)) {
|
||||
this.checkAuth(method, reqUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,79 +0,0 @@
|
|||
package com.mdd.admin.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.mdd.admin.service.ILoginService;
|
||||
import com.mdd.admin.validate.CodeArg;
|
||||
import com.mdd.admin.validate.commons.IdValidate;
|
||||
import com.mdd.admin.validate.login.LoginPhoneValidate;
|
||||
import com.mdd.admin.validate.login.RegisterValidate;
|
||||
import com.mdd.admin.vo.LoginTokenVo;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.aop.NotPower;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/appLogin")
|
||||
@Api(tags = "app登录")
|
||||
public class AppLoginController {
|
||||
|
||||
@Resource
|
||||
ILoginService iLoginService;
|
||||
|
||||
@NotLogin
|
||||
@PostMapping("/register")
|
||||
@ApiOperation(value="注册账号")
|
||||
public AjaxResult<Object> register(@Validated @RequestBody RegisterValidate registerValidate) {
|
||||
iLoginService.register(registerValidate);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
||||
@NotLogin
|
||||
@PostMapping("/mobileLogin")
|
||||
@ApiOperation(value="手机登录")
|
||||
public AjaxResult<LoginTokenVo> mobileLogin(@Validated @RequestBody LoginPhoneValidate loginPhoneValidate) {
|
||||
String mobile = loginPhoneValidate.getMobile();
|
||||
String code = loginPhoneValidate.getCode();
|
||||
LoginTokenVo vo = iLoginService.mobileLogin(mobile, code);
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
@NotLogin
|
||||
@ApiOperation("获取验证码")
|
||||
@PostMapping("/code")
|
||||
public AjaxResult<String> code(@RequestBody CodeArg arg){
|
||||
return iLoginService.code(arg.getMobile());
|
||||
}
|
||||
|
||||
@NotPower
|
||||
@PostMapping("/logout")
|
||||
@ApiOperation(value="退出登录")
|
||||
public AjaxResult<Object> logout(HttpServletRequest request) {
|
||||
StpUtil.logout();
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/* @NotLogin
|
||||
@PostMapping("/mnpLogin")
|
||||
@ApiOperation(value="微信登录")
|
||||
public AjaxResult<LoginTokenVo> mnpLogin(@Validated @RequestBody LoginCodeValidate loginCodeValidate) {
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
String code = loginCodeValidate.getCode();
|
||||
|
||||
LoginTokenVo vo = iLoginService.mnpLogin(code, terminal);
|
||||
return AjaxResult.success(vo);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package com.mdd.admin.service;
|
||||
|
||||
|
||||
import com.mdd.admin.validate.login.RegisterValidate;
|
||||
import com.mdd.admin.vo.LoginTokenVo;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* 登录服务接口类
|
||||
*/
|
||||
public interface ILoginService {
|
||||
|
||||
/**
|
||||
* 账号注册
|
||||
*
|
||||
* @author fzr
|
||||
*/
|
||||
void register(RegisterValidate registerValidate);
|
||||
|
||||
/**
|
||||
* 手机登录
|
||||
*
|
||||
* @author fzr
|
||||
* @param mobile 手机号
|
||||
* @param code 验证码
|
||||
* @return LoginTokenVo
|
||||
*/
|
||||
LoginTokenVo mobileLogin(String mobile, String code);
|
||||
|
||||
AjaxResult<String> code(String mobile);
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*
|
||||
* @author fzr
|
||||
* @param code 微信code
|
||||
* @param terminal 终端
|
||||
* @return LoginTokenVo
|
||||
*/
|
||||
// LoginTokenVo mnpLogin(String code, Integer terminal);
|
||||
|
||||
}
|
||||
|
|
@ -1,159 +0,0 @@
|
|||
package com.mdd.admin.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.admin.service.ILoginService;
|
||||
import com.mdd.admin.utils.SmsUtil;
|
||||
import com.mdd.admin.validate.login.RegisterValidate;
|
||||
import com.mdd.admin.vo.LoginTokenVo;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.AppUser;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.AppUserMapper;
|
||||
import com.mdd.common.util.RedisUtils;
|
||||
import com.mdd.common.util.ToolUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 登录服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class LoginServiceImpl implements ILoginService {
|
||||
|
||||
@Resource
|
||||
AppUserMapper appUserMapper;
|
||||
|
||||
Integer terminal = 88;
|
||||
|
||||
@Resource
|
||||
private SmsUtil smsUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 注册账号
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public void register(RegisterValidate entity) {
|
||||
AppUser model = appUserMapper.selectOne(new QueryWrapper<AppUser>()
|
||||
.select("id,sn,username")
|
||||
.eq("mobile", entity.getMobile())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.isNull(model, "手机号已存在,换一个吧!");
|
||||
|
||||
String sn = this.__generateSn();
|
||||
|
||||
AppUser user = new AppUser();
|
||||
BeanUtils.copyProperties(entity,user);
|
||||
user.setSn(sn);
|
||||
user.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
user.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
appUserMapper.insert(user);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 手机号登录
|
||||
*
|
||||
* @author fzr
|
||||
* @param mobile 手机号
|
||||
* @param code 验证码
|
||||
* @return LoginTokenVo
|
||||
*/
|
||||
@Override
|
||||
public LoginTokenVo mobileLogin(String mobile, String code) {
|
||||
// 校验验证码
|
||||
Object sceneCode = RedisUtils.get("app_code_" + mobile);
|
||||
if (sceneCode == null || !sceneCode.equals(code)) {
|
||||
throw new OperateException("验证码错误!");
|
||||
}
|
||||
|
||||
// 查询手机号
|
||||
AppUser user = appUserMapper.selectOne(new QueryWrapper<AppUser>()
|
||||
.select("id,username,mobile")
|
||||
.eq("mobile", mobile)
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.notNull(user, "账号不存在!");
|
||||
|
||||
return this.__loginToken(user.getId(), user.getMobile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult code(String mobile) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
stringBuilder.append(random.nextInt(10));
|
||||
}
|
||||
//五分钟
|
||||
RedisUtils.set("app_code_" + mobile, stringBuilder.toString(), 60*5);
|
||||
|
||||
// 发送短信验证码:效验是否登录还是修改密码
|
||||
try {
|
||||
SendSmsResponse sendSmsResponse = smsUtil.sendSms(mobile, stringBuilder.toString());
|
||||
System.out.println("发送短信返回值:" + JSON.toJSONString(sendSmsResponse));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return AjaxResult.success(stringBuilder.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用户编号
|
||||
*
|
||||
* @author fzr
|
||||
* @return Integer
|
||||
*/
|
||||
private String __generateSn() {
|
||||
Integer sn;
|
||||
String no = "jxp_";
|
||||
while (true) {
|
||||
sn = Integer.parseInt(ToolUtils.randomInt(6));
|
||||
no = no + sn;
|
||||
AppUser snModel = appUserMapper.selectOne(new QueryWrapper<AppUser>()
|
||||
.select("id,sn")
|
||||
.eq("sn", no)
|
||||
.last("limit 1"));
|
||||
if (snModel == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return no;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理录令牌
|
||||
*
|
||||
* @author fzr
|
||||
* @param userId 用户ID
|
||||
* @param mobile 用户手机
|
||||
* @return LoginTokenVo
|
||||
*/
|
||||
private LoginTokenVo __loginToken(Integer userId, String mobile) {
|
||||
// 实现账号登录
|
||||
StpUtil.login(userId, String.valueOf(terminal));
|
||||
|
||||
// 返回登录信息
|
||||
LoginTokenVo vo = new LoginTokenVo();
|
||||
vo.setId(userId);
|
||||
vo.setMobile(mobile);
|
||||
vo.setToken(StpUtil.getTokenValue());
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -87,18 +87,4 @@ sa-token:
|
|||
is-share: false # 多人同登账号共用token
|
||||
token-style: random-64 # token生成的风格
|
||||
is-print: false # 打印版本字符画
|
||||
is-log: false # 是否输出操作日志
|
||||
|
||||
config:
|
||||
#短信短信配置
|
||||
aliyun:
|
||||
sms:
|
||||
#ID和Secret是通用的,在控制台可以查看到
|
||||
accessKeyId: LTAI5tM1LeE2pkiS3qEFQkfb
|
||||
accessKeySecret: fEZZyFvWkETS8Clm73f7qmY9ohcTpc
|
||||
#短信签名-可在短信控制台中找到
|
||||
signName: 丙煜
|
||||
#配置超时时间
|
||||
defaultConnectTimeout: 10000
|
||||
defaultReadTimeout: 10000
|
||||
smsCode: SMS_465690552
|
||||
is-log: false # 是否输出操作日志
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
package com.mdd.admin.validate;
|
||||
package com.mdd.common.validator;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author byw
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.mdd.front.aop;
|
||||
|
||||
|
||||
import com.mdd.front.aop.aspect.RequestType;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 日志记录类
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Log {
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
String title() default "";
|
||||
|
||||
/**
|
||||
* 请求类型
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
RequestType requestType() default RequestType.Default;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
package com.mdd.front.aop.aspect;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.mdd.common.entity.system.SystemLogOperate;
|
||||
import com.mdd.common.mapper.system.SystemLogOperateMapper;
|
||||
import com.mdd.common.util.IpUtils;
|
||||
import com.mdd.common.util.RequestUtils;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.aop.Log;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class LogAspect {
|
||||
|
||||
@Resource
|
||||
SystemLogOperateMapper systemLogOperateMapper;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(LogAspect.class);
|
||||
|
||||
/**
|
||||
* 线程本地变量
|
||||
*/
|
||||
private static final ThreadLocal<Long> threadLocal = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 单线程化的线程池
|
||||
*/
|
||||
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
/**
|
||||
* 声明切面点拦截那些类
|
||||
*/
|
||||
@Pointcut("@annotation(com.mdd.front.aop.Log)")
|
||||
private void pointCutMethodController() {}
|
||||
|
||||
/**
|
||||
* 环绕通知前后增强
|
||||
*/
|
||||
@Around(value = "pointCutMethodController()")
|
||||
public Object doAroundService(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
// 开始时间
|
||||
threadLocal.set(System.currentTimeMillis());
|
||||
// 执行方法
|
||||
Object result = joinPoint.proceed();
|
||||
// 保存日志
|
||||
recordLog(joinPoint, null);
|
||||
// 返回结果
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截异常操作
|
||||
*
|
||||
* @param joinPoint 切点
|
||||
* @param e 异常
|
||||
*/
|
||||
@AfterThrowing(value = "@annotation(controllerLog)", throwing = "e")
|
||||
public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) {
|
||||
recordLog(joinPoint, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录日志信息
|
||||
*
|
||||
* @param joinPointObj joinPoint
|
||||
* @param e Exception 错误异常
|
||||
*/
|
||||
private void recordLog(Object joinPointObj, final Exception e) {
|
||||
try {
|
||||
long beginTime = threadLocal.get();
|
||||
long endTime = System.currentTimeMillis();
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes != null) {
|
||||
// 取得请求对象
|
||||
HttpServletRequest request = requestAttributes.getRequest();
|
||||
|
||||
// 获取当前的用户
|
||||
Integer adminId = LikeFrontThreadLocal.getTerminal();
|
||||
|
||||
// 获取日志注解
|
||||
ProceedingJoinPoint joinPoint = (ProceedingJoinPoint) joinPointObj;
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
Method method = signature.getMethod();
|
||||
Log logAnnotation = method.getAnnotation(Log.class);
|
||||
|
||||
// 方法名称
|
||||
String className = joinPoint.getTarget().getClass().getName();
|
||||
String methodName = joinPoint.getSignature().getName();
|
||||
|
||||
// 获取请求参数
|
||||
String queryString = request.getQueryString();
|
||||
Object[] args = joinPoint.getArgs();
|
||||
String params = "";
|
||||
if (args.length > 0) {
|
||||
if("POST".equals(request.getMethod())){
|
||||
if (RequestType.File.equals(logAnnotation.requestType())){
|
||||
//文件类型获取文件名称作为参数
|
||||
StandardMultipartHttpServletRequest standardMultipartHttpServletRequest = (StandardMultipartHttpServletRequest) args[0];
|
||||
//提取文件名
|
||||
params = standardMultipartHttpServletRequest
|
||||
.getMultiFileMap()
|
||||
.values()
|
||||
.stream()
|
||||
.map(m -> m.stream()
|
||||
.map(MultipartFile::getOriginalFilename)
|
||||
.collect(Collectors.joining(",")))
|
||||
.collect(Collectors.joining(","));
|
||||
} else {
|
||||
params = JSON.toJSONString(args);
|
||||
}
|
||||
|
||||
} else if("GET".equals(request.getMethod())){
|
||||
params = queryString;
|
||||
}
|
||||
}
|
||||
|
||||
// 错误信息
|
||||
String error = "";
|
||||
int status = 1;
|
||||
if (e != null) {
|
||||
error = e.getMessage();
|
||||
status = 2; // 1=成功, 2=失败
|
||||
}
|
||||
|
||||
// 数据库日志
|
||||
SystemLogOperate model = new SystemLogOperate();
|
||||
model.setAdminId(adminId);
|
||||
model.setTitle(logAnnotation.title());
|
||||
model.setIp(IpUtils.getIpAddress());
|
||||
model.setType(request.getMethod());
|
||||
model.setMethod(className + "." + methodName + "()");
|
||||
model.setUrl(RequestUtils.route());
|
||||
model.setArgs(params);
|
||||
model.setError(error);
|
||||
model.setStatus(status);
|
||||
model.setStartTime(beginTime / 1000);
|
||||
model.setEndTime(endTime / 1000);
|
||||
model.setTaskTime(endTime - beginTime);
|
||||
model.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
executor.submit(() -> {
|
||||
systemLogOperateMapper.insert(model);
|
||||
});
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("异常信息:{}", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.mdd.front.aop.aspect;
|
||||
|
||||
/**
|
||||
* 请求参数类
|
||||
*/
|
||||
public enum RequestType {
|
||||
/**
|
||||
* 文件类型
|
||||
*/
|
||||
File,
|
||||
/**
|
||||
* 默认数据类型
|
||||
*/
|
||||
Default
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.mdd.admin.config;
|
||||
package com.mdd.front.config;
|
||||
|
||||
import com.mdd.admin.utils.SmsUtil;
|
||||
import com.mdd.front.utils.SmsUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -1,19 +1,20 @@
|
|||
package com.mdd.admin.controller;
|
||||
package com.mdd.front.controller;
|
||||
|
||||
import com.mdd.admin.aop.Log;
|
||||
import com.mdd.admin.service.IAppUserService;
|
||||
import com.mdd.admin.validate.commons.IdValidate;
|
||||
import com.mdd.admin.validate.AppUserCreateValidate;
|
||||
import com.mdd.admin.validate.AppUserUpdateValidate;
|
||||
import com.mdd.admin.validate.AppUserSearchValidate;
|
||||
import com.mdd.admin.validate.commons.PageValidate;
|
||||
import com.mdd.admin.vo.AppUserListedVo;
|
||||
import com.mdd.admin.vo.AppUserDetailVo;
|
||||
import com.mdd.front.aop.Log;
|
||||
import com.mdd.front.service.IAppUserService;
|
||||
import com.mdd.front.validate.AppUserCreateValidate;
|
||||
import com.mdd.front.validate.AppUserSearchValidate;
|
||||
import com.mdd.front.validate.AppUserUpdateValidate;
|
||||
import com.mdd.front.validate.common.IdValidate;
|
||||
import com.mdd.front.validate.common.PageValidate;
|
||||
import com.mdd.front.vo.AppUserDetailVo;
|
||||
import com.mdd.front.vo.AppUserListedVo;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
package com.mdd.front.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.aop.NotPower;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.validator.CodeArg;
|
||||
import com.mdd.front.LikeFrontThreadLocal;
|
||||
import com.mdd.front.service.ILoginService;
|
||||
import com.mdd.front.validate.login.*;
|
||||
|
|
@ -14,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
|
|
@ -31,10 +35,7 @@ public class LoginController {
|
|||
@ApiOperation(value="注册账号")
|
||||
public AjaxResult<Object> register(@Validated @RequestBody RegisterValidate registerValidate) {
|
||||
Integer terminal = LikeFrontThreadLocal.getTerminal();
|
||||
String username = registerValidate.getUsername();
|
||||
String password = registerValidate.getPassword();
|
||||
|
||||
iLoginService.register(username, password, terminal);
|
||||
iLoginService.register(registerValidate, terminal);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
|
|
@ -115,4 +116,19 @@ public class LoginController {
|
|||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
@NotLogin
|
||||
@ApiOperation("获取验证码")
|
||||
@PostMapping("/code")
|
||||
public AjaxResult<String> code(@RequestBody CodeArg arg){
|
||||
return iLoginService.code(arg.getMobile());
|
||||
}
|
||||
|
||||
@NotPower
|
||||
@PostMapping("/logout")
|
||||
@ApiOperation(value="退出登录")
|
||||
public AjaxResult<Object> logout(HttpServletRequest request) {
|
||||
StpUtil.logout();
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
package com.mdd.admin.service;
|
||||
package com.mdd.front.service;
|
||||
|
||||
import com.mdd.admin.validate.commons.PageValidate;
|
||||
import com.mdd.admin.validate.AppUserCreateValidate;
|
||||
import com.mdd.admin.validate.AppUserUpdateValidate;
|
||||
import com.mdd.admin.validate.AppUserSearchValidate;
|
||||
import com.mdd.admin.vo.AppUserListedVo;
|
||||
import com.mdd.admin.vo.AppUserDetailVo;
|
||||
import com.mdd.front.validate.AppUserCreateValidate;
|
||||
import com.mdd.front.validate.AppUserSearchValidate;
|
||||
import com.mdd.front.validate.AppUserUpdateValidate;
|
||||
import com.mdd.front.validate.common.PageValidate;
|
||||
import com.mdd.front.vo.AppUserDetailVo;
|
||||
import com.mdd.front.vo.AppUserListedVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
|
||||
/**
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.mdd.front.service;
|
||||
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.front.validate.login.RegisterValidate;
|
||||
import com.mdd.front.vo.login.LoginTokenVo;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
|
@ -13,11 +15,9 @@ public interface ILoginService {
|
|||
* 账号注册
|
||||
*
|
||||
* @author fzr
|
||||
* @param username 账号
|
||||
* @param password 密码
|
||||
* @param terminal 终端
|
||||
*/
|
||||
void register(String username, String password, Integer terminal);
|
||||
void register(RegisterValidate registerValidate, Integer terminal);
|
||||
|
||||
/**
|
||||
* 账号登录
|
||||
|
|
@ -90,4 +90,7 @@ public interface ILoginService {
|
|||
*/
|
||||
LoginTokenVo scanLogin(String code, String state, Integer terminal, HttpSession session);
|
||||
|
||||
AjaxResult<String> code(String mobile);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,18 @@
|
|||
package com.mdd.admin.service.impl;
|
||||
package com.mdd.front.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.mdd.admin.validate.commons.PageValidate;
|
||||
import com.mdd.admin.service.IAppUserService;
|
||||
import com.mdd.admin.validate.AppUserCreateValidate;
|
||||
import com.mdd.admin.validate.AppUserUpdateValidate;
|
||||
import com.mdd.admin.validate.AppUserSearchValidate;
|
||||
import com.mdd.admin.vo.AppUserListedVo;
|
||||
import com.mdd.admin.vo.AppUserDetailVo;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import com.mdd.front.service.IAppUserService;
|
||||
import com.mdd.front.validate.AppUserCreateValidate;
|
||||
import com.mdd.front.validate.AppUserSearchValidate;
|
||||
import com.mdd.front.validate.AppUserUpdateValidate;
|
||||
import com.mdd.front.validate.common.PageValidate;
|
||||
import com.mdd.front.vo.AppUserDetailVo;
|
||||
import com.mdd.front.vo.AppUserListedVo;
|
||||
import com.mdd.common.core.PageResult;
|
||||
import com.mdd.common.entity.AppUser;
|
||||
import com.mdd.common.mapper.AppUserMapper;
|
||||
import com.mdd.common.util.ListUtils;
|
||||
import com.mdd.common.util.TimeUtils;
|
||||
import com.mdd.common.util.UrlUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
|
@ -23,7 +20,8 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户信息实现类
|
||||
|
|
@ -3,12 +3,17 @@ package com.mdd.front.service.impl;
|
|||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import com.mdd.common.entity.AppUser;
|
||||
import com.mdd.common.entity.user.User;
|
||||
import com.mdd.common.entity.user.UserAuth;
|
||||
import com.mdd.common.enums.NoticeEnum;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.AppUserMapper;
|
||||
import com.mdd.common.mapper.user.UserAuthMapper;
|
||||
import com.mdd.common.mapper.user.UserMapper;
|
||||
import com.mdd.common.plugin.notice.NoticeCheck;
|
||||
|
|
@ -16,6 +21,8 @@ import com.mdd.common.plugin.wechat.WxMnpDriver;
|
|||
import com.mdd.common.util.*;
|
||||
import com.mdd.front.cache.ScanLoginCache;
|
||||
import com.mdd.front.service.ILoginService;
|
||||
import com.mdd.front.utils.SmsUtil;
|
||||
import com.mdd.front.validate.login.RegisterValidate;
|
||||
import com.mdd.front.vo.login.LoginTokenVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
|
|
@ -23,6 +30,7 @@ import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
|
|||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpOAuth2ServiceImpl;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
@ -32,6 +40,7 @@ import java.io.IOException;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 登录服务实现类
|
||||
|
|
@ -46,40 +55,36 @@ public class LoginServiceImpl implements ILoginService {
|
|||
@Resource
|
||||
UserAuthMapper userAuthMapper;
|
||||
|
||||
@Resource
|
||||
AppUserMapper appUserMapper;
|
||||
|
||||
@Resource
|
||||
private SmsUtil smsUtil;
|
||||
|
||||
/**
|
||||
* 注册账号
|
||||
*
|
||||
* @author fzr
|
||||
* @param username 账号
|
||||
* @param password 密码
|
||||
* @param terminal 总端
|
||||
*/
|
||||
@Override
|
||||
public void register(String username, String password, Integer terminal) {
|
||||
User model = userMapper.selectOne(new QueryWrapper<User>()
|
||||
public void register(RegisterValidate registerValidate, Integer terminal) {
|
||||
AppUser model = appUserMapper.selectOne(new QueryWrapper<AppUser>()
|
||||
.select("id,sn,username")
|
||||
.eq("username", username)
|
||||
.eq("mobile", registerValidate.getMobile())
|
||||
.eq("is_delete", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
Assert.isNull(model, "账号已存在,换一个吧!");
|
||||
Assert.isNull(model, "手机号已存在,换一个吧!");
|
||||
|
||||
Integer sn = this.__generateSn();
|
||||
String salt = ToolUtils.randomString(5);
|
||||
String pwd = ToolUtils.makeMd5(password+salt);
|
||||
String sn = this.generateSn();
|
||||
|
||||
User user = new User();
|
||||
AppUser user = new AppUser();
|
||||
BeanUtils.copyProperties(registerValidate,user);
|
||||
user.setSn(sn);
|
||||
user.setNickname("用户"+sn);
|
||||
user.setUsername(username);
|
||||
user.setPassword(pwd);
|
||||
user.setSalt(salt);
|
||||
user.setAvatar("/api/static/default_avatar.png");
|
||||
user.setChannel(terminal);
|
||||
user.setIsNew(1);
|
||||
user.setCreateTime(System.currentTimeMillis() / 1000);
|
||||
user.setUpdateTime(System.currentTimeMillis() / 1000);
|
||||
userMapper.insert(user);
|
||||
appUserMapper.insert(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -442,4 +447,42 @@ public class LoginServiceImpl implements ILoginService {
|
|||
return sn;
|
||||
}
|
||||
|
||||
private String generateSn() {
|
||||
Integer sn;
|
||||
String no = "jxp_";
|
||||
while (true) {
|
||||
sn = Integer.parseInt(ToolUtils.randomInt(6));
|
||||
no = no + sn;
|
||||
AppUser snModel = appUserMapper.selectOne(new QueryWrapper<AppUser>()
|
||||
.select("id,sn")
|
||||
.eq("sn", no)
|
||||
.last("limit 1"));
|
||||
if (snModel == null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return no;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AjaxResult code(String mobile) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
stringBuilder.append(random.nextInt(10));
|
||||
}
|
||||
//五分钟
|
||||
RedisUtils.set("app_code_" + mobile, stringBuilder.toString(), 60*5);
|
||||
|
||||
// 发送短信验证码:效验是否登录还是修改密码
|
||||
try {
|
||||
SendSmsResponse sendSmsResponse = smsUtil.sendSms(mobile, stringBuilder.toString());
|
||||
System.out.println("发送短信返回值:" + JSON.toJSONString(sendSmsResponse));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return AjaxResult.success(stringBuilder.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.mdd.admin.utils;
|
||||
package com.mdd.front.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
|
|
@ -11,8 +11,6 @@ import com.aliyuncs.profile.IClientProfile;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
package com.mdd.admin.validate;
|
||||
package com.mdd.front.validate;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Data
|
||||
@ApiModel("用户信息创建参数")
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package com.mdd.admin.validate;
|
||||
package com.mdd.front.validate;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
package com.mdd.admin.validate;
|
||||
package com.mdd.front.validate;
|
||||
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import javax.validation.constraints.*;
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
|
||||
/**
|
||||
* 用户信息参数
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.mdd.front.validate.common;
|
||||
|
||||
import com.mdd.common.validator.annotation.IDMust;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@ApiModel("ID参数")
|
||||
public class IdValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@IDMust(message = "id参数必传且需大于0")
|
||||
@ApiModelProperty(value = "ID", required = true)
|
||||
private Integer id;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.mdd.front.validate.common;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("IDS参数")
|
||||
public class IdsValidate implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "ids参数缺失")
|
||||
@ApiModelProperty(value = "ID数组", required = true)
|
||||
private List<Integer> ids;
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
|
|||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
|
@ -16,17 +17,23 @@ public class RegisterValidate implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull(message = "username参数缺失")
|
||||
@NotEmpty(message = "账号不能为空")
|
||||
@Length(min = 3, max = 12, message = "账号必须在3~12个字符内")
|
||||
@Pattern(message = "账号应该为3-12位数字、字母组合", regexp="^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{3,12}$")
|
||||
@ApiModelProperty(value = "登录账号", required = true)
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
@ApiModelProperty(value = "用户名", required = true)
|
||||
private String username;
|
||||
|
||||
@NotNull(message = "password参数缺失")
|
||||
@NotEmpty(message = "密码不能为空")
|
||||
@Length(min = 6, max = 12, message = "密码必须在6~12个字符内")
|
||||
@ApiModelProperty(value = "登录密码", required = true)
|
||||
private String password;
|
||||
@NotBlank(message = "头像不能为空")
|
||||
@ApiModelProperty(value = "头像", required = true)
|
||||
private String avatar;
|
||||
|
||||
@NotBlank(message = "手机号不能为空")
|
||||
@ApiModelProperty(value = "手机号", required = true)
|
||||
private String mobile;
|
||||
|
||||
@NotNull(message = "性别不能为空")
|
||||
@ApiModelProperty(value = "性别1男2女", required = true)
|
||||
private Integer sex;
|
||||
|
||||
@ApiModelProperty(value = "地址")
|
||||
private String address;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.mdd.admin.vo;
|
||||
package com.mdd.front.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.mdd.admin.vo;
|
||||
package com.mdd.front.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
|
@ -80,4 +80,19 @@ sa-token:
|
|||
is-share: false # 多人同登账号共用token
|
||||
token-style: random-64 # token生成的风格
|
||||
is-print: false # 打印版本字符画
|
||||
is-log: false # 是否输出操作日志
|
||||
is-log: false # 是否输出操作日志
|
||||
|
||||
|
||||
config:
|
||||
#短信短信配置
|
||||
aliyun:
|
||||
sms:
|
||||
#ID和Secret是通用的,在控制台可以查看到
|
||||
accessKeyId: LTAI5tM1LeE2pkiS3qEFQkfb
|
||||
accessKeySecret: fEZZyFvWkETS8Clm73f7qmY9ohcTpc
|
||||
#短信签名-可在短信控制台中找到
|
||||
signName: 丙煜
|
||||
#配置超时时间
|
||||
defaultConnectTimeout: 10000
|
||||
defaultReadTimeout: 10000
|
||||
smsCode: SMS_465690552
|
||||
Loading…
Reference in New Issue