[关闭]
@attack666 2021-03-10T07:34:48.000000Z 字数 2619 阅读 447

登陆接口修改

思路

前端找到登陆接口并修改为目前的接口

关键位置

目录 说明
config\dev.env.js 连接后端接口
src\api\login.js 发起请求的接口
src\utils\request.js 前端登陆工具的封装
beauty-o2o-api/.../api/controller/AccountController.java 旧的后端登陆接口

现有问题

  1. 后端目前没有account/info接口,因此后台管理页面仍然无法正常登入

    • 解决方法:
      1. 如需使用旧的后端进行调试,请自行备份旧的代码
      1. 或者在调试时使用git切换到之前的版本
  2. 后端原来的管理员表是t_sys_user。新的用户表是tb_sys_user,但是里面并没有数据。

    • 解决方法:
      1. 向原来的数据库中导入sys_user.sql文件。
      1. 使用Postman提交两条请求到create接口
  3. 后端原本使用roles字段来确定登陆后台的角色,但是目前的管理员表并没有此字段

  4. 后端默认不允许跨域,如需调试,请自行更改admin-api/.../Security.java中的跨域配置,一个可行的配置如下
  1. /**
  2. * Created on 2021/3/7. * * @author liuxd2017@163.com
  3. */@EnableWebSecurity
  4. public class Security extends WebSecurityConfigurerAdapter {
  5. @Autowired
  6. private PasswordEncoder passwordEncoder;
  7. @Autowired
  8. private SysUserService sysUserService;
  9. @Bean
  10. public AuthenticationProvider authenticationProvider() {
  11. DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
  12. authenticationProvider.setUserDetailsService(sysUserService);
  13. authenticationProvider.setPasswordEncoder(passwordEncoder);
  14. return authenticationProvider;
  15. }
  16. /**
  17. * 认证
  18. */
  19. @Override
  20. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  21. auth.authenticationProvider(authenticationProvider());
  22. auth.eraseCredentials(false);
  23. }
  24. /**
  25. * 授权
  26. */
  27. @Override
  28. protected void configure(HttpSecurity http) throws Exception {
  29. // 禁止隧道 // 禁止跨域 // 禁止头部
  30. http.csrf().disable();
  31. http.headers().disable();
  32. http.cors().configurationSource(CorsConfigurationSource());
  33. http.addFilterAt(new JwtAuthenticationFilter(authenticationManager()), UsernamePasswordAuthenticationFilter.class);
  34. http.authorizeRequests()
  35. .antMatchers("/xhr/v1/users/login",
  36. "/xhr/v1/users/create",
  37. "/xhr/v1/users/needLogin",
  38. "/v2/api-docs",
  39. "/configuration/ui",
  40. "/swagger-resources/**",
  41. "/configuration/security",
  42. "/swagger-ui.html",
  43. "/webjars/**")
  44. .permitAll()
  45. .anyRequest().authenticated()
  46. .and()
  47. .formLogin()
  48. .loginPage("/xhr/v1/users/needLogin")
  49. .loginProcessingUrl("/xhr/v1/users/login")
  50. .and()
  51. .addFilter(new JwtAuthorizationFilter(authenticationManager(), sysUserService))
  52. // 前后端分离是 STATELESS,故 session 使用该策略
  53. .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
  54. }
  55. private CorsConfigurationSource CorsConfigurationSource() {
  56. CorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
  57. CorsConfiguration corsConfiguration = new CorsConfiguration();
  58. corsConfiguration.addAllowedOrigin("http://localhost:9528"); //同源配置,*表示任何请求都视为同源,若需指定ip和端口可以改为如“localhost:8080”,多个以“,”分隔;
  59. corsConfiguration.addAllowedHeader("*");//header,允许哪些header,本案中使用的是token,此处可将*替换为token;
  60. corsConfiguration.addAllowedMethod("*"); //允许的请求方法,PSOT、GET等
  61. corsConfiguration.setAllowCredentials(true);
  62. ((UrlBasedCorsConfigurationSource) source).registerCorsConfiguration("/**",corsConfiguration); //配置允许跨域访问的url
  63. return source;
  64. }
  65. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注