Commit c22e97fc4e7c311d235088220c903bdeb00eaeee
1 parent
a7dbf215
系统认证相关代码提交
Signed-off-by: TanYibin <5491541@qq.com>
Showing
9 changed files
with
68 additions
and
217 deletions
ant-design-vue-jeecg/src/config/router.config.js
... | ... | @@ -323,7 +323,7 @@ export const constantRouterMap = [ |
323 | 323 | { |
324 | 324 | path: 'systemTokenModal', |
325 | 325 | name: 'systemTokenModal', |
326 | - component: () => import(/* webpackChunkName: "user" */ '@/views/user/modules/SystemTokenModal') | |
326 | + component: () => import(/* webpackChunkName: "user" */ '@/views/user/modules/SystemActivationModal') | |
327 | 327 | }, |
328 | 328 | ] |
329 | 329 | }, |
... | ... |
ant-design-vue-jeecg/src/views/user/LoginAccount.vue
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | <script> |
34 | 34 | import Vue from 'vue' |
35 | 35 | import {getAction} from '@/api/manage' |
36 | -import SystemTokenModal from './modules/SystemTokenModal' | |
36 | +import SystemActivationModal from './modules/SystemActivationModal' | |
37 | 37 | import {mapActions} from 'vuex' |
38 | 38 | import {getWarehouseByUserCode} from '@/api/api' |
39 | 39 | |
... | ... |
ant-design-vue-jeecg/src/views/user/modules/SystemTokenModal.vue renamed to ant-design-vue-jeecg/src/views/user/modules/SystemActivationModal.vue
1 | 1 | <template> |
2 | 2 | <div class="main"> |
3 | - <a-form-model class="user-layout-login" @keyup.enter.native="handleSubmit"> | |
3 | + <a-form-model class="user-layout-login" @keyup.enter.native="handleSubmit" :rules="validatorRules"> | |
4 | 4 | <a-tabs :activeKey="customActiveKey" :tabBarStyle="{ textAlign: 'center', borderBottom: 'unset' }" @change="handleTabClick"> |
5 | - <a-tab-pane key="tab1" tab="授权 TOKEN"> | |
5 | + <a-tab-pane key="tab1" tab="激活码授权"> | |
6 | 6 | <!-- <login-account ref="alogin" @validateFail="validateFail" @success="requestSuccess" @fail="requestFailed"></login-account> --> |
7 | 7 | </a-tab-pane> |
8 | 8 | <!-- <a-tab-pane key="tab2" tab="手机号登录"> |
... | ... | @@ -10,7 +10,7 @@ |
10 | 10 | </a-tab-pane> --> |
11 | 11 | </a-tabs> |
12 | 12 | <a-form-model-item> |
13 | - <a-input size="large" v-model="model.password" autocomplete="false" placeholder="请输入授权 TOKEN"/> | |
13 | + <a-input size="large" v-model="model.activationCode" autocomplete="false" placeholder="请输入激活码"/> | |
14 | 14 | </a-form-model-item> |
15 | 15 | <a-form-item style="margin-top:24px"> |
16 | 16 | <a-button size="large" type="primary" htmlType="submit" class="login-button" :loading="loginBtn" @click.stop.prevent="handleSubmit" :disabled="loginBtn">确定 |
... | ... | @@ -30,12 +30,10 @@ import {ACCESS_TOKEN, ENCRYPTED_STRING} from '@/store/mutation-types' |
30 | 30 | import TwoStepCaptcha from '@/components/tools/TwoStepCaptcha' |
31 | 31 | import {getEncryptedString} from '@/utils/encryption/aesEncrypt' |
32 | 32 | import {timeFix} from '@/utils/util' |
33 | -import SystemTokenForm from './SystemTokenForm' | |
34 | 33 | |
35 | 34 | export default { |
36 | 35 | components: { |
37 | - TwoStepCaptcha, | |
38 | - SystemTokenForm | |
36 | + TwoStepCaptcha | |
39 | 37 | }, |
40 | 38 | data() { |
41 | 39 | return { |
... | ... | @@ -50,8 +48,14 @@ export default { |
50 | 48 | iv: "", |
51 | 49 | }, |
52 | 50 | model: { |
53 | - password: '' | |
51 | + activationCode: '' | |
54 | 52 | }, |
53 | + | |
54 | + validatorRules: { | |
55 | + activationCode: [{ | |
56 | + required: true, message: '请输入激活码', validator: 'click' | |
57 | + }] | |
58 | + } | |
55 | 59 | } |
56 | 60 | }, |
57 | 61 | created() { |
... | ... | @@ -75,11 +79,32 @@ export default { |
75 | 79 | } |
76 | 80 | }) |
77 | 81 | }, |
82 | + // 验证字段 | |
83 | + validateFields(arr, callback) { | |
84 | + let promiseArray = [] | |
85 | + for (let item of arr) { | |
86 | + let p = new Promise((resolve, reject) => { | |
87 | + this.$refs['form'].validateField(item, (err) => { | |
88 | + if (!err) { | |
89 | + resolve(); | |
90 | + } else { | |
91 | + reject(err); | |
92 | + } | |
93 | + }) | |
94 | + }); | |
95 | + promiseArray.push(p) | |
96 | + } | |
97 | + Promise.all(promiseArray).then(() => { | |
98 | + callback() | |
99 | + }).catch(err => { | |
100 | + callback(err) | |
101 | + }) | |
102 | + }, | |
78 | 103 | //登录 |
79 | 104 | handleSubmit() { |
80 | 105 | this.loginBtn = true; |
81 | 106 | console.log('handleSubmit start') |
82 | - this.handleLogin(this.rememberMe) | |
107 | + this.handleSystemActivation(this.rememberMe) | |
83 | 108 | }, |
84 | 109 | // 校验失败 |
85 | 110 | validateFail() { |
... | ... | @@ -114,16 +139,16 @@ export default { |
114 | 139 | description: `${timeFix()},欢迎回来`, |
115 | 140 | }); |
116 | 141 | }, |
117 | - insertTokenSuccess() { | |
142 | + systemActivationSuccess() { | |
118 | 143 | this.$router.push({path: "/user/login"}); |
119 | 144 | this.$notification.success({ |
120 | - message: '验证成功,请重新登录', | |
145 | + message: '激活成功,请重新登录', | |
121 | 146 | // description: `${timeFix()},欢迎回来`, |
122 | 147 | }); |
123 | 148 | }, |
124 | - insertTokenError() { | |
149 | + systemActivationSuccessError() { | |
125 | 150 | this.$notification.error({ |
126 | - message: '验证失败,请重新输入', | |
151 | + message: '激活失败,请重新输入', | |
127 | 152 | // description: `${timeFix()},欢迎回来`, |
128 | 153 | }); |
129 | 154 | this.loginBtn = false; |
... | ... | @@ -148,13 +173,13 @@ export default { |
148 | 173 | this.encryptedString = encryptedString; |
149 | 174 | } |
150 | 175 | }, |
151 | - handleLogin(rememberMe) { | |
176 | + handleSystemActivation(rememberMe) { | |
152 | 177 | console.log('handleLogin start') |
153 | 178 | let loginParams = { |
154 | - password: this.model.password, | |
179 | + activationCode: this.model.activationCode, | |
155 | 180 | } |
156 | - // this.insertTokenSuccess(); | |
157 | - this.insertTokenError(); | |
181 | + // this.systemActivationSuccess(); | |
182 | + this.systemActivationSuccessError(); | |
158 | 183 | // this.loginSelectOk(); |
159 | 184 | // this.Login(loginParams).then((res) => { |
160 | 185 | // this.$emit('success', res.result) |
... | ... |
ant-design-vue-jeecg/src/views/user/modules/SystemTokenForm.vue deleted
1 | -<template> | |
2 | - <div> | |
3 | - <a-form-model ref="form" :model="model" :rules="validatorRules"> | |
4 | - <a-form-model-item required prop="username"> | |
5 | - <a-input v-model="model.username" size="large" placeholder="请输入帐户名 / admin" @blur="getWarehouse"> | |
6 | - <a-icon slot="prefix" type="user" :style="{ color: 'rgba(0,0,0,.25)' }"/> | |
7 | - </a-input> | |
8 | - </a-form-model-item> | |
9 | - <a-form-model-item required prop="password"> | |
10 | - <a-input v-model="model.password" size="large" type="password" autocomplete="false" | |
11 | - placeholder="请输入密码 / 123456"> | |
12 | - <a-icon slot="prefix" type="lock" :style="{ color: 'rgba(0,0,0,.25)' }"/> | |
13 | - </a-input> | |
14 | - </a-form-model-item> | |
15 | - | |
16 | - <a-form-model-item prop="warehouseCode"> | |
17 | - <a-select | |
18 | - show-search | |
19 | - placeholder="请选择仓库" | |
20 | - option-filter-prop="label" | |
21 | - v-model="model.warehouseCode"> | |
22 | - <a-select-option v-for="item in warehouseList" :key="item.name" :value="item.code">{{ | |
23 | - item.name | |
24 | - }} | |
25 | - </a-select-option> | |
26 | - </a-select> | |
27 | - </a-form-model-item> | |
28 | - | |
29 | - </a-form-model> | |
30 | - </div> | |
31 | -</template> | |
32 | - | |
33 | -<script> | |
34 | -import {getAction} from '@/api/manage' | |
35 | -import Vue from 'vue' | |
36 | -import {mapActions} from 'vuex' | |
37 | -import {getWarehouseByUserCode} from '@/api/api' | |
38 | - | |
39 | -export default { | |
40 | - name: 'SystemTokenForm', | |
41 | - data() { | |
42 | - return { | |
43 | - requestCodeSuccess: false, | |
44 | - randCodeImage: '', | |
45 | - currdatetime: '', | |
46 | - loginType: 0, | |
47 | - warehouseList: {}, | |
48 | - querySource: {}, | |
49 | - model: { | |
50 | - username: '', | |
51 | - password: '', | |
52 | - warehouseCode: '', | |
53 | - // inputCode: '' | |
54 | - }, | |
55 | - validatorRules: { | |
56 | - username: [ | |
57 | - {required: true, message: '请输入用户名!'}, | |
58 | - {validator: this.handleUsernameOrEmail} | |
59 | - ], | |
60 | - password: [{ | |
61 | - required: true, message: '请输入密码!', validator: 'click' | |
62 | - }], | |
63 | - warehouseCode: [{ | |
64 | - required: true, message: '请选择仓库!', trigger: "change" , validator: 'click' | |
65 | - }], | |
66 | - } | |
67 | - } | |
68 | - }, | |
69 | - created() { | |
70 | - this.handleChangeCheckCode(); | |
71 | - this.getWarehouse(); | |
72 | - }, | |
73 | - | |
74 | - methods: { | |
75 | - ...mapActions(['Login']), | |
76 | - /**刷新验证码*/ | |
77 | - handleChangeCheckCode() { | |
78 | - this.currdatetime = new Date().getTime(); | |
79 | - // this.model.inputCode = '' | |
80 | - getAction(`/sys/randomImage/${this.currdatetime}`).then(res => { | |
81 | - if (res.success) { | |
82 | - this.randCodeImage = res.result | |
83 | - this.requestCodeSuccess = true | |
84 | - } else { | |
85 | - this.$message.error(res.message) | |
86 | - this.requestCodeSuccess = false | |
87 | - } | |
88 | - }).catch(() => { | |
89 | - this.requestCodeSuccess = false | |
90 | - }) | |
91 | - }, | |
92 | - | |
93 | - getWarehouse() { | |
94 | - const that = this; | |
95 | - this.querySource.username = that.model.username; | |
96 | - let obj = getWarehouseByUserCode(that.querySource); | |
97 | - obj.then((res) => { | |
98 | - that.warehouseList = res.result; | |
99 | - if (this.warehouseList != null) { | |
100 | - this.model.warehouseCode = this.warehouseList[0].code; | |
101 | - } | |
102 | - }) | |
103 | - }, | |
104 | - | |
105 | - // 判断登录类型 | |
106 | - handleUsernameOrEmail(rule, value, callback) { | |
107 | - const regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/; | |
108 | - if (regex.test(value)) { | |
109 | - this.loginType = 0 | |
110 | - } else { | |
111 | - this.loginType = 1 | |
112 | - } | |
113 | - callback() | |
114 | - }, | |
115 | - /** | |
116 | - * 验证字段 | |
117 | - * @param arr | |
118 | - * @param callback | |
119 | - */ | |
120 | - validateFields(arr, callback) { | |
121 | - let promiseArray = [] | |
122 | - for (let item of arr) { | |
123 | - let p = new Promise((resolve, reject) => { | |
124 | - this.$refs['form'].validateField(item, (err) => { | |
125 | - if (!err) { | |
126 | - resolve(); | |
127 | - } else { | |
128 | - reject(err); | |
129 | - } | |
130 | - }) | |
131 | - }); | |
132 | - promiseArray.push(p) | |
133 | - } | |
134 | - Promise.all(promiseArray).then(() => { | |
135 | - callback() | |
136 | - }).catch(err => { | |
137 | - callback(err) | |
138 | - }) | |
139 | - }, | |
140 | - acceptUsername(username) { | |
141 | - this.model['username'] = username | |
142 | - }, | |
143 | - // 账号密码登录 | |
144 | - handleLogin(rememberMe) { | |
145 | - this.validateFields(['username', 'password'], (err) => { | |
146 | - if (!err) { | |
147 | - let loginParams = { | |
148 | - username: this.model.username, | |
149 | - password: this.model.password, | |
150 | - warehouseCode: this.model.warehouseCode, | |
151 | - checkKey: this.currdatetime, | |
152 | - remember_me: rememberMe, | |
153 | - } | |
154 | - this.Login(loginParams).then((res) => { | |
155 | - this.$emit('success', res.result) | |
156 | - }).catch((err) => { | |
157 | - console.log(">>>>>>>>>err.message:", err.message) | |
158 | - this.$emit('fail', err) | |
159 | - this.$router.push({path: "/user/systemTokenModal"}).catch(() => { | |
160 | - | |
161 | - }) | |
162 | - }); | |
163 | - } else { | |
164 | - this.$emit('validateFail') | |
165 | - } | |
166 | - }) | |
167 | - } | |
168 | - } | |
169 | -} | |
170 | -</script> | |
171 | - | |
172 | -<style scoped> | |
173 | - | |
174 | -</style> | |
175 | 0 | \ No newline at end of file |
huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/LoginController.java
... | ... | @@ -162,7 +162,7 @@ public class LoginController { |
162 | 162 | result.error500("请选择仓库编码"); |
163 | 163 | return result; |
164 | 164 | } |
165 | -// result = HuahengJwtUtil.checkSystemToken(); | |
165 | +// result = HuahengJwtUtil.checkSystemActivationCode(); | |
166 | 166 | // if (!result.isSuccess()) { |
167 | 167 | // return result; |
168 | 168 | // } |
... | ... | @@ -178,12 +178,12 @@ public class LoginController { |
178 | 178 | return result; |
179 | 179 | } |
180 | 180 | |
181 | - @ApiOperation("系统认证API") | |
182 | - @RequestMapping(value = "/systemAuthentication", method = RequestMethod.POST) | |
181 | + @ApiOperation("系统激活API") | |
182 | + @RequestMapping(value = "/systemActivation", method = RequestMethod.POST) | |
183 | 183 | public Result<JSONObject> systemAuthentication(@RequestBody SystemAuthenticationModel systemAuthenticationModel) throws IOException { |
184 | 184 | Result<JSONObject> result = new Result<JSONObject>(); |
185 | - if (StringUtils.isEmpty(systemAuthenticationModel.getToken())) { | |
186 | - result.error500("请输入TOKEN"); | |
185 | + if (StringUtils.isEmpty(systemAuthenticationModel.getActivationCode())) { | |
186 | + result.error500("请输入激活码"); | |
187 | 187 | return result; |
188 | 188 | } |
189 | 189 | FileOutputStream outputStream = null; |
... | ... | @@ -191,25 +191,24 @@ public class LoginController { |
191 | 191 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); |
192 | 192 | JWTVerifier verifier = |
193 | 193 | JWT.require(algorithm).withClaim("operator", HuahengJwtUtil.HUAHENG_SYSTEM_ID).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); |
194 | - DecodedJWT jwt = verifier.verify(systemAuthenticationModel.getToken()); | |
194 | + DecodedJWT jwt = verifier.verify(systemAuthenticationModel.getActivationCode()); | |
195 | 195 | new ApiAuthentication.ApiAuthenticationBuild().operator(jwt.getClaim("operator").asString()).audience(jwt.getAudience().get(0)).issuer(jwt.getIssuer()) |
196 | 196 | .issuedAt(jwt.getIssuedAt()).expireDateTime(jwt.getExpiresAt()).bulid(); |
197 | 197 | |
198 | - String path = System.getProperties().getProperty("user.dir") + "\\SystemToken.txt"; | |
199 | - File file = new File(path); | |
198 | + // 验证通过写入文件 | |
199 | + File file = new File(System.getProperties().getProperty("user.dir") + File.separatorChar + HuahengJwtUtil.SYSTEM_ACTIVATION_CODE_FILE_NAME); | |
200 | 200 | outputStream = new FileOutputStream(file, false); |
201 | - FileCopyUtils.copy(systemAuthenticationModel.getToken().getBytes(), outputStream); | |
202 | - | |
201 | + FileCopyUtils.copy(systemAuthenticationModel.getActivationCode().getBytes(), outputStream); | |
203 | 202 | } catch (JWTVerificationException e) { |
204 | 203 | log.error(e.getMessage()); |
205 | - result.error500("认证失败"); | |
204 | + result.error500("激活失败"); | |
206 | 205 | return result; |
207 | 206 | } finally { |
208 | 207 | if (outputStream != null) { |
209 | 208 | outputStream.close(); |
210 | 209 | } |
211 | 210 | } |
212 | - result.setMessage("认证成功"); | |
211 | + result.setMessage("激活成功"); | |
213 | 212 | return result; |
214 | 213 | } |
215 | 214 | |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/modules/api/controller/SystemAPIController.java renamed to huaheng-wms-core/src/main/java/org/jeecg/modules/system/controller/SystemAPIController.java
huaheng-wms-core/src/main/java/org/jeecg/modules/system/model/SystemAuthenticationModel.java
... | ... | @@ -13,7 +13,7 @@ import lombok.Data; |
13 | 13 | @ApiModel(value = "系统认证对象", description = "系统认证对象") |
14 | 14 | public class SystemAuthenticationModel { |
15 | 15 | |
16 | - @ApiModelProperty(value = "TOKEN") | |
17 | - private String token; | |
16 | + @ApiModelProperty(value = "ActivationCode") | |
17 | + private String activationCode; | |
18 | 18 | |
19 | 19 | } |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/utils/HuahengJwtUtil.java
... | ... | @@ -55,6 +55,8 @@ public class HuahengJwtUtil { |
55 | 55 | |
56 | 56 | /** 全仓CODE */ |
57 | 57 | public static final String ALL_WAREHOUSE_CODE = "ALL_WAREHOUSE"; |
58 | + | |
59 | + public static final String SYSTEM_ACTIVATION_CODE_FILE_NAME = "ActivationCode.txt"; | |
58 | 60 | |
59 | 61 | /** |
60 | 62 | * 根据request中的token获取用户账号 |
... | ... | @@ -264,29 +266,28 @@ public class HuahengJwtUtil { |
264 | 266 | } |
265 | 267 | } |
266 | 268 | |
267 | - public static Result<JSONObject> checkSystemToken() throws IOException { | |
269 | + public static Result<JSONObject> checkSystemActivationCode() throws IOException { | |
268 | 270 | Result<JSONObject> result = new Result<JSONObject>(); |
269 | 271 | InputStream inputStream = null; |
270 | 272 | try { |
271 | - String path = System.getProperties().getProperty("user.dir") + "\\SystemToken.txt"; | |
272 | - File file = new File(path); | |
273 | + File file = new File(System.getProperties().getProperty("user.dir") + File.separatorChar + SYSTEM_ACTIVATION_CODE_FILE_NAME); | |
273 | 274 | inputStream = new FileInputStream(file); |
274 | - String systemToken = IOUtils.toString(inputStream, "utf-8"); | |
275 | - | |
275 | + // 获得激活码 | |
276 | + String activationCode = IOUtils.toString(inputStream, "utf-8"); | |
276 | 277 | Algorithm algorithm = Algorithm.RSA256(new SystemRSA256Key().getPublicKey(), new SystemRSA256Key().getPrivateKey()); |
277 | 278 | JWTVerifier verifier = |
278 | 279 | JWT.require(algorithm).withClaim("operator", HuahengJwtUtil.HUAHENG_SYSTEM_ID).withIssuer(HuahengJwtUtil.HUAHENG_SYSTEM_ID).build(); |
279 | - DecodedJWT jwt = verifier.verify(systemToken); | |
280 | + DecodedJWT jwt = verifier.verify(activationCode); | |
280 | 281 | new ApiAuthentication.ApiAuthenticationBuild().operator(jwt.getClaim("operator").asString()).audience(jwt.getAudience().get(0)).issuer(jwt.getIssuer()) |
281 | 282 | .issuedAt(jwt.getIssuedAt()).expireDateTime(jwt.getExpiresAt()).bulid(); |
282 | 283 | } catch (TokenExpiredException e) { |
283 | 284 | result.setSuccess(false); |
284 | 285 | result.setCode(499); |
285 | - result.setMessage("系统授权期限已过期"); | |
286 | + result.setMessage("系统激活码使用期限已到期"); | |
286 | 287 | } catch (Exception e) { |
287 | 288 | result.setSuccess(false); |
288 | 289 | result.setCode(499); |
289 | - result.setMessage("系统授权TOKEN无效"); | |
290 | + result.setMessage("系统激活码无效"); | |
290 | 291 | } finally { |
291 | 292 | if (inputStream != null) { |
292 | 293 | inputStream.close(); |
... | ... |
huaheng-wms-core/src/main/java/org/jeecg/utils/support/SystemRSA256Key.java
... | ... | @@ -12,12 +12,12 @@ import lombok.Data; |
12 | 12 | @Component |
13 | 13 | public class SystemRSA256Key { |
14 | 14 | |
15 | - /** 第三方HTTP访问 公钥 */ | |
15 | + /** 系统激活码公钥 */ | |
16 | 16 | private RSAPublicKey publicKey = |
17 | 17 | (RSAPublicKey)SecretKeyUtils.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCdEKYyMFZJpE0t+37vOhMRJ0AV2JQRP9k0qAn5wHejNl7a12mrQSYPi" |
18 | 18 | + "riOEvR9wlQJBDy/cakSbN7G1s4jVyVv/9RTl7RMMzNlh3q6yspHR2CNE2aAsAxJx2xDyJb7Yq3xAbdfVMCjkufbonhMm2i21oaS5p9vLWHRMoEODbIFBwIDAQAB"); |
19 | 19 | |
20 | - /** 第三方HTTP访问 私钥 */ | |
20 | + /** 系统激活码私钥 */ | |
21 | 21 | private RSAPrivateKey privateKey = |
22 | 22 | (RSAPrivateKey)SecretKeyUtils.getPrivateKey("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJ0QpjIwVkmkTS37fu86ExEnQBXYlBE/2TSoCfnAd6M" |
23 | 23 | + "2XtrXaatBJg+KuI4S9H3CVAkEPL9xqRJs3sbWziNXJW//1FOXtEwzM2WHerrKykdHYI0TZoCwDEnHbEPIlvtirfEBt19UwKOS59uieEybaLbWhpLmn28tYdEygQ4NsgUH" |
... | ... |