|
@@ -1,6 +1,14 @@
|
|
|
package com.ruoyi.framework.web.service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.core.domain.model.LoginBody;
|
|
|
+import com.ruoyi.common.enums.UserStatus;
|
|
|
+import com.ruoyi.common.exception.base.BaseException;
|
|
|
+import com.ruoyi.system.domain.SysLogininfor;
|
|
|
+import com.ruoyi.system.service.ISysLogininforService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
import org.springframework.security.authentication.BadCredentialsException;
|
|
@@ -24,6 +32,7 @@ import com.ruoyi.framework.manager.AsyncManager;
|
|
|
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
|
|
import com.ruoyi.system.service.ISysConfigService;
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
/**
|
|
|
* 登录校验方法
|
|
@@ -48,6 +57,9 @@ public class SysLoginService
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysLogininforService logininforService;
|
|
|
+
|
|
|
/**
|
|
|
* 登录验证
|
|
|
*
|
|
@@ -170,4 +182,62 @@ public class SysLoginService
|
|
|
sysUser.setLoginDate(DateUtils.getNowDate());
|
|
|
userService.updateUserProfile(sysUser);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * APP扫码登录
|
|
|
+ *
|
|
|
+ * @param form
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public R<?> phoneScanLogin(LoginBody form) {
|
|
|
+ if(redisCache.getCacheObject(form.getUuid()) == null){
|
|
|
+ throw new BaseException("登录超时,请重新登录");
|
|
|
+ }
|
|
|
+ String cacheObject = redisCache.getCacheObject(form.getUuid()).toString();
|
|
|
+ if (StringUtils.isBlank(cacheObject)) {
|
|
|
+ throw new BaseException("登录超时,请重新登录");
|
|
|
+ }
|
|
|
+ String phone = form.getPhone();
|
|
|
+ if (StringUtils.isBlank(phone)) {
|
|
|
+ throw new BaseException("缺少参数,手机号码");
|
|
|
+ }
|
|
|
+ SysUser user =userService.getByPhone(phone);
|
|
|
+ String userName = user.getUserName();
|
|
|
+ if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
|
|
+ saveLogininfor(userName, Constants.LOGIN_FAIL, "对不起,您的账号已被删除");
|
|
|
+ throw new BaseException("对不起,您的账号:" + userName + " 已被删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
|
+ saveLogininfor(userName, Constants.LOGIN_FAIL, "用户已停用,请联系管理员");
|
|
|
+ throw new BaseException("对不起,您的账号:" + userName + " 已停用");
|
|
|
+ }
|
|
|
+ saveLogininfor(userName, Constants.LOGIN_SUCCESS, "登录成功");
|
|
|
+ redisCache.setCacheObject(form.getUuid(),form.getPhone());
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveLogininfor(@RequestParam("username") String username, @RequestParam("status") String status,
|
|
|
+ @RequestParam("message") String message)
|
|
|
+ {
|
|
|
+ String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
|
|
|
+
|
|
|
+ // 封装对象
|
|
|
+ SysLogininfor logininfor = new SysLogininfor();
|
|
|
+ logininfor.setUserName(username);
|
|
|
+ logininfor.setIpaddr(ip);
|
|
|
+ logininfor.setMsg(message);
|
|
|
+ // 日志状态
|
|
|
+ if (Constants.LOGIN_SUCCESS.equals(status) || Constants.LOGOUT.equals(status))
|
|
|
+ {
|
|
|
+ logininfor.setStatus("0");
|
|
|
+ }
|
|
|
+ else if (Constants.LOGIN_FAIL.equals(status))
|
|
|
+ {
|
|
|
+ logininfor.setStatus("1");
|
|
|
+ }
|
|
|
+ logininforService.insertLogininfor(logininfor);
|
|
|
+ }
|
|
|
}
|