mirror of https://github.com/Rekoe/rk_svnadmin
邮件发送
parent
a12751e424
commit
4c7e131e65
|
@ -42,6 +42,11 @@ public class ProjectConfig implements Serializable {
|
|||
@Comment("默认初始化目录")
|
||||
private List<String> dirs;
|
||||
|
||||
@Column(hump = true)
|
||||
@Comment("是否开启邮件变更提醒")
|
||||
@Default("0")
|
||||
private boolean emailNotify;
|
||||
|
||||
public List<String> getDirs() {
|
||||
if (dirs == null) {
|
||||
this.dirs = new ArrayList<>();
|
||||
|
@ -49,6 +54,14 @@ public class ProjectConfig implements Serializable {
|
|||
return dirs;
|
||||
}
|
||||
|
||||
public boolean isEmailNotify() {
|
||||
return emailNotify;
|
||||
}
|
||||
|
||||
public void setEmailNotify(boolean emailNotify) {
|
||||
this.emailNotify = emailNotify;
|
||||
}
|
||||
|
||||
public void setDirs(List<String> dirs) {
|
||||
this.dirs = dirs;
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public class AdminProjectAct extends BaseAction {
|
|||
@RequiresPermissions({ "svn.project:conf" })
|
||||
@PermissionTag(name = "配置管理", tag = "SVN项目管理", enable = false)
|
||||
public Message conf_update(@Param("::conf.") ProjectConfig conf, HttpServletRequest req) {
|
||||
boolean isRight = projectConfigService.update(conf.getRepositoryPath(), conf.getDomainPath());
|
||||
boolean isRight = projectConfigService.update(conf);
|
||||
if (isRight) {
|
||||
return Message.success("ok", req);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
package com.rekoe.module.admin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
@ -13,14 +20,20 @@ import org.nutz.mvc.annotation.Param;
|
|||
import com.rekoe.annotation.PermissionTag;
|
||||
import com.rekoe.common.Message;
|
||||
import com.rekoe.common.page.Pagination;
|
||||
import com.rekoe.domain.ProjectConfig;
|
||||
import com.rekoe.domain.Usr;
|
||||
import com.rekoe.module.BaseAction;
|
||||
import com.rekoe.service.EmailService;
|
||||
import com.rekoe.service.ProjectConfigService;
|
||||
import com.rekoe.service.SvnUserService;
|
||||
import com.rekoe.utils.EncryptUtil;
|
||||
|
||||
@IocBean
|
||||
@At("/admin/svn/user")
|
||||
public class AdminSvnUserAct extends BaseAction {
|
||||
|
||||
private static final char[] RANDOM_ARRY_CHAR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
|
||||
|
||||
@Inject
|
||||
private SvnUserService svnUserService;
|
||||
|
||||
|
@ -53,4 +66,44 @@ public class AdminSvnUserAct extends BaseAction {
|
|||
}
|
||||
return Message.error("error", req);
|
||||
}
|
||||
|
||||
@Inject
|
||||
private EmailService emailService;
|
||||
|
||||
@Inject
|
||||
private ProjectConfigService projectConfigService;
|
||||
|
||||
/**
|
||||
* 重置账号密码
|
||||
*
|
||||
* @param usr
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
@Ok("json")
|
||||
@RequiresPermissions("svn.user:add")
|
||||
@PermissionTag(name = "SVN添加账号", tag = "SVN账号管理", enable = false)
|
||||
public Message restpwd(@Param("usr") String usr, HttpServletRequest req) {
|
||||
Usr user = svnUserService.fetch(Cnd.where("usr", "=", usr));
|
||||
if (user == null) {
|
||||
return Message.error("error.account.empty", req);
|
||||
}
|
||||
String code = RandomStringUtils.random(7, RANDOM_ARRY_CHAR);
|
||||
svnUserService.update(Chain.make("psw", EncryptUtil.encrypt(code)), Cnd.where("usr", "=", usr));
|
||||
ProjectConfig conf = projectConfigService.get();
|
||||
emailNotify(user, emailService, conf, user.getEmail(), code);
|
||||
return Message.success("ok", req);
|
||||
}
|
||||
|
||||
@Async
|
||||
private void emailNotify(Usr user, EmailService emailService, ProjectConfig conf, String to, String pwd) {
|
||||
if (conf.isEmailNotify() && Strings.isEmail(to)) {
|
||||
Map<String, Object> root = new HashMap<String, Object>();
|
||||
root.put("name", user.getName());
|
||||
root.put("pwd", pwd);
|
||||
root.put("usr", user.getUsr());
|
||||
emailService.restpwd(to, root);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
package com.rekoe.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface EmailService {
|
||||
|
||||
boolean send(String to, String subject, String html);
|
||||
public boolean send(String to, String subject, String templateFile, Map<String, Object> root);
|
||||
|
||||
/**
|
||||
* 密码重置
|
||||
*
|
||||
* @param to
|
||||
* @param root
|
||||
* @return
|
||||
*/
|
||||
public boolean restpwd(String to, Map<String, Object> root);
|
||||
|
||||
/**
|
||||
* 项目开启
|
||||
*
|
||||
* @param to
|
||||
* @param root
|
||||
* @return
|
||||
*/
|
||||
public boolean projectOpen(String to, Map<String, Object> root);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,31 +1,72 @@
|
|||
package com.rekoe.service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.mail.HtmlEmail;
|
||||
import org.nutz.ioc.Ioc;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
import org.nutz.plugins.view.freemarker.FreeMarkerConfigurer;
|
||||
|
||||
@IocBean(name="emailService")
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
|
||||
@IocBean(name = "emailService")
|
||||
public class EmailServiceImpl implements EmailService {
|
||||
|
||||
private static final Log log = Logs.get();
|
||||
|
||||
|
||||
@Inject("refer:$ioc")
|
||||
protected Ioc ioc;
|
||||
|
||||
public boolean send(String to, String subject, String html) {
|
||||
@Inject
|
||||
private Configuration configuration;
|
||||
|
||||
@Inject
|
||||
private FreeMarkerConfigurer freeMarkerConfigurer;
|
||||
|
||||
public boolean send(String to, String subject, String templateFile, Map<String, Object> root) {
|
||||
try {
|
||||
HtmlEmail email = ioc.get(HtmlEmail.class);
|
||||
email.setCharset("UTF-8");
|
||||
email.setSubject(subject);
|
||||
email.setHtmlMsg(html);
|
||||
email.setHtmlMsg(processTemplateIntoString(templateFile, root));
|
||||
email.addTo(to);
|
||||
email.send();
|
||||
String res = email.send();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(res);
|
||||
}
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
log.info("send email fail", e);
|
||||
} catch (Exception e) {
|
||||
log.error("send email fail", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private String processTemplateIntoString(String templateFile, Map<String, Object> root) {
|
||||
try {
|
||||
String path = "template" + File.separator + "admin" + File.separator + "common" + File.separator + templateFile + freeMarkerConfigurer.getSuffix();
|
||||
Template template = configuration.getTemplate(path);
|
||||
template.setEncoding("UTF-8");
|
||||
java.io.StringWriter writer = new java.io.StringWriter();
|
||||
template.process(root, writer);
|
||||
return writer.toString();
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean restpwd(String to, Map<String, Object> root) {
|
||||
return send(to, "svn-密码重置邮件<系统邮件,请勿回复>", "rest_pwd", root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean projectOpen(String to, Map<String, Object> root) {
|
||||
return send(to, "svn-项目开启邮件<系统邮件,请勿回复>", "project_open", root);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,10 @@ public class ProjectConfigService extends BaseService<ProjectConfig> {
|
|||
dao().update(conf);
|
||||
return true;
|
||||
}
|
||||
public boolean update(ProjectConfig conf) {
|
||||
dao().update(conf);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
get();
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.rekoe.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -11,12 +14,15 @@ import javax.servlet.http.HttpServletRequest;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.log.Log;
|
||||
import org.nutz.log.Logs;
|
||||
|
||||
/**
|
||||
* 工具类
|
||||
*/
|
||||
public class CommonUtils {
|
||||
|
||||
private final static Log log = Logs.get();
|
||||
/**
|
||||
* 正则表达式:验证用户名
|
||||
*/
|
||||
|
@ -153,4 +159,21 @@ public class CommonUtils {
|
|||
}
|
||||
return paramsMap;
|
||||
}
|
||||
|
||||
public static String getCurrentPath() {
|
||||
URL url = CommonUtils.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
String filePath = null;
|
||||
try {
|
||||
filePath = URLDecoder.decode(url.getPath(), "utf-8");
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
if (filePath.endsWith(".jar")) {
|
||||
filePath = filePath.substring(0, filePath.lastIndexOf("/") + 1);
|
||||
}
|
||||
File file = new File(filePath);
|
||||
filePath = file.getAbsolutePath();
|
||||
return filePath;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
${name}: 您好 <br/>
|
||||
|
||||
账号:${usr}<br/>
|
||||
密码:${pwd}<br/><br/>
|
||||
密码信息请妥善保管。系统邮件请勿回复
|
||||
</p>
|
|
@ -0,0 +1,60 @@
|
|||
<p><!--[if gte mso 9]><xml>
|
||||
<w:WordDocument>
|
||||
<w:View>Normal</w:View>
|
||||
<w:Zoom>0</w:Zoom>
|
||||
<w:PunctuationKerning />
|
||||
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
|
||||
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
|
||||
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
|
||||
<w:ValidateAgainstSchemas />
|
||||
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
|
||||
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
|
||||
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
|
||||
<w:Compatibility>
|
||||
<w:SpaceForUL />
|
||||
<w:BalanceSingleByteDoubleByteWidth />
|
||||
<w:DoNotLeaveBackslashAlone />
|
||||
<w:ULTrailSpace />
|
||||
<w:DoNotExpandShiftReturn />
|
||||
<w:AdjustLineHeightInTable />
|
||||
<w:BreakWrappedTables />
|
||||
<w:SnapToGridInCell />
|
||||
<w:WrapTextWithPunct />
|
||||
<w:UseAsianBreakRules />
|
||||
<w:DontGrowAutofit />
|
||||
<w:UseFELayout />
|
||||
</w:Compatibility>
|
||||
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
|
||||
</w:WordDocument>
|
||||
</xml><![endif]--></p>
|
||||
<p><!--[if gte mso 9]><xml>
|
||||
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
|
||||
</w:LatentStyles>
|
||||
</xml><![endif]--><!--[if gte mso 10]>
|
||||
<style>
|
||||
/* Style Definitions */
|
||||
table.MsoNormalTable
|
||||
{mso-style-name:普通表格;
|
||||
mso-tstyle-rowband-size:0;
|
||||
mso-tstyle-colband-size:0;
|
||||
mso-style-noshow:yes;
|
||||
mso-style-parent:"";
|
||||
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
|
||||
mso-para-margin:0cm;
|
||||
mso-para-margin-bottom:.0001pt;
|
||||
mso-pagination:widow-orphan;
|
||||
font-size:10.0pt;
|
||||
font-family:"Times New Roman";
|
||||
mso-fareast-font-family:"Times New Roman";
|
||||
mso-ansi-language:#0400;
|
||||
mso-fareast-language:#0400;
|
||||
mso-bidi-language:#0400;}
|
||||
</style>
|
||||
<![endif]-->
|
||||
${name}: 您好 <br/>
|
||||
|
||||
账号:${usr}<br/>
|
||||
密码:${pwd}<br/><br/>
|
||||
密码信息请妥善保管。系统邮件请勿回复
|
||||
|
||||
</p>
|
|
@ -11,10 +11,12 @@
|
|||
<div class="clear"></div>
|
||||
</div>
|
||||
<div class="body-box">
|
||||
<#assign isSend=obj.emailNotify>
|
||||
<@p.form id="jvForm" action="update" labelWidth="12" onsubmit="return false;">
|
||||
<@p.hidden id="conf.id" name="conf.id" value='${obj.id}' />
|
||||
<@p.text width="30" label="仓库路径" id="conf.repositoryPath" name="conf.repositoryPath" value="${obj.repositoryPath}" maxlength="100" class="required" required="true"/><@p.tr/>
|
||||
<@p.text width="30" label="访问url" id="conf.domainPath" name="conf.domainPath" value="${obj.domainPath}" maxlength="100" class="required" required="true"/><@p.tr/>
|
||||
<@p.radio width="50" colspan="1" label="是否发送重置密码邮件" id="conf.emailNotify" name="conf.emailNotify" value=isSend list={"true":"global.true","false":"global.false"} required="true"/><@p.tr/>
|
||||
<@p.td label="默认开启的文件夹" colspan="6">
|
||||
<table border="0" id="attachTable">
|
||||
<tr colspan="3">
|
||||
|
|
|
@ -25,7 +25,7 @@ function deleted(pj,gr){
|
|||
$.message(message);
|
||||
if (message.type == "success")
|
||||
{
|
||||
window.location.href = back;
|
||||
window.location.href = list.rk;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -8,6 +8,31 @@
|
|||
function getTableForm() {
|
||||
return document.getElementById('tableForm');
|
||||
}
|
||||
function rest(usr){
|
||||
$.dialog({
|
||||
type: "warn",
|
||||
content: '确定要充值用户密码?',
|
||||
ok: 'Ok',
|
||||
cancel: 'Cancel',
|
||||
onOk: function() {
|
||||
$.ajax({
|
||||
url: "restpwd.rk",
|
||||
type: "POST",
|
||||
data: {"usr":usr},
|
||||
dataType: "json",
|
||||
cache: false,
|
||||
success: function(message) {
|
||||
$.message(message);
|
||||
if (message.type == "success")
|
||||
{
|
||||
window.location.href = list.rk;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -30,6 +55,9 @@ function getTableForm() {
|
|||
<@p.column title="编辑" align="center">
|
||||
<a href="edit.rk?id=${user.usr}" class="pn-opt">编辑</a><#rt/>
|
||||
</@p.column><#t/>
|
||||
<@p.column title="密码重置" align="center">
|
||||
<a href="javascript:void(0);" onclick="rest('${user.usr}')" class="pn-opt">密码重置</a><#rt/>
|
||||
</@p.column><#t/>
|
||||
</@shiro.hasPermission>
|
||||
</@p.table>
|
||||
</@p.form>
|
||||
|
|
Loading…
Reference in New Issue