2024-07-11
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Teacher Ruan explained it very well. The website is as follows:
http://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html
A: No, so you can only log in on the login page. If you want to jump to other interfaces, you will be redirected to the login page and forced to log in. The front-end blocking code is as follows:
A: It is generated when logging in. The specific code is as follows:
- public String login(String username, String password, String code, String uuid)
- {
- boolean captchaOnOff = configService.selectCaptchaOnOff();
- // 验证码开关
- if (captchaOnOff)
- {
- validateCaptcha(username, code, uuid);
- }
- // 用户验证
- Authentication authentication = null;
- try
- {
- // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
- authentication = authenticationManager
- .authenticate(new UsernamePasswordAuthenticationToken(username, password));
- }
- catch (Exception e)
- {
- if (e instanceof BadCredentialsException)
- {
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
- throw new UserPasswordNotMatchException();
- }
- else
- {
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
- throw new ServiceException(e.getMessage());
- }
- }
- AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
- LoginUser loginUser = (LoginUser) authentication.getPrincipal();
- recordLoginInfo(loginUser.getUserId());
- // 生成token
- return tokenService.createToken(loginUser);
- }