forked from github/dataease
feat: 登录页面增加用户名验证
This commit is contained in:
parent
acf8ecbdeb
commit
89370df958
@ -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)) {
|
||||
callback(new Error('Please enter the correct user name'))
|
||||
} else {
|
||||
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'))
|
||||
})
|
||||
// if (!validUsername(value)) {
|
||||
// callback(new Error('Please enter the correct user name'))
|
||||
// } else {
|
||||
// callback()
|
||||
// }
|
||||
}
|
||||
const validatePassword = (rule, value, callback) => {
|
||||
if (value.length < 6) {
|
||||
|
Loading…
Reference in New Issue
Block a user