'添加查询默认smtp设置'

This commit is contained in:
wenyann 2020-06-04 18:32:06 +08:00
parent 54f2fdf3ea
commit fc8cad2679
4 changed files with 65 additions and 24 deletions

View File

@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*; import org.apache.shiro.authc.*;
import org.apache.shiro.authz.UnauthorizedException; import org.apache.shiro.authz.UnauthorizedException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject; import org.apache.shiro.subject.Subject;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -94,4 +95,5 @@ public class LoginController {
return userService.getDefaultLanguage(); return userService.getDefaultLanguage();
} }
} }

View File

@ -1,11 +1,10 @@
package io.metersphere.controller; package io.metersphere.controller;
import io.metersphere.base.domain.SystemParameter; import io.metersphere.base.domain.SystemParameter;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.service.SystemParameterService; import io.metersphere.service.SystemParameterService;
import org.springframework.web.bind.annotation.PostMapping; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
@ -26,5 +25,9 @@ public class SystemParameterController {
public void testConnection(@RequestBody HashMap<String, String> hashMap) { public void testConnection(@RequestBody HashMap<String, String> hashMap) {
SystemParameterService.testConnection(hashMap); SystemParameterService.testConnection(hashMap);
} }
@GetMapping("/mail/info")
public Object mailInfo() {
return SystemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
}
} }

View File

@ -15,9 +15,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Properties;
@Service @Service
@ -83,7 +81,30 @@ public class SystemParameterService {
} catch (MessagingException e) { } catch (MessagingException e) {
MSException.throwException(Translator.get("connection_failed")); MSException.throwException(Translator.get("connection_failed"));
} }
}
public Object mailInfo(String type) {
List<SystemParameter> 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;
} }
} }

View File

@ -42,13 +42,13 @@
<!----> <!---->
<div style="border: 0px;margin-bottom: 20px;margin-top: 20px"> <div style="border: 0px;margin-bottom: 20px;margin-top: 20px">
<el-checkbox v-model="SSL" :label="$t('system_parameter_setting.SSL')"></el-checkbox> <el-checkbox v-model="formInline.SSL" :label="$t('system_parameter_setting.SSL')"></el-checkbox>
</div> </div>
<div style="border: 0px;margin-bottom: 20px"> <div style="border: 0px;margin-bottom: 20px">
<el-checkbox v-model="TLS" :label="$t('system_parameter_setting.TLS')"></el-checkbox> <el-checkbox v-model="formInline.TLS" :label="$t('system_parameter_setting.TLS')"></el-checkbox>
</div> </div>
<div style="border: 0px;margin-bottom: 20px"> <div style="border: 0px;margin-bottom: 20px">
<el-checkbox v-model="SMTP" :label="$t('system_parameter_setting.SMTP')"></el-checkbox> <el-checkbox v-model="formInline.SMTP" :label="$t('system_parameter_setting.SMTP')"></el-checkbox>
</div> </div>
<template v-slot:footer> <template v-slot:footer>
</template> </template>
@ -74,15 +74,15 @@
data() { data() {
return { return {
formInline: { formInline: {
host: 'smtp.163.com', /*host: 'smtp.163.com',
port: '465', port: '465',
account: 'xjj0608@163.com', account: 'xjj0608@163.com',
password: '2345678', password: '2345678',*/
}, },
result: {}, result: {},
SSL: false, /*SSL: [],
TLS: false, TLS: [],
SMTP: true, SMTP: [],*/
showEdit: true, showEdit: true,
showSave: false, showSave: false,
showCancel: false, showCancel: false,
@ -112,8 +112,22 @@
} }
}, },
activated() {
this.query()
},
methods: { 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() { change() {
if (!this.formInline.host || !this.formInline.port || !this.formInline.account) { if (!this.formInline.host || !this.formInline.port || !this.formInline.account) {
this.disabledConnection = true; this.disabledConnection = true;
@ -129,9 +143,9 @@
"smtp.port": this.formInline.port, "smtp.port": this.formInline.port,
"smtp.account": this.formInline.account, "smtp.account": this.formInline.account,
"smtp.password": this.formInline.password, "smtp.password": this.formInline.password,
"smtp.ssl": this.SSL, "smtp.ssl": this.formInline.SSL,
"smtp.tls": this.TLS, "smtp.tls": this.formInline.TLS,
"smtp.smtp": this.SMTP, "smtp.smtp": this.formInline.SMTP,
}; };
this.$refs[formInline].validate((valid) => { this.$refs[formInline].validate((valid) => {
if (valid) { if (valid) {
@ -154,14 +168,15 @@
this.showCancel = false; this.showCancel = false;
this.showSave = false; this.showSave = false;
this.show = true; this.show = true;
alert(this.formInline.SSL)
let param = [ let param = [
{paramKey: "smtp.host", paramValue: this.formInline.host, type: "text", sort: 1}, {paramKey: "smtp.host", paramValue: this.formInline.host, type: "text", sort: 1},
{paramKey: "smtp.port", paramValue: this.formInline.port, type: "text", sort: 2}, {paramKey: "smtp.port", paramValue: this.formInline.port, type: "text", sort: 2},
{paramKey: "smtp.account", paramValue: this.formInline.account, type: "text", sort: 3}, {paramKey: "smtp.account", paramValue: this.formInline.account, type: "text", sort: 3},
{paramKey: "smtp.password", paramValue: this.formInline.password, type: "password", sort: 4}, {paramKey: "smtp.password", paramValue: this.formInline.password, type: "password", sort: 4},
{paramKey: "smtp.ssl", paramValue: this.SSL, type: "text", sort: 5}, {paramKey: "smtp.ssl", paramValue: this.formInline.SSL, type: "text", sort: 5},
{paramKey: "smtp.tls", paramValue: this.TLS, type: "text", sort: 6}, {paramKey: "smtp.tls", paramValue: this.formInline.TLS, type: "text", sort: 6},
{paramKey: "smtp.smtp", paramValue: this.SMTP, type: "text", sort: 7} {paramKey: "smtp.smtp", paramValue: this.formInline.SMTP, type: "text", sort: 7}
] ]
this.$refs[formInline].validate(valid => { this.$refs[formInline].validate(valid => {