提交 89370df9 authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 登录页面增加用户名验证

上级 acf8ecbd
......@@ -7,6 +7,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@Api(tags = "权限:权限管理")
@RequestMapping("/api/auth")
......@@ -26,6 +28,9 @@ public interface AuthApi {
@PostMapping("/logout")
String logout();
@PostMapping("/validateName")
Boolean validateName(Map<String, String> nameDto);
@GetMapping("/test")
String test();
......
......@@ -82,6 +82,15 @@ public class AuthServer implements AuthApi {
return "success";
}
@Override
public Boolean validateName(@RequestBody Map<String, String> nameDto) {
String userName = nameDto.get("userName");
if (StringUtils.isEmpty(userName)) return false;
SysUserEntity userEntity = authUserService.getUserByName(userName);
if (ObjectUtils.isEmpty(userEntity)) return false;
return true;
}
@Override
public Boolean isLogin() {
return null;
......
......@@ -49,6 +49,7 @@ public class ShiroServiceImpl implements ShiroService {
filterChainDefinitionMap.put("/api/auth/login", ANON);
filterChainDefinitionMap.put("/api/auth/validateName", ANON);
filterChainDefinitionMap.put("/unauth", ANON);
filterChainDefinitionMap.put("/display/**", ANON);
filterChainDefinitionMap.put("/tokenExpired", ANON);
......
......@@ -21,3 +21,11 @@ export function logout() {
method: 'post'
})
}
export function validateUserName(data) {
return request({
url: '/api/auth/validateName',
method: 'post',
data
})
}
......@@ -49,17 +49,28 @@
</template>
<script>
import { validUsername } from '@/utils/validate'
import { encrypt } from '@/utils/rsaEncrypt'
import { validateUserName } from '@/api/user'
export default {
name: 'Login',
data() {
const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) {
const userName = value.trim()
validateUserName({ userName: userName }).then(res => {
if (res.data) {
callback()
} else {
callback(new Error('Please enter the correct user name'))
}
}).catch(() => {
callback(new Error('Please enter the correct user name'))
} else {
callback()
}
})
// if (!validUsername(value)) {
// callback(new Error('Please enter the correct user name'))
// } else {
// callback()
// }
}
const validatePassword = (rule, value, callback) => {
if (value.length < 6) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论