opt:五月增补-去掉登录验证码,token有效期24小时、主登录界面已经登录后,看板页面不要再次登录
This commit is contained in:
@@ -3,18 +3,13 @@ package org.nl.system.controller.secutiry;
|
|||||||
|
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.wf.captcha.base.Captcha;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.common.utils.RedisUtils;
|
|
||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.common.utils.dto.CurrentUser;
|
import org.nl.common.utils.dto.CurrentUser;
|
||||||
import org.nl.common.security.config.bean.LoginCodeEnum;
|
|
||||||
import org.nl.common.security.config.bean.LoginProperties;
|
|
||||||
import org.nl.system.service.secutiry.impl.OnlineUserService;
|
import org.nl.system.service.secutiry.impl.OnlineUserService;
|
||||||
import org.nl.system.service.user.ISysUserService;
|
import org.nl.system.service.user.ISysUserService;
|
||||||
import org.nl.system.service.user.dao.SysUser;
|
import org.nl.system.service.user.dao.SysUser;
|
||||||
@@ -24,9 +19,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
@@ -38,14 +31,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@RequestMapping("/auth")
|
@RequestMapping("/auth")
|
||||||
@Api(tags = "系统:系统授权接口")
|
@Api(tags = "系统:系统授权接口")
|
||||||
public class AuthorizationController {
|
public class AuthorizationController {
|
||||||
@Autowired
|
|
||||||
private RedisUtils redisUtils;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OnlineUserService onlineUserService;
|
private OnlineUserService onlineUserService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysUserService userService;
|
private ISysUserService userService;
|
||||||
@Autowired
|
|
||||||
private LoginProperties loginProperties;
|
|
||||||
|
|
||||||
@ApiOperation("登录授权")
|
@ApiOperation("登录授权")
|
||||||
@PostMapping(value = "/login")
|
@PostMapping(value = "/login")
|
||||||
@@ -77,27 +66,6 @@ public class AuthorizationController {
|
|||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取验证码")
|
|
||||||
@GetMapping(value = "/code")
|
|
||||||
public ResponseEntity<Object> getCode() {
|
|
||||||
// 获取运算的结果
|
|
||||||
Captcha captcha = loginProperties.getCaptcha();
|
|
||||||
String uuid = IdUtil.simpleUUID();
|
|
||||||
//当验证码类型为 arithmetic时且长度 >= 2 时,captcha.text()的结果有几率为浮点型
|
|
||||||
String captchaValue = captcha.text();
|
|
||||||
if (captcha.getCharType() - 1 == LoginCodeEnum.arithmetic.ordinal() && captchaValue.contains(".")) {
|
|
||||||
captchaValue = captchaValue.split("\\.")[0];
|
|
||||||
}
|
|
||||||
// 保存
|
|
||||||
redisUtils.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES);
|
|
||||||
// 验证码信息
|
|
||||||
Map<String, Object> imgResult = new HashMap<String, Object>(2) {{
|
|
||||||
put("img", captcha.toBase64());
|
|
||||||
put("uuid", uuid);
|
|
||||||
}};
|
|
||||||
return ResponseEntity.ok(imgResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("退出登录")
|
@ApiOperation("退出登录")
|
||||||
@DeleteMapping(value = "/logout")
|
@DeleteMapping(value = "/logout")
|
||||||
public ResponseEntity<Object> logout(HttpServletRequest request) {
|
public ResponseEntity<Object> logout(HttpServletRequest request) {
|
||||||
|
|||||||
@@ -215,16 +215,6 @@ public class OnlineUserService {
|
|||||||
// 密码解密 - 前端的加密规则: encrypt
|
// 密码解密 - 前端的加密规则: encrypt
|
||||||
AuthUserDto authUser = JSON.toJavaObject((JSON) JSON.toJSON(paramMap), AuthUserDto.class);
|
AuthUserDto authUser = JSON.toJavaObject((JSON) JSON.toJSON(paramMap), AuthUserDto.class);
|
||||||
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
||||||
// 查询验证码
|
|
||||||
String code = (String) redisUtils.get(authUser.getUuid());
|
|
||||||
// 清除验证码
|
|
||||||
redisUtils.del(authUser.getUuid());
|
|
||||||
if (StrUtil.isEmpty(code)) {
|
|
||||||
throw new BadRequestException("验证码不存在或已过期");
|
|
||||||
}
|
|
||||||
if (StrUtil.isEmpty(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
|
|
||||||
throw new BadRequestException("验证码错误");
|
|
||||||
}
|
|
||||||
// 校验数据库
|
// 校验数据库
|
||||||
// 根据用户名查询,在比对密码
|
// 根据用户名查询,在比对密码
|
||||||
SysUser userInfo = sysUserService.getOne(new QueryWrapper<SysUser>().eq("username",authUser.getUsername()));
|
SysUser userInfo = sysUserService.getOne(new QueryWrapper<SysUser>().eq("username",authUser.getUsername()));
|
||||||
|
|||||||
@@ -81,24 +81,8 @@ spring:
|
|||||||
login:
|
login:
|
||||||
# 登录缓存
|
# 登录缓存
|
||||||
cache-enable: true
|
cache-enable: true
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: false
|
single-login: false
|
||||||
# 验证码
|
|
||||||
login-code:
|
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
|
||||||
code-type: arithmetic
|
|
||||||
# 登录图形验证码有效时间/分钟
|
|
||||||
expiration: 2
|
|
||||||
# 验证码高度
|
|
||||||
width: 111
|
|
||||||
# 验证码宽度
|
|
||||||
heigth: 36
|
|
||||||
# 内容长度
|
|
||||||
length: 2
|
|
||||||
# 字体名称,为空则使用默认字体
|
|
||||||
font-name:
|
|
||||||
# 字体大小
|
|
||||||
font-size: 25
|
|
||||||
|
|
||||||
#是否允许生成代码,生产环境设置为false
|
#是否允许生成代码,生产环境设置为false
|
||||||
generator:
|
generator:
|
||||||
@@ -135,8 +119,8 @@ logging:
|
|||||||
sa-token:
|
sa-token:
|
||||||
# token 名称 (同时也是cookie名称)
|
# token 名称 (同时也是cookie名称)
|
||||||
token-name: Authorization
|
token-name: Authorization
|
||||||
# token 有效期,单位s 默认30天, -1代表永不过期
|
# token 有效期,单位s 默认24小时, -1代表永不过期
|
||||||
timeout: 2592000
|
timeout: 86400
|
||||||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||||
activity-timeout: -1
|
activity-timeout: -1
|
||||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||||
|
|||||||
@@ -81,24 +81,8 @@ spring:
|
|||||||
login:
|
login:
|
||||||
# 登录缓存
|
# 登录缓存
|
||||||
cache-enable: true
|
cache-enable: true
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: false
|
single-login: false
|
||||||
# 验证码
|
|
||||||
login-code:
|
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
|
||||||
code-type: arithmetic
|
|
||||||
# 登录图形验证码有效时间/分钟
|
|
||||||
expiration: 2
|
|
||||||
# 验证码高度
|
|
||||||
width: 111
|
|
||||||
# 验证码宽度
|
|
||||||
heigth: 36
|
|
||||||
# 内容长度
|
|
||||||
length: 2
|
|
||||||
# 字体名称,为空则使用默认字体
|
|
||||||
font-name:
|
|
||||||
# 字体大小
|
|
||||||
font-size: 25
|
|
||||||
|
|
||||||
#是否允许生成代码,生产环境设置为false
|
#是否允许生成代码,生产环境设置为false
|
||||||
generator:
|
generator:
|
||||||
@@ -135,8 +119,8 @@ logging:
|
|||||||
sa-token:
|
sa-token:
|
||||||
# token 名称 (同时也是cookie名称)
|
# token 名称 (同时也是cookie名称)
|
||||||
token-name: Authorization
|
token-name: Authorization
|
||||||
# token 有效期,单位s 默认30天, -1代表永不过期
|
# token 有效期,单位s 默认24小时, -1代表永不过期
|
||||||
timeout: 2592000
|
timeout: 86400
|
||||||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||||
activity-timeout: -1
|
activity-timeout: -1
|
||||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||||
|
|||||||
@@ -72,24 +72,8 @@ spring:
|
|||||||
login:
|
login:
|
||||||
# 登录缓存
|
# 登录缓存
|
||||||
cache-enable: true
|
cache-enable: true
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: false
|
single-login: false
|
||||||
# 验证码
|
|
||||||
login-code:
|
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
|
||||||
code-type: arithmetic
|
|
||||||
# 登录图形验证码有效时间/分钟
|
|
||||||
expiration: 2
|
|
||||||
# 验证码高度
|
|
||||||
width: 111
|
|
||||||
# 验证码宽度
|
|
||||||
heigth: 36
|
|
||||||
# 内容长度
|
|
||||||
length: 2
|
|
||||||
# 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可
|
|
||||||
font-name:
|
|
||||||
# 字体大小
|
|
||||||
font-size: 25
|
|
||||||
|
|
||||||
#jwt
|
#jwt
|
||||||
jwt:
|
jwt:
|
||||||
@@ -151,8 +135,8 @@ logging:
|
|||||||
sa-token:
|
sa-token:
|
||||||
# token 名称 (同时也是cookie名称)
|
# token 名称 (同时也是cookie名称)
|
||||||
token-name: Authorization
|
token-name: Authorization
|
||||||
# token 有效期,单位s 默认30天, -1代表永不过期
|
# token 有效期,单位s 默认24小时, -1代表永不过期
|
||||||
timeout: 2592000
|
timeout: 86400
|
||||||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||||
activity-timeout: -1
|
activity-timeout: -1
|
||||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
export function login(username, password, code, uuid) {
|
export function login(username, password) {
|
||||||
return request({
|
return request({
|
||||||
url: 'auth/login',
|
url: 'auth/login',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {
|
data: {
|
||||||
username,
|
username,
|
||||||
password,
|
password
|
||||||
code,
|
|
||||||
uuid
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -20,13 +18,6 @@ export function getInfo() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCodeImg() {
|
|
||||||
return request({
|
|
||||||
url: 'auth/code',
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function logout() {
|
export function logout() {
|
||||||
return request({
|
return request({
|
||||||
url: 'auth/logout',
|
url: 'auth/logout',
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const user = {
|
|||||||
Login({ commit }, userInfo) {
|
Login({ commit }, userInfo) {
|
||||||
// const rememberMe = userInfo.rememberMe
|
// const rememberMe = userInfo.rememberMe
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
login(userInfo.username, userInfo.password, userInfo.code, userInfo.uuid).then(res => {
|
login(userInfo.username, userInfo.password).then(res => {
|
||||||
// setToken(res.token, rememberMe)
|
// setToken(res.token, rememberMe)
|
||||||
commit('SET_TOKEN', res.token)
|
commit('SET_TOKEN', res.token)
|
||||||
setUserInfo(res.user, commit)
|
setUserInfo(res.user, commit)
|
||||||
|
|||||||
@@ -13,14 +13,6 @@
|
|||||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="code">
|
|
||||||
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin">
|
|
||||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
|
||||||
</el-input>
|
|
||||||
<div class="login-code">
|
|
||||||
<img :src="codeUrl" @click="getCode">
|
|
||||||
</div>
|
|
||||||
</el-form-item>
|
|
||||||
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">
|
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">
|
||||||
记住我
|
记住我
|
||||||
</el-checkbox>
|
</el-checkbox>
|
||||||
@@ -43,7 +35,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { encrypt } from '@/utils/rsaEncrypt'
|
import { encrypt } from '@/utils/rsaEncrypt'
|
||||||
import Config from '@/settings'
|
import Config from '@/settings'
|
||||||
import { getCodeImg } from '@/api/login'
|
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
import Background from '@/assets/images/background.jpg'
|
import Background from '@/assets/images/background.jpg'
|
||||||
export default {
|
export default {
|
||||||
@@ -53,19 +44,15 @@ export default {
|
|||||||
title: '诺力开发平台',
|
title: '诺力开发平台',
|
||||||
title_param: 'platform',
|
title_param: 'platform',
|
||||||
Background: Background,
|
Background: Background,
|
||||||
codeUrl: '',
|
|
||||||
cookiePass: '',
|
cookiePass: '',
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
rememberMe: true,
|
rememberMe: true
|
||||||
code: '',
|
|
||||||
uuid: ''
|
|
||||||
},
|
},
|
||||||
loginRules: {
|
loginRules: {
|
||||||
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
|
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
|
||||||
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
|
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
|
||||||
code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
|
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
redirect: undefined
|
redirect: undefined
|
||||||
@@ -83,20 +70,12 @@ export default {
|
|||||||
this.getValueByCode(this.title_param).then(res => {
|
this.getValueByCode(this.title_param).then(res => {
|
||||||
this.title = res.value
|
this.title = res.value
|
||||||
})
|
})
|
||||||
// 获取验证码
|
|
||||||
this.getCode()
|
|
||||||
// 获取用户名密码等Cookie
|
// 获取用户名密码等Cookie
|
||||||
this.getCookie()
|
this.getCookie()
|
||||||
// token 过期提示
|
// token 过期提示
|
||||||
this.point()
|
this.point()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCode() {
|
|
||||||
getCodeImg().then(res => {
|
|
||||||
this.codeUrl = res.img
|
|
||||||
this.loginForm.uuid = res.uuid
|
|
||||||
})
|
|
||||||
},
|
|
||||||
getCookie() {
|
getCookie() {
|
||||||
const username = Cookies.get('username')
|
const username = Cookies.get('username')
|
||||||
let password = Cookies.get('password')
|
let password = Cookies.get('password')
|
||||||
@@ -116,9 +95,7 @@ export default {
|
|||||||
const user = {
|
const user = {
|
||||||
username: this.loginForm.username,
|
username: this.loginForm.username,
|
||||||
password: this.loginForm.password,
|
password: this.loginForm.password,
|
||||||
rememberMe: this.loginForm.rememberMe,
|
rememberMe: this.loginForm.rememberMe
|
||||||
code: this.loginForm.code,
|
|
||||||
uuid: this.loginForm.uuid
|
|
||||||
}
|
}
|
||||||
user.password = encrypt(user.password)
|
user.password = encrypt(user.password)
|
||||||
if (valid) {
|
if (valid) {
|
||||||
@@ -139,10 +116,9 @@ export default {
|
|||||||
// window.location.href = this.redirect
|
// window.location.href = this.redirect
|
||||||
// }
|
// }
|
||||||
// this.$router.push({ path: this.redirect || '/' })
|
// this.$router.push({ path: this.redirect || '/' })
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.getCode()
|
})
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
console.log('error submit!!')
|
console.log('error submit!!')
|
||||||
return false
|
return false
|
||||||
@@ -195,19 +171,9 @@ export default {
|
|||||||
height: 39px;width: 14px;margin-left: 2px;
|
height: 39px;width: 14px;margin-left: 2px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.login-tip {
|
.login-tip {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #bfbfbf;
|
color: #bfbfbf;
|
||||||
}
|
}
|
||||||
.login-code {
|
|
||||||
width: 33%;
|
|
||||||
display: inline-block;
|
|
||||||
height: 38px;
|
|
||||||
float: right;
|
|
||||||
img{
|
|
||||||
cursor: pointer;
|
|
||||||
vertical-align:middle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -3,18 +3,13 @@ package org.nl.system.controller.secutiry;
|
|||||||
|
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.wf.captcha.base.Captcha;
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.common.utils.RedisUtils;
|
|
||||||
import org.nl.common.utils.SecurityUtils;
|
import org.nl.common.utils.SecurityUtils;
|
||||||
import org.nl.common.utils.dto.CurrentUser;
|
import org.nl.common.utils.dto.CurrentUser;
|
||||||
import org.nl.common.security.config.bean.LoginCodeEnum;
|
|
||||||
import org.nl.common.security.config.bean.LoginProperties;
|
|
||||||
import org.nl.system.service.secutiry.impl.OnlineUserService;
|
import org.nl.system.service.secutiry.impl.OnlineUserService;
|
||||||
import org.nl.system.service.user.ISysUserService;
|
import org.nl.system.service.user.ISysUserService;
|
||||||
import org.nl.system.service.user.dao.SysUser;
|
import org.nl.system.service.user.dao.SysUser;
|
||||||
@@ -24,9 +19,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
@@ -38,14 +31,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@RequestMapping("/auth")
|
@RequestMapping("/auth")
|
||||||
@Api(tags = "系统:系统授权接口")
|
@Api(tags = "系统:系统授权接口")
|
||||||
public class AuthorizationController {
|
public class AuthorizationController {
|
||||||
@Autowired
|
|
||||||
private RedisUtils redisUtils;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OnlineUserService onlineUserService;
|
private OnlineUserService onlineUserService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysUserService userService;
|
private ISysUserService userService;
|
||||||
@Autowired
|
|
||||||
private LoginProperties loginProperties;
|
|
||||||
|
|
||||||
@ApiOperation("登录授权")
|
@ApiOperation("登录授权")
|
||||||
@PostMapping(value = "/login")
|
@PostMapping(value = "/login")
|
||||||
@@ -77,27 +66,6 @@ public class AuthorizationController {
|
|||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取验证码")
|
|
||||||
@GetMapping(value = "/code")
|
|
||||||
public ResponseEntity<Object> getCode() {
|
|
||||||
// 获取运算的结果
|
|
||||||
Captcha captcha = loginProperties.getCaptcha();
|
|
||||||
String uuid = IdUtil.simpleUUID();
|
|
||||||
//当验证码类型为 arithmetic时且长度 >= 2 时,captcha.text()的结果有几率为浮点型
|
|
||||||
String captchaValue = captcha.text();
|
|
||||||
if (captcha.getCharType() - 1 == LoginCodeEnum.arithmetic.ordinal() && captchaValue.contains(".")) {
|
|
||||||
captchaValue = captchaValue.split("\\.")[0];
|
|
||||||
}
|
|
||||||
// 保存
|
|
||||||
redisUtils.set(uuid, captchaValue, loginProperties.getLoginCode().getExpiration(), TimeUnit.MINUTES);
|
|
||||||
// 验证码信息
|
|
||||||
Map<String, Object> imgResult = new HashMap<String, Object>(2) {{
|
|
||||||
put("img", captcha.toBase64());
|
|
||||||
put("uuid", uuid);
|
|
||||||
}};
|
|
||||||
return ResponseEntity.ok(imgResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("退出登录")
|
@ApiOperation("退出登录")
|
||||||
@DeleteMapping(value = "/logout")
|
@DeleteMapping(value = "/logout")
|
||||||
public ResponseEntity<Object> logout(HttpServletRequest request) {
|
public ResponseEntity<Object> logout(HttpServletRequest request) {
|
||||||
|
|||||||
@@ -215,16 +215,6 @@ public class OnlineUserService {
|
|||||||
// 密码解密 - 前端的加密规则: encrypt
|
// 密码解密 - 前端的加密规则: encrypt
|
||||||
AuthUserDto authUser = JSON.toJavaObject((JSON) JSON.toJSON(paramMap), AuthUserDto.class);
|
AuthUserDto authUser = JSON.toJavaObject((JSON) JSON.toJSON(paramMap), AuthUserDto.class);
|
||||||
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
||||||
// 查询验证码
|
|
||||||
String code = (String) redisUtils.get(authUser.getUuid());
|
|
||||||
// 清除验证码
|
|
||||||
redisUtils.del(authUser.getUuid());
|
|
||||||
if (StrUtil.isEmpty(code)) {
|
|
||||||
throw new BadRequestException("验证码不存在或已过期");
|
|
||||||
}
|
|
||||||
if (StrUtil.isEmpty(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
|
|
||||||
throw new BadRequestException("验证码错误");
|
|
||||||
}
|
|
||||||
// 校验数据库
|
// 校验数据库
|
||||||
// 根据用户名查询,在比对密码
|
// 根据用户名查询,在比对密码
|
||||||
SysUser userInfo = sysUserService.getOne(new QueryWrapper<SysUser>().eq("username",authUser.getUsername()));
|
SysUser userInfo = sysUserService.getOne(new QueryWrapper<SysUser>().eq("username",authUser.getUsername()));
|
||||||
|
|||||||
@@ -51,24 +51,8 @@ spring:
|
|||||||
login:
|
login:
|
||||||
# 登录缓存
|
# 登录缓存
|
||||||
cache-enable: true
|
cache-enable: true
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: false
|
single-login: false
|
||||||
# 验证码
|
|
||||||
login-code:
|
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
|
||||||
code-type: arithmetic
|
|
||||||
# 登录图形验证码有效时间/分钟
|
|
||||||
expiration: 2
|
|
||||||
# 验证码高度
|
|
||||||
width: 111
|
|
||||||
# 验证码宽度
|
|
||||||
heigth: 36
|
|
||||||
# 内容长度
|
|
||||||
length: 2
|
|
||||||
# 字体名称,为空则使用默认字体
|
|
||||||
font-name:
|
|
||||||
# 字体大小
|
|
||||||
font-size: 25
|
|
||||||
|
|
||||||
#是否允许生成代码,生产环境设置为false
|
#是否允许生成代码,生产环境设置为false
|
||||||
generator:
|
generator:
|
||||||
@@ -105,8 +89,8 @@ logging:
|
|||||||
sa-token:
|
sa-token:
|
||||||
# token 名称 (同时也是cookie名称)
|
# token 名称 (同时也是cookie名称)
|
||||||
token-name: Authorization
|
token-name: Authorization
|
||||||
# token 有效期,单位s 默认30天, -1代表永不过期
|
# token 有效期,单位s 默认24小时, -1代表永不过期
|
||||||
timeout: 2592000
|
timeout: 86400
|
||||||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||||
activity-timeout: -1
|
activity-timeout: -1
|
||||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||||
|
|||||||
@@ -63,24 +63,8 @@ spring:
|
|||||||
login:
|
login:
|
||||||
# 登录缓存
|
# 登录缓存
|
||||||
cache-enable: true
|
cache-enable: true
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: false
|
single-login: false
|
||||||
# 验证码
|
|
||||||
login-code:
|
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
|
||||||
code-type: arithmetic
|
|
||||||
# 登录图形验证码有效时间/分钟
|
|
||||||
expiration: 2
|
|
||||||
# 验证码高度
|
|
||||||
width: 111
|
|
||||||
# 验证码宽度
|
|
||||||
heigth: 36
|
|
||||||
# 内容长度
|
|
||||||
length: 2
|
|
||||||
# 字体名称,为空则使用默认字体
|
|
||||||
font-name:
|
|
||||||
# 字体大小
|
|
||||||
font-size: 25
|
|
||||||
|
|
||||||
#是否允许生成代码,生产环境设置为false
|
#是否允许生成代码,生产环境设置为false
|
||||||
generator:
|
generator:
|
||||||
@@ -117,8 +101,8 @@ logging:
|
|||||||
sa-token:
|
sa-token:
|
||||||
# token 名称 (同时也是cookie名称)
|
# token 名称 (同时也是cookie名称)
|
||||||
token-name: Authorization
|
token-name: Authorization
|
||||||
# token 有效期,单位s 默认30天, -1代表永不过期
|
# token 有效期,单位s 默认24小时, -1代表永不过期
|
||||||
timeout: 2592000
|
timeout: 86400
|
||||||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||||
activity-timeout: -1
|
activity-timeout: -1
|
||||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||||
|
|||||||
@@ -63,24 +63,8 @@ spring:
|
|||||||
login:
|
login:
|
||||||
# 登录缓存
|
# 登录缓存
|
||||||
cache-enable: true
|
cache-enable: true
|
||||||
# 是否限制单用户登录
|
# 是否限制单用户登录
|
||||||
single-login: false
|
single-login: false
|
||||||
# 验证码
|
|
||||||
login-code:
|
|
||||||
# 验证码类型配置 查看 LoginProperties 类
|
|
||||||
code-type: arithmetic
|
|
||||||
# 登录图形验证码有效时间/分钟
|
|
||||||
expiration: 2
|
|
||||||
# 验证码高度
|
|
||||||
width: 111
|
|
||||||
# 验证码宽度
|
|
||||||
heigth: 36
|
|
||||||
# 内容长度
|
|
||||||
length: 2
|
|
||||||
# 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可
|
|
||||||
font-name:
|
|
||||||
# 字体大小
|
|
||||||
font-size: 25
|
|
||||||
|
|
||||||
#jwt
|
#jwt
|
||||||
jwt:
|
jwt:
|
||||||
@@ -142,8 +126,8 @@ logging:
|
|||||||
sa-token:
|
sa-token:
|
||||||
# token 名称 (同时也是cookie名称)
|
# token 名称 (同时也是cookie名称)
|
||||||
token-name: Authorization
|
token-name: Authorization
|
||||||
# token 有效期,单位s 默认30天, -1代表永不过期
|
# token 有效期,单位s 默认24小时, -1代表永不过期
|
||||||
timeout: 2592000
|
timeout: 86400
|
||||||
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
# token 临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
|
||||||
activity-timeout: -1
|
activity-timeout: -1
|
||||||
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
export function login(username, password, code, uuid) {
|
export function login(username, password) {
|
||||||
return request({
|
return request({
|
||||||
url: 'auth/login',
|
url: 'auth/login',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {
|
data: {
|
||||||
username,
|
username,
|
||||||
password,
|
password
|
||||||
code,
|
|
||||||
uuid
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -20,13 +18,6 @@ export function getInfo() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCodeImg() {
|
|
||||||
return request({
|
|
||||||
url: 'auth/code',
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function logout() {
|
export function logout() {
|
||||||
return request({
|
return request({
|
||||||
url: 'auth/logout',
|
url: 'auth/logout',
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const user = {
|
|||||||
Login({ commit }, userInfo) {
|
Login({ commit }, userInfo) {
|
||||||
// const rememberMe = userInfo.rememberMe
|
// const rememberMe = userInfo.rememberMe
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
login(userInfo.username, userInfo.password, userInfo.code, userInfo.uuid).then(res => {
|
login(userInfo.username, userInfo.password).then(res => {
|
||||||
// setToken(res.token, rememberMe)
|
// setToken(res.token, rememberMe)
|
||||||
commit('SET_TOKEN', res.token)
|
commit('SET_TOKEN', res.token)
|
||||||
setUserInfo(res.user, commit)
|
setUserInfo(res.user, commit)
|
||||||
|
|||||||
@@ -13,14 +13,6 @@
|
|||||||
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
||||||
</el-input>
|
</el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item prop="code">
|
|
||||||
<el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin">
|
|
||||||
<svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
|
||||||
</el-input>
|
|
||||||
<div class="login-code">
|
|
||||||
<img :src="codeUrl" @click="getCode">
|
|
||||||
</div>
|
|
||||||
</el-form-item>
|
|
||||||
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">
|
<el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">
|
||||||
记住我
|
记住我
|
||||||
</el-checkbox>
|
</el-checkbox>
|
||||||
@@ -43,7 +35,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import { encrypt } from '@/utils/rsaEncrypt'
|
import { encrypt } from '@/utils/rsaEncrypt'
|
||||||
import Config from '@/settings'
|
import Config from '@/settings'
|
||||||
import { getCodeImg } from '@/api/login'
|
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
import Background from '@/assets/images/background.jpg'
|
import Background from '@/assets/images/background.jpg'
|
||||||
export default {
|
export default {
|
||||||
@@ -53,19 +44,15 @@ export default {
|
|||||||
title: '诺力开发平台',
|
title: '诺力开发平台',
|
||||||
title_param: 'platform',
|
title_param: 'platform',
|
||||||
Background: Background,
|
Background: Background,
|
||||||
codeUrl: '',
|
|
||||||
cookiePass: '',
|
cookiePass: '',
|
||||||
loginForm: {
|
loginForm: {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: '',
|
password: '',
|
||||||
rememberMe: true,
|
rememberMe: true
|
||||||
code: '',
|
|
||||||
uuid: ''
|
|
||||||
},
|
},
|
||||||
loginRules: {
|
loginRules: {
|
||||||
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
|
username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
|
||||||
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }],
|
password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
|
||||||
code: [{ required: true, trigger: 'change', message: '验证码不能为空' }]
|
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
redirect: undefined
|
redirect: undefined
|
||||||
@@ -83,20 +70,12 @@ export default {
|
|||||||
this.getValueByCode(this.title_param).then(res => {
|
this.getValueByCode(this.title_param).then(res => {
|
||||||
this.title = res.value
|
this.title = res.value
|
||||||
})
|
})
|
||||||
// 获取验证码
|
|
||||||
this.getCode()
|
|
||||||
// 获取用户名密码等Cookie
|
// 获取用户名密码等Cookie
|
||||||
this.getCookie()
|
this.getCookie()
|
||||||
// token 过期提示
|
// token 过期提示
|
||||||
this.point()
|
this.point()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCode() {
|
|
||||||
getCodeImg().then(res => {
|
|
||||||
this.codeUrl = res.img
|
|
||||||
this.loginForm.uuid = res.uuid
|
|
||||||
})
|
|
||||||
},
|
|
||||||
getCookie() {
|
getCookie() {
|
||||||
const username = Cookies.get('username')
|
const username = Cookies.get('username')
|
||||||
let password = Cookies.get('password')
|
let password = Cookies.get('password')
|
||||||
@@ -116,9 +95,7 @@ export default {
|
|||||||
const user = {
|
const user = {
|
||||||
username: this.loginForm.username,
|
username: this.loginForm.username,
|
||||||
password: this.loginForm.password,
|
password: this.loginForm.password,
|
||||||
rememberMe: this.loginForm.rememberMe,
|
rememberMe: this.loginForm.rememberMe
|
||||||
code: this.loginForm.code,
|
|
||||||
uuid: this.loginForm.uuid
|
|
||||||
}
|
}
|
||||||
user.password = encrypt(user.password)
|
user.password = encrypt(user.password)
|
||||||
if (valid) {
|
if (valid) {
|
||||||
@@ -139,10 +116,9 @@ export default {
|
|||||||
// window.location.href = this.redirect
|
// window.location.href = this.redirect
|
||||||
// }
|
// }
|
||||||
// this.$router.push({ path: this.redirect || '/' })
|
// this.$router.push({ path: this.redirect || '/' })
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
this.getCode()
|
})
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
console.log('error submit!!')
|
console.log('error submit!!')
|
||||||
return false
|
return false
|
||||||
@@ -195,19 +171,9 @@ export default {
|
|||||||
height: 39px;width: 14px;margin-left: 2px;
|
height: 39px;width: 14px;margin-left: 2px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.login-tip {
|
.login-tip {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #bfbfbf;
|
color: #bfbfbf;
|
||||||
}
|
}
|
||||||
.login-code {
|
|
||||||
width: 33%;
|
|
||||||
display: inline-block;
|
|
||||||
height: 38px;
|
|
||||||
float: right;
|
|
||||||
img{
|
|
||||||
cursor: pointer;
|
|
||||||
vertical-align:middle
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -533,6 +533,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import crudProduceScreen, {getAllPrinter, sendPrint} from './produceScreen'
|
import crudProduceScreen, {getAllPrinter, sendPrint} from './produceScreen'
|
||||||
import {getAgvStatus} from '@/api/agv_alarm'
|
import {getAgvStatus} from '@/api/agv_alarm'
|
||||||
|
import Cookies from 'js-cookie'
|
||||||
// import crudProduceScreen from './mork'
|
// import crudProduceScreen from './mork'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -573,7 +574,7 @@ export default {
|
|||||||
material_qty: '',
|
material_qty: '',
|
||||||
material_id: '',
|
material_id: '',
|
||||||
material_code: '',
|
material_code: '',
|
||||||
username: JSON.parse(localStorage.getItem('screenData')).username
|
username: JSON.parse(localStorage.getItem('screenData')) !== undefined ? JSON.parse(localStorage.getItem('screenData')).username : Cookies.get('username')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -48,18 +48,23 @@
|
|||||||
<script>
|
<script>
|
||||||
import { encrypt } from '@/utils/rsaEncrypt'
|
import { encrypt } from '@/utils/rsaEncrypt'
|
||||||
import crudProduceScreen from './produceScreen'
|
import crudProduceScreen from './produceScreen'
|
||||||
|
import Cookies from 'js-cookie'
|
||||||
|
import {getToken} from "../../../utils/auth";
|
||||||
// import crudProduceScreen from './mork'
|
// import crudProduceScreen from './mork'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
username: '',
|
username: Cookies.get('username'),
|
||||||
password: '',
|
password: Cookies.get('password'),
|
||||||
options: [],
|
options: [],
|
||||||
value: '',
|
value: '',
|
||||||
disabled: false,
|
disabled: false,
|
||||||
show: false
|
show: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
this.isLogin() // 判断是否登录,已登录则直接跳转控制面板
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toLogin() {
|
toLogin() {
|
||||||
this.disabled = true
|
this.disabled = true
|
||||||
@@ -83,6 +88,14 @@ export default {
|
|||||||
this.disabled = false
|
this.disabled = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
isLogin() {
|
||||||
|
if (getToken()) {
|
||||||
|
crudProduceScreen.getUserOrDevice({ username: Cookies.get('username') }).then(res => {
|
||||||
|
this.options = [...res]
|
||||||
|
this.show = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
toSure() {
|
toSure() {
|
||||||
this.disabled = true
|
this.disabled = true
|
||||||
if (!this.value) {
|
if (!this.value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user