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

This commit is contained in:
fit2cloud-chenyw 2021-04-22 14:53:23 +08:00
parent acf8ecbdeb
commit 89370df958
5 changed files with 39 additions and 5 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -21,3 +21,11 @@ export function logout() {
method: 'post'
})
}
export function validateUserName(data) {
return request({
url: '/api/auth/validateName',
method: 'post',
data
})
}

View File

@ -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) {