From 175ae1f569fec6899a1b86bee472ebb4b8870fe4 Mon Sep 17 00:00:00 2001 From: zhubingjian Date: Wed, 29 May 2019 10:03:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=99=AE=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B3=A8=E5=86=8C=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=B8=94?= =?UTF-8?q?=E4=BB=BB=E4=BD=95=E4=BA=BA=E9=83=BD=E8=83=BD=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blogserver/.vscode/launch.json | 21 +++ .../org/sang/config/WebSecurityConfig.java | 12 +- .../main/java/org/sang/mapper/UserMapper.xml | 2 +- .../src/main/resources/application.properties | 6 +- vueblog/src/components/Login.vue | 16 +++ vueblog/src/components/PostArticle.vue | 6 +- vueblog/src/components/SignIn.vue | 126 ++++++++++++++++++ vueblog/src/router/index.js | 7 +- 8 files changed, 183 insertions(+), 13 deletions(-) create mode 100644 blogserver/.vscode/launch.json create mode 100644 vueblog/src/components/SignIn.vue diff --git a/blogserver/.vscode/launch.json b/blogserver/.vscode/launch.json new file mode 100644 index 00000000..9db5118c --- /dev/null +++ b/blogserver/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Debug (Launch) - Current File", + "request": "launch", + "mainClass": "${file}" + }, + { + "type": "java", + "name": "Debug (Launch)-BlogserverApplication", + "request": "launch", + "mainClass": "org.sang.BlogserverApplication", + "projectName": "blogserver" + } + ] +} \ No newline at end of file diff --git a/blogserver/src/main/java/org/sang/config/WebSecurityConfig.java b/blogserver/src/main/java/org/sang/config/WebSecurityConfig.java index e8a6976f..7d1cfec9 100644 --- a/blogserver/src/main/java/org/sang/config/WebSecurityConfig.java +++ b/blogserver/src/main/java/org/sang/config/WebSecurityConfig.java @@ -26,6 +26,7 @@ * Created by sang on 2017/12/17. */ @Configuration +// @EnableWebSecurity //2019-5-28 添加注解@EnableWebSecurity,避免造成不可预估的结果 public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired UserService userService; @@ -53,10 +54,12 @@ public boolean matches(CharSequence charSequence, String s) { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() + .antMatchers("/reg").permitAll() .antMatchers("/admin/category/all").authenticated() - .antMatchers("/admin/**","/reg").hasRole("超级管理员")///admin/**的URL都需要有超级管理员角色,如果使用.hasAuthority()方法来配置,需要在参数中加上ROLE_,如下.hasAuthority("ROLE_超级管理员") - .anyRequest().authenticated()//其他的路径都是登录后即可访问 - .and().formLogin().loginPage("/login_page").successHandler(new AuthenticationSuccessHandler() { + .antMatchers("/admin/**").hasRole("超级管理员")///admin/**的URL都需要有超级管理员角色,如果使用.hasAuthority()方法来配置,需要在参数中加上ROLE_,如下.hasAuthority("ROLE_超级管理员") + .anyRequest().authenticated().and() + //除注册、登录路径外的其他的路径都是登录后即可访问 + .formLogin().loginPage("/login_page").successHandler(new AuthenticationSuccessHandler() { @Override public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { httpServletResponse.setContentType("application/json;charset=utf-8"); @@ -65,8 +68,7 @@ public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpS out.flush(); out.close(); } - }) - .failureHandler(new AuthenticationFailureHandler() { + }).failureHandler(new AuthenticationFailureHandler() { @Override public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { httpServletResponse.setContentType("application/json;charset=utf-8"); diff --git a/blogserver/src/main/java/org/sang/mapper/UserMapper.xml b/blogserver/src/main/java/org/sang/mapper/UserMapper.xml index 57c2246d..e1537794 100644 --- a/blogserver/src/main/java/org/sang/mapper/UserMapper.xml +++ b/blogserver/src/main/java/org/sang/mapper/UserMapper.xml @@ -7,7 +7,7 @@ SELECT * FROM user WHERE username=#{username} - INSERT INTO user set username=#{username},password=#{password},nickname=#{nickname} + INSERT INTO user set username=#{username},password=#{password},nickname=#{nickname},email=#{email} UPDATE user set email=#{email} WHERE id=#{id} diff --git a/blogserver/src/main/resources/application.properties b/blogserver/src/main/resources/application.properties index 857ce9a6..8a02f714 100644 --- a/blogserver/src/main/resources/application.properties +++ b/blogserver/src/main/resources/application.properties @@ -1,7 +1,7 @@ spring.datasource.type=com.alibaba.druid.pool.DruidDataSource -spring.datasource.url=jdbc:mysql:///vueblog?useUnicode=true&characterEncoding=UTF-8 -spring.datasource.username=username -spring.datasource.password=password +spring.datasource.url=jdbc:mysql:///vueblog2?useUnicode=true&characterEncoding=UTF-8 +spring.datasource.username=root +spring.datasource.password=Zbj123 mybatis.config-location=classpath:/mybatis-config.xml server.port=8081 diff --git a/vueblog/src/components/Login.vue b/vueblog/src/components/Login.vue index 13af1c9e..33bf0f82 100644 --- a/vueblog/src/components/Login.vue +++ b/vueblog/src/components/Login.vue @@ -9,6 +9,8 @@ + + 登录 @@ -32,6 +34,11 @@ loading: false } }, + mounted: function (){ + var _this = this; + _this.loginForm.username = _this.$route.query.username===undefined?"sang":_this.$route.query.username; + _this.loginForm.password = _this.$route.query.password===undefined?"123":_this.$route.query.password; + }, methods: { submitClick: function () { var _this = this; @@ -57,11 +64,16 @@ _this.loading = false; _this.$alert('找不到服务器⊙﹏⊙∥!', '失败!'); }); + }, + Sign_In:function(){ + var _this = this; + _this.$router.replace({path: '/signin'}); } } } diff --git a/vueblog/src/components/PostArticle.vue b/vueblog/src/components/PostArticle.vue index c29fb5ee..15d02557 100644 --- a/vueblog/src/components/PostArticle.vue +++ b/vueblog/src/components/PostArticle.vue @@ -40,7 +40,7 @@ 保存到草稿箱 发表文章 -