From fc8cad26792996d929fa2c6df7503a743d0c8d86 Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Thu, 4 Jun 2020 18:32:06 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E9=BB=98?= =?UTF-8?q?=E8=AE=A4smtp=E8=AE=BE=E7=BD=AE'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginController.java | 2 + .../controller/SystemParameterController.java | 11 +++-- .../service/SystemParameterService.java | 31 ++++++++++--- .../system/SystemParameterSetting.vue | 45 ++++++++++++------- 4 files changed, 65 insertions(+), 24 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/LoginController.java b/backend/src/main/java/io/metersphere/controller/LoginController.java index 6b01b6cfdb..5254a011a2 100644 --- a/backend/src/main/java/io/metersphere/controller/LoginController.java +++ b/backend/src/main/java/io/metersphere/controller/LoginController.java @@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; import org.apache.shiro.authz.UnauthorizedException; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.subject.Subject; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.*; @@ -94,4 +95,5 @@ public class LoginController { return userService.getDefaultLanguage(); } + } diff --git a/backend/src/main/java/io/metersphere/controller/SystemParameterController.java b/backend/src/main/java/io/metersphere/controller/SystemParameterController.java index 3dc6c620b3..5c2648aa23 100644 --- a/backend/src/main/java/io/metersphere/controller/SystemParameterController.java +++ b/backend/src/main/java/io/metersphere/controller/SystemParameterController.java @@ -1,11 +1,10 @@ package io.metersphere.controller; import io.metersphere.base.domain.SystemParameter; +import io.metersphere.commons.constants.ParamConstants; import io.metersphere.service.SystemParameterService; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; @@ -26,5 +25,9 @@ public class SystemParameterController { public void testConnection(@RequestBody HashMap hashMap) { SystemParameterService.testConnection(hashMap); } + @GetMapping("/mail/info") + public Object mailInfo() { + return SystemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue()); + } } diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index 725afb6768..b57b2ff6e2 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -15,9 +15,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.mail.MessagingException; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; +import java.util.*; @Service @@ -83,7 +81,30 @@ public class SystemParameterService { } catch (MessagingException e) { MSException.throwException(Translator.get("connection_failed")); } - - + } + public Object mailInfo(String type) { + List paramList = this.getParamList(type); + if (CollectionUtils.isEmpty(paramList)) { + paramList = new ArrayList<>(); + ParamConstants.MAIL[] values = ParamConstants.MAIL.values(); + for (ParamConstants.MAIL value : values) { + SystemParameter systemParameter = new SystemParameter(); + if (value.equals(ParamConstants.MAIL.PASSWORD)) { + systemParameter.setType(ParamConstants.Type.PASSWORD.getValue()); + } else { + systemParameter.setType(ParamConstants.Type.TEXT.getValue()); + } + systemParameter.setParamKey(value.getKey()); + systemParameter.setSort(value.getValue()); + paramList.add(systemParameter); + } + } else { + paramList.stream().filter(param -> param.getParamKey().equals(ParamConstants.MAIL.PASSWORD.getKey())).forEach(param -> { + String string = EncryptUtils.aesDecrypt(param.getParamValue()).toString(); + param.setParamValue(string); + }); + } + paramList.sort(Comparator.comparingInt(SystemParameter::getSort)); + return paramList; } } diff --git a/frontend/src/business/components/settings/system/SystemParameterSetting.vue b/frontend/src/business/components/settings/system/SystemParameterSetting.vue index e993f612a4..811a94dd84 100644 --- a/frontend/src/business/components/settings/system/SystemParameterSetting.vue +++ b/frontend/src/business/components/settings/system/SystemParameterSetting.vue @@ -42,13 +42,13 @@
- +
- +
- +
@@ -74,15 +74,15 @@ data() { return { formInline: { - host: 'smtp.163.com', + /*host: 'smtp.163.com', port: '465', account: 'xjj0608@163.com', - password: '2345678', + password: '2345678',*/ }, result: {}, - SSL: false, - TLS: false, - SMTP: true, + /*SSL: [], + TLS: [], + SMTP: [],*/ showEdit: true, showSave: false, showCancel: false, @@ -112,8 +112,22 @@ } }, - + activated() { + this.query() + }, methods: { + + query() { + this.result = this.$get("/system/mail/info", response => { + this.$set(this.formInline, "host", response.data[0].paramValue); + this.$set(this.formInline, "port", response.data[1].paramValue); + this.$set(this.formInline, "account", response.data[2].paramValue); + this.$set(this.formInline, "password", response.data[3].paramValue); + this.$set(this.formInline, "SSL", response.data[4].paramValue); + this.$set(this.formInline, "TLS", response.data[5].paramValue); + this.$set(this.formInline, "SMTP", response.data[6].paramValue); + }) + }, change() { if (!this.formInline.host || !this.formInline.port || !this.formInline.account) { this.disabledConnection = true; @@ -129,9 +143,9 @@ "smtp.port": this.formInline.port, "smtp.account": this.formInline.account, "smtp.password": this.formInline.password, - "smtp.ssl": this.SSL, - "smtp.tls": this.TLS, - "smtp.smtp": this.SMTP, + "smtp.ssl": this.formInline.SSL, + "smtp.tls": this.formInline.TLS, + "smtp.smtp": this.formInline.SMTP, }; this.$refs[formInline].validate((valid) => { if (valid) { @@ -154,14 +168,15 @@ this.showCancel = false; this.showSave = false; this.show = true; + alert(this.formInline.SSL) let param = [ {paramKey: "smtp.host", paramValue: this.formInline.host, type: "text", sort: 1}, {paramKey: "smtp.port", paramValue: this.formInline.port, type: "text", sort: 2}, {paramKey: "smtp.account", paramValue: this.formInline.account, type: "text", sort: 3}, {paramKey: "smtp.password", paramValue: this.formInline.password, type: "password", sort: 4}, - {paramKey: "smtp.ssl", paramValue: this.SSL, type: "text", sort: 5}, - {paramKey: "smtp.tls", paramValue: this.TLS, type: "text", sort: 6}, - {paramKey: "smtp.smtp", paramValue: this.SMTP, type: "text", sort: 7} + {paramKey: "smtp.ssl", paramValue: this.formInline.SSL, type: "text", sort: 5}, + {paramKey: "smtp.tls", paramValue: this.formInline.TLS, type: "text", sort: 6}, + {paramKey: "smtp.smtp", paramValue: this.formInline.SMTP, type: "text", sort: 7} ] this.$refs[formInline].validate(valid => {