xiongzhu 2 anni fa
parent
commit
54baf84d8b

+ 1 - 1
src/main/java/com/izouma/zhirongip/enums/NavAuth.java

@@ -6,7 +6,7 @@ public enum NavAuth {
      */
     ALL,
     /*
-    需要登
+    需要登
      */
     LOGIN,
     /*

+ 1 - 0
src/main/java/com/izouma/zhirongip/security/WebSecurityConfig.java

@@ -128,6 +128,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/404").permitAll()
                 .antMatchers("/500").permitAll()
                 .antMatchers("/MP_verify*").permitAll()
+                .antMatchers("/technologyProduct/top").permitAll()
                 // all other requests need to be authenticated
                 .anyRequest().authenticated().and()
                 // make sure we use stateless session; session won't be used to

+ 45 - 35
src/main/java/com/izouma/zhirongip/service/UserService.java

@@ -9,6 +9,7 @@ import com.izouma.zhirongip.domain.User;
 import com.izouma.zhirongip.dto.PageQuery;
 import com.izouma.zhirongip.dto.UserRegister;
 import com.izouma.zhirongip.enums.AuthorityName;
+import com.izouma.zhirongip.exception.AuthenticationException;
 import com.izouma.zhirongip.exception.BusinessException;
 import com.izouma.zhirongip.repo.InstitutionRepo;
 import com.izouma.zhirongip.repo.PersonalRepo;
@@ -83,8 +84,17 @@ public class UserService {
         }
     }
 
-    public User loginByPhone(String phone) {
-        return userRepo.findByPhoneAndDelFalse(phone);
+    public User loginByPhone(String phone, String code) {
+        User user = userRepo.findByPhoneAndDelFalse(phone);
+        if (user == null) {
+            throw new AuthenticationException("手机号未注册", null);
+        }
+        try {
+            smsService.verify(phone, code);
+        } catch (SmsService.SmsVerifyException e) {
+            throw new AuthenticationException("验证码错误", e);
+        }
+        return user;
     }
 
     public User loginMp(String code) throws WxErrorException {
@@ -93,17 +103,17 @@ public class UserService {
         User user = userRepo.findByOpenIdAndDelFalse(wxMpUser.getOpenId());
         if (user == null) {
             user = User.builder()
-                    .username(UUID.randomUUID().toString())
-                    .nickname(wxMpUser.getNickname())
-                    .avatar(wxMpUser.getHeadImgUrl())
-                    .sex(wxMpUser.getSexDesc())
-                    .country(wxMpUser.getCountry())
-                    .province(wxMpUser.getProvince())
-                    .city(wxMpUser.getCity())
-                    .openId(wxMpUser.getOpenId())
-                    .language(wxMpUser.getLanguage())
-                    .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
-                    .build();
+                       .username(UUID.randomUUID().toString())
+                       .nickname(wxMpUser.getNickname())
+                       .avatar(wxMpUser.getHeadImgUrl())
+                       .sex(wxMpUser.getSexDesc())
+                       .country(wxMpUser.getCountry())
+                       .province(wxMpUser.getProvince())
+                       .city(wxMpUser.getCity())
+                       .openId(wxMpUser.getOpenId())
+                       .language(wxMpUser.getLanguage())
+                       .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
+                       .build();
             userRepo.save(user);
         }
         return user;
@@ -119,12 +129,12 @@ public class UserService {
                 return userInfo;
             }
             userInfo = User.builder()
-                    .username(UUID.randomUUID().toString())
-                    .nickname("用户" + RandomStringUtils.randomAlphabetic(6))
-                    .openId(openId)
-                    .avatar(Constants.DEFAULT_AVATAR)
-                    .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
-                    .build();
+                           .username(UUID.randomUUID().toString())
+                           .nickname("用户" + RandomStringUtils.randomAlphabetic(6))
+                           .openId(openId)
+                           .avatar(Constants.DEFAULT_AVATAR)
+                           .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
+                           .build();
             userInfo = userRepo.save(userInfo);
             return userInfo;
         } catch (WxErrorException e) {
@@ -158,16 +168,16 @@ public class UserService {
         if (user == null) {
 
             user = User.builder()
-                    .username(UUID.randomUUID().toString())
-                    .nickname(wxUserInfo.getNickName())
-                    .openId(wxUserInfo.getOpenId())
-                    .avatar(avatarUrl)
-                    .sex(wxUserInfo.getGender())
-                    .country(wxUserInfo.getCountry())
-                    .province(wxUserInfo.getProvince())
-                    .city(wxUserInfo.getCity())
-                    .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
-                    .build();
+                       .username(UUID.randomUUID().toString())
+                       .nickname(wxUserInfo.getNickName())
+                       .openId(wxUserInfo.getOpenId())
+                       .avatar(avatarUrl)
+                       .sex(wxUserInfo.getGender())
+                       .country(wxUserInfo.getCountry())
+                       .province(wxUserInfo.getProvince())
+                       .city(wxUserInfo.getCity())
+                       .authorities(Collections.singleton(Authority.builder().name("ROLE_USER").build()))
+                       .build();
             user = userRepo.save(user);
 
         } else {
@@ -206,12 +216,12 @@ public class UserService {
 
         String phone1 = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
         User user = User.builder()
-                .phone(phone)
-                .username(phone)
-                .nickname("用户" + phone1)
-                .password(new BCryptPasswordEncoder().encode(password))
-                .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
-                .build();
+                        .phone(phone)
+                        .username(phone)
+                        .nickname("用户" + phone1)
+                        .password(new BCryptPasswordEncoder().encode(password))
+                        .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
+                        .build();
         return userRepo.save(user);
     }
 

+ 6 - 5
src/main/java/com/izouma/zhirongip/web/AuthenticationController.java

@@ -57,13 +57,14 @@ public class AuthenticationController {
 
     @PostMapping("/phoneLogin")
     @ApiOperation(value = "手机号登录")
-    public String phoneLogin(String phone) {
+    public String phoneLogin(String phone, String code) {
         try {
-            User user = userService.loginByPhone(phone);
+            User user = userService.loginByPhone(phone, code);
             return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
         } catch (Exception e) {
             log.error("loginByPhone", e);
-            throw new AuthenticationException("登陆错误", e);
+            if (e instanceof AuthenticationException) throw e;
+            throw new AuthenticationException("登录错误", e);
         }
     }
 
@@ -75,7 +76,7 @@ public class AuthenticationController {
             return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
         } catch (Exception e) {
             log.error("loginByCode", e);
-            throw new AuthenticationException("登错误", e);
+            throw new AuthenticationException("登错误", e);
         }
     }
 
@@ -87,7 +88,7 @@ public class AuthenticationController {
             return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
         } catch (Exception e) {
             log.error("loginByCode", e);
-            throw new AuthenticationException("登错误", e);
+            throw new AuthenticationException("登错误", e);
         }
     }
 

+ 2 - 2
src/main/vue/src/views/Login.vue

@@ -23,7 +23,7 @@
             <div class="login-wrapper" @keyup.enter="login" v-else key="login">
                 <div class="title">欢迎登录</div>
                 <el-tabs v-model="activeName" stretch class="tab-list">
-                    <el-tab-pane label="用户名登" name="first">
+                    <el-tab-pane label="用户名登" name="first">
                         <el-form :model="userInfo" style="width: 350px;" ref="form">
                             <el-form-item
                                 prop="username"
@@ -55,7 +55,7 @@
                             </el-form-item>
                         </el-form>
                     </el-tab-pane>
-                    <el-tab-pane label="验证码登" name="second">
+                    <el-tab-pane label="验证码登" name="second">
                         <el-form :model="userInfo" style="width: 350px;" ref="form2">
                             <el-form-item
                                 prop="phone"

+ 2 - 2
src/main/vue/src/views/Navigations.vue

@@ -95,8 +95,8 @@ export default {
             edit: false,
             expandKeys: [],
             authorities: [
-                { label: '不需要登', value: 'ALL' },
-                { label: '需要登', value: 'LOGIN' },
+                { label: '不需要登', value: 'ALL' },
+                { label: '需要登', value: 'LOGIN' },
                 { label: '仅个人认证用户', value: 'PERSONAL' },
                 { label: '仅企业认证用户', value: 'COMPANY' },
                 { label: '个人和企业认证用户', value: 'PERSONAL_COMPANY' }

+ 1 - 1
src/main/zhi-rong-web/src/components/PageHeader.vue

@@ -18,7 +18,7 @@
                         快速注册
                     </div>
                     <div class="header_top_login" @click.prevent="$refs.registrationReset.login = true" v-if="!isLogin">
-                        立即登
+                        立即登
                     </div>
                     <div class="btn-list" v-if="isLogin">
                         <el-dropdown @command="onCommand" style="margin-right: 10px" trigger="click">

+ 11 - 21
src/main/zhi-rong-web/src/components/popup/Agreement2.vue

@@ -134,34 +134,24 @@ export default {
                 if (valid) {
                     this.loading = true;
                     this.$http
-                        .get('/sms/verify', {
+                        .post('/auth/phoneLogin', {
                             phone: this.form.phone,
                             code: this.form.code
                         })
                         .then(res => {
+                            this.loading = false;
                             localStorage.setItem('webToken', res);
-                            this.$http
-                                .post('/auth/phoneLogin', {
-                                    phone: this.form.phone,
-                                    code: this.form.code
-                                })
-                                .then(res => {
-                                    localStorage.setItem('webToken', res);
-                                    this.$message.warning('登录成功');
-                                    this.$store.dispatch('getUserInfo');
-                                    this.login = false;
+                            this.$message.warning('登录成功');
+                            this.$store.dispatch('getUserInfo');
+                            this.login = false;
 
-                                    // this.$router.replace('/');
-                                })
-                                .catch(e => {
-                                    this.loading = false;
-                                    if (e) {
-                                        this.$message.error(e.error);
-                                    }
-                                });
+                            // this.$router.replace('/');
                         })
                         .catch(e => {
-                            this.$message.error(e.error);
+                            this.loading = false;
+                            if (e) {
+                                this.$message.error(e.error);
+                            }
                         });
                 }
             });
@@ -333,7 +323,7 @@ export default {
 .code2 {
     width: 100px;
     height: 34px;
-  	background: #c8c9cc;
+    background: #c8c9cc;
     border-radius: 4px;
     font-size: 13px;
     font-weight: 400;

+ 11 - 21
src/main/zhi-rong-web/src/components/popup/registrationReset.vue

@@ -136,33 +136,23 @@ export default {
                 if (valid) {
                     this.loading = true;
                     this.$http
-                        .get('/sms/verify', {
+                        .post('/auth/phoneLogin', {
                             phone: this.form.phone,
                             code: this.form.code
                         })
                         .then(res => {
+                            this.loading = false;
                             localStorage.setItem('webToken', res);
-                            this.$http
-                                .post('/auth/phoneLogin', {
-                                    phone: this.form.phone,
-                                    code: this.form.code
-                                })
-                                .then(res => {
-                                    localStorage.setItem('webToken', res);
-                                    this.$message.warning('登录成功');
-                                    this.$store.dispatch('getUserInfo');
-                                    this.login = false;
-                                    // this.$router.replace('/');
-                                })
-                                .catch(e => {
-                                    this.loading = false;
-                                    if (e) {
-                                        this.$message.error(e.error);
-                                    }
-                                });
+                            this.$message.warning('登录成功');
+                            this.$store.dispatch('getUserInfo');
+                            this.login = false;
+                            // this.$router.replace('/');
                         })
                         .catch(e => {
-                            this.$message.error(e.error);
+                            this.loading = false;
+                            if (e) {
+                                this.$message.error(e.error);
+                            }
                         });
                 }
             });
@@ -335,7 +325,7 @@ export default {
 .code2 {
     width: 100px;
     height: 34px;
-  	background: #c8c9cc;
+    background: #c8c9cc;
     border-radius: 4px;
     font-size: 13px;
     font-weight: 400;

+ 8 - 6
src/main/zhi-rong-web/src/plugins/http.js

@@ -7,9 +7,9 @@ switch (process.env.NODE_ENV) {
         baseUrl = 'http://yangzhouip.izouma.com';
         // baseUrl = 'https://www.bxgxzc.com';
         // baseUrl = '/www.bxgxzc.com';
-        // baseUrl = 'http://192.168.50.190:8080'; 
-        //  baseUrl = 'http://localhost:8080';
-        // baseUrl = 'http://192.168.50.190:8080'; 
+        // baseUrl = 'http://192.168.50.190:8080';
+        baseUrl = 'http://localhost:8080';
+        // baseUrl = 'http://192.168.50.190:8080';
         break;
     case 'test':
         baseUrl = 'http://localhost:8080';
@@ -76,9 +76,11 @@ const http = {
         return new Promise((resolve, reject) => {
             axiosInstance
                 .get(
-                    url, {
+                    url,
+                    {
                         params: params
-                    }, {
+                    },
+                    {
                         withCredentials: true
                     }
                 )
@@ -120,4 +122,4 @@ export default {
         _Vue.prototype.$axios = axiosInstance;
         _Vue.prototype.$http = http;
     }
-};
+};

+ 13 - 22
src/main/zhi-rong-web/src/views/Login.vue

@@ -168,32 +168,22 @@ export default {
                 if (valid) {
                     this.loading = true;
                     this.$http
-                        .get('/sms/verify', {
+                        .post('/auth/phoneLogin', {
                             phone: this.form.phone,
                             code: this.form.code
                         })
                         .then(res => {
+                            this.loading = false;
                             localStorage.setItem('webToken', res);
-                            this.$http
-                                .post('/auth/phoneLogin', {
-                                    phone: this.form.phone,
-                                    code: this.form.code
-                                })
-                                .then(res => {
-                                    localStorage.setItem('webToken', res);
-                                    this.$message.warning('登录成功');
-                                    this.$store.dispatch('getUserInfo');
-                                    this.$router.replace('/');
-                                })
-                                .catch(e => {
-                                    this.loading = false;
-                                    if (e) {
-                                        this.$message.error(e.error);
-                                    }
-                                });
+                            this.$message.warning('登录成功');
+                            this.$store.dispatch('getUserInfo');
+                            this.$router.replace('/');
                         })
                         .catch(e => {
-                            this.$message.error(e.error);
+                            this.loading = false;
+                            if (e) {
+                                this.$message.error(e.error);
+                            }
                         });
                 }
             });
@@ -382,7 +372,7 @@ export default {
 .forgot_password {
     font-size: 12px;
     font-weight: 400;
-    color: #405CFF;
+    color: #405cff;
     line-height: 17px;
     margin-left: 330px;
     margin-top: 10px;
@@ -395,7 +385,7 @@ export default {
     .btn_one {
         width: 330px;
         height: 40px;
-        background: #405CFF;
+        background: #405cff;
         border-radius: 4px;
         font-size: 12px;
         font-weight: bold;
@@ -438,7 +428,7 @@ export default {
 .code2 {
     width: 100px;
     height: 34px;
-    background: #405CFF;
+    background: #405cff;
     border-radius: 4px;
     font-size: 13px;
     font-weight: 400;
@@ -447,3 +437,4 @@ export default {
     cursor: pointer;
 }
 </style>
+