From 4d0fb614476e1ca8799238a855080601d1134b49 Mon Sep 17 00:00:00 2001 From: biezhi Date: Tue, 3 May 2016 11:41:20 +0800 Subject: [PATCH] add resend mail active users --- src/main/java/com/javachina/Types.java | 3 +- .../controller/admin/IndexController.java | 9 + .../javachina/service/ActivecodeService.java | 2 + .../service/impl/ActivecodeServiceImpl.java | 28 ++ .../service/impl/SendMailServiceImpl.java | 6 +- .../webapp/WEB-INF/views/admin/users.html | 163 +++++----- src/main/webapp/assets/scripts/admin.js | 306 +++++++++--------- 7 files changed, 287 insertions(+), 230 deletions(-) diff --git a/src/main/java/com/javachina/Types.java b/src/main/java/com/javachina/Types.java index 076f140..aae0ffb 100644 --- a/src/main/java/com/javachina/Types.java +++ b/src/main/java/com/javachina/Types.java @@ -28,6 +28,7 @@ public enum Types { allow_signup, forgot, sinks, - topic_sinks + topic_sinks, + resend } \ No newline at end of file diff --git a/src/main/java/com/javachina/controller/admin/IndexController.java b/src/main/java/com/javachina/controller/admin/IndexController.java index 9df54e0..1767dd5 100644 --- a/src/main/java/com/javachina/controller/admin/IndexController.java +++ b/src/main/java/com/javachina/controller/admin/IndexController.java @@ -21,6 +21,7 @@ import com.javachina.controller.BaseController; import com.javachina.model.Node; import com.javachina.model.User; +import com.javachina.service.ActivecodeService; import com.javachina.service.NodeService; import com.javachina.service.SettingsService; import com.javachina.service.TopicService; @@ -43,6 +44,9 @@ public class IndexController extends BaseController { @Inject private SettingsService settingsService; + @Inject + private ActivecodeService activecodeService; + /** * 首页 */ @@ -229,6 +233,11 @@ public void updateStatus(Request request, Response response){ role_id = 3; } + // 重新发送激活邮件 + if(type.equals(Types.resend.toString())){ + activecodeService.resend(uid); + } + if(null != status){ userService.updateStatus(uid, status); } diff --git a/src/main/java/com/javachina/service/ActivecodeService.java b/src/main/java/com/javachina/service/ActivecodeService.java index 13d9557..95de033 100644 --- a/src/main/java/com/javachina/service/ActivecodeService.java +++ b/src/main/java/com/javachina/service/ActivecodeService.java @@ -10,5 +10,7 @@ public interface ActivecodeService { String save(User user, String type); boolean useCode(String code); + + boolean resend(Long uid); } diff --git a/src/main/java/com/javachina/service/impl/ActivecodeServiceImpl.java b/src/main/java/com/javachina/service/impl/ActivecodeServiceImpl.java index 82d4340..6ec040c 100644 --- a/src/main/java/com/javachina/service/impl/ActivecodeServiceImpl.java +++ b/src/main/java/com/javachina/service/impl/ActivecodeServiceImpl.java @@ -7,6 +7,7 @@ import com.javachina.model.User; import com.javachina.service.ActivecodeService; import com.javachina.service.SendMailService; +import com.javachina.service.UserService; import com.javachina.service.UserinfoService; import blade.kit.DateKit; @@ -18,6 +19,9 @@ public class ActivecodeServiceImpl implements ActivecodeService { @Inject private SendMailService sendMailService; + @Inject + private UserService userService; + @Inject private UserinfoService userinfoService; @@ -82,5 +86,29 @@ public boolean useCode(String code) { } return false; } + + @Override + public boolean resend(Long uid) { + if(null != uid){ + User user = userService.getUser(uid); + if(null == user){ + return false; + } + + int time = DateKit.getCurrentUnixTime(); + int expires_time = time + 3600; + String code = StringKit.getRandomChar(32); + try { + + AR.update("insert into t_activecode(uid, code, type, expires_time, create_time) values(?, ?, ?, ?, ?)", + user.getUid(), code, "signup", expires_time, time).executeUpdate(); + sendMailService.signup(user.getLogin_name(), user.getEmail(), code); + return true; + } catch (Exception e) { + e.printStackTrace(); + } + } + return false; + } } diff --git a/src/main/java/com/javachina/service/impl/SendMailServiceImpl.java b/src/main/java/com/javachina/service/impl/SendMailServiceImpl.java index 3dee307..70544e9 100644 --- a/src/main/java/com/javachina/service/impl/SendMailServiceImpl.java +++ b/src/main/java/com/javachina/service/impl/SendMailServiceImpl.java @@ -46,7 +46,8 @@ public void signup(String username, String email, String code) { "fromName", "Java中国", "xsmtpapi", x_smtpapi.toString(), "subject", "Java中国账户激活").body(); - System.out.println(body); + + LOGGER.info(body); userlogService.save(0L, Actions.SEND_MAIL, email + ":" + code + ":" + "signup"); @@ -75,7 +76,8 @@ public void forgot(String username, String email, String code) { "fromName", "Java中国", "xsmtpapi", x_smtpapi.toString(), "subject", "Java中国密码找回").body(); - System.out.println(body); + + LOGGER.info(body); userlogService.save(0L, Actions.SEND_MAIL, email + ":" + code + ":" + "forgot"); diff --git a/src/main/webapp/WEB-INF/views/admin/users.html b/src/main/webapp/WEB-INF/views/admin/users.html index d9c0e0d..96f8264 100644 --- a/src/main/webapp/WEB-INF/views/admin/users.html +++ b/src/main/webapp/WEB-INF/views/admin/users.html @@ -1,82 +1,83 @@ -#include("./header.html", {active:'users', title:'用户管理'}) -
-
-
用户列表
-
-
-
-
-
- - -
-
-
- - - - - - - - - - - - #for(user : userPage.results) - - - - - - - - #end - -
用户名用户邮箱注册日期用户状态操作
- ${user.login_name} - ${user.email}${fmtdate(user.create_time, 'yyyy-MM-dd HH:mm')} - #if(user.status == 0) - 未激活 - #elseif(user.status == 1) - 正常 - #elseif(user.status == 2) - 已拉黑 - #end - - #if(user.status == 0) - 激活账户 - #elseif(user.status == 1) - 拉黑 - #if(user.role_id == 3) - 取消管理员 - #else - 设置管理员 - #end - #elseif(user.status == 2) - 恢复账户 - #end -
-
-
-
- #if(userPage.totalPage > 1) -
    - #if(userPage.page > 1) -
  • 上一页
  • - #end - #if(userPage.totalPage > 1 && userPage.page != userPage.totalPage) -
  • 下一页
  • - #end -
- #end -
-
-
-
-
-#include("./footer.html") - +#include("./header.html", {active:'users', title:'用户管理'}) +
+
+
用户列表
+
+
+
+
+
+ + +
+
+
+ + + + + + + + + + + + #for(user : userPage.results) + + + + + + + + #end + +
用户名用户邮箱注册日期用户状态操作
+ ${user.login_name} + ${user.email}${fmtdate(user.create_time, 'yyyy-MM-dd HH:mm')} + #if(user.status == 0) + 未激活 + #elseif(user.status == 1) + 正常 + #elseif(user.status == 2) + 已拉黑 + #end + + #if(user.status == 0) + 激活账户 + 重新发送邮件激活 + #elseif(user.status == 1) + 拉黑 + #if(user.role_id == 3) + 取消管理员 + #else + 设置管理员 + #end + #elseif(user.status == 2) + 恢复账户 + #end +
+
+
+
+ #if(userPage.totalPage > 1) +
    + #if(userPage.page > 1) +
  • 上一页
  • + #end + #if(userPage.totalPage > 1 && userPage.page != userPage.totalPage) +
  • 下一页
  • + #end +
+ #end +
+
+
+
+
+#include("./footer.html") + \ No newline at end of file diff --git a/src/main/webapp/assets/scripts/admin.js b/src/main/webapp/assets/scripts/admin.js index 3ecc539..f4fc71a 100644 --- a/src/main/webapp/assets/scripts/admin.js +++ b/src/main/webapp/assets/scripts/admin.js @@ -1,147 +1,161 @@ - -$('a[data-toggle=layout-small-menu]').on('click', function(e){ - e.preventDefault(), e.stopPropagation(), $('.layout-fixed-header').toggleClass("layout-small-menu"); -}); - -function alertError(msg){ - swal({ - title:"提示信息", - text: msg, - type:"error", - timer: 3000 - }); -} - -function alertOk(msg){ - swal({ - title:"提示信息", - text: msg, - type:"success", - timer: 3000 - }); -} - -function len(o){ - var n, count = 0; - for(n in o){ - if(o.hasOwnProperty(n)){ - count++; - } - } - return count; -} - -// 激活用户 -$('.user-table .activeAccount').on('click', function(){ - var uid = $(this).attr("uid"); - $.post(BASE + '/admin/status', {uid:uid, type:'activeAccount'}, function(response){ - if(response){ - if(response.status == 200){ - window.location.reload(); - } else{ - alertError(response.msg); - } - } - }); -}); - -//禁用用户 -$('.user-table .disable').on('click', function(){ - var uid = $(this).attr("uid"); - $.post(BASE + '/admin/status', {uid:uid, type:'disable'}, function(response){ - if(response){ - if(response.status == 200){ - window.location.reload(); - } else{ - alertError(response.msg); - } - } - }); -}); - -//取消管理员 -$('.user-table .removeAdmin').on('click', function(){ - var uid = $(this).attr("uid"); - $.post(BASE + '/admin/status', {uid:uid, type:'removeAdmin'}, function(response){ - if(response){ - if(response.status == 200){ - window.location.reload(); - } else{ - alertError(response.msg); - } - } - }); -}); - -//设置管理员 -$('.user-table .setAdmin').on('click', function(){ - var uid = $(this).attr("uid"); - $.post(BASE + '/admin/status', {uid:uid, type:'setAdmin'}, function(response){ - if(response){ - if(response.status == 200){ - window.location.reload(); - } else{ - alertError(response.msg); - } - } - }); -}); - -//恢复账户 -$('.user-table .recoveryAccount').on('click', function(){ - var uid = $(this).attr("uid"); - $.post(BASE + '/admin/status', {uid:uid, type:'recoveryAccount'}, function(response){ - if(response){ - if(response.status == 200){ - window.location.reload(); - } else{ - alertError(response.msg); - } - } - }); -}); - -var setting_data = {}; -$("#setting_form :input").change(function (){ - var key = $(this).attr('name'); - if(key == 'allow_signup'){ - setting_data[key] = $(this).is(':checked'); - } else{ - setting_data[key] = $(this).val(); - } -}); - - -// 保存系统设置 -function save_settings(){ - if(len(setting_data) > 0){ - $.post(BASE + '/admin/settings', setting_data, function(response){ - setting_data = {}; - if(response){ - if(response.status == 200){ - alertOk("保存成功!"); - } else { - alertError(response.msg); - } - } - }); - } - return false; -} - -// 修改节点 -function update_node(){ - var formData = $('#editnode_form').serialize(); - $.post(BASE + '/admin/nodes/edit', formData, function(response){ - setting_data = {}; - if(response){ - if(response.status == 200){ - alertOk("修改成功!"); - } else { - alertError(response.msg); - } - } - }); - return false; -} + +$('a[data-toggle=layout-small-menu]').on('click', function(e){ + e.preventDefault(), e.stopPropagation(), $('.layout-fixed-header').toggleClass("layout-small-menu"); +}); + +function alertError(msg){ + swal({ + title:"提示信息", + text: msg, + type:"error", + timer: 3000 + }); +} + +function alertOk(msg){ + swal({ + title:"提示信息", + text: msg, + type:"success", + timer: 3000 + }); +} + +function len(o){ + var n, count = 0; + for(n in o){ + if(o.hasOwnProperty(n)){ + count++; + } + } + return count; +} + +// 激活用户 +$('.user-table .activeAccount').on('click', function(){ + var uid = $(this).attr("uid"); + $.post(BASE + '/admin/status', {uid:uid, type:'activeAccount'}, function(response){ + if(response){ + if(response.status == 200){ + window.location.reload(); + } else{ + alertError(response.msg); + } + } + }); +}); + +// 重新发送激活邮件 +$('.user-table .resendMail').on('click', function(){ + var uid = $(this).attr("uid"); + $.post(BASE + '/admin/status', {uid:uid, type:'resend'}, function(response){ + if(response){ + if(response.status == 200){ + alertOk('邮件已发送'); + } else{ + alertError(response.msg); + } + } + }); +}); + +//禁用用户 +$('.user-table .disable').on('click', function(){ + var uid = $(this).attr("uid"); + $.post(BASE + '/admin/status', {uid:uid, type:'disable'}, function(response){ + if(response){ + if(response.status == 200){ + window.location.reload(); + } else{ + alertError(response.msg); + } + } + }); +}); + +//取消管理员 +$('.user-table .removeAdmin').on('click', function(){ + var uid = $(this).attr("uid"); + $.post(BASE + '/admin/status', {uid:uid, type:'removeAdmin'}, function(response){ + if(response){ + if(response.status == 200){ + window.location.reload(); + } else{ + alertError(response.msg); + } + } + }); +}); + +//设置管理员 +$('.user-table .setAdmin').on('click', function(){ + var uid = $(this).attr("uid"); + $.post(BASE + '/admin/status', {uid:uid, type:'setAdmin'}, function(response){ + if(response){ + if(response.status == 200){ + window.location.reload(); + } else{ + alertError(response.msg); + } + } + }); +}); + +//恢复账户 +$('.user-table .recoveryAccount').on('click', function(){ + var uid = $(this).attr("uid"); + $.post(BASE + '/admin/status', {uid:uid, type:'recoveryAccount'}, function(response){ + if(response){ + if(response.status == 200){ + window.location.reload(); + } else{ + alertError(response.msg); + } + } + }); +}); + +var setting_data = {}; +$("#setting_form :input").change(function (){ + var key = $(this).attr('name'); + if(key == 'allow_signup'){ + setting_data[key] = $(this).is(':checked'); + } else{ + setting_data[key] = $(this).val(); + } +}); + + +// 保存系统设置 +function save_settings(){ + if(len(setting_data) > 0){ + $.post(BASE + '/admin/settings', setting_data, function(response){ + setting_data = {}; + if(response){ + if(response.status == 200){ + alertOk("保存成功!"); + } else { + alertError(response.msg); + } + } + }); + } + return false; +} + +// 修改节点 +function update_node(){ + var formData = $('#editnode_form').serialize(); + $.post(BASE + '/admin/nodes/edit', formData, function(response){ + setting_data = {}; + if(response){ + if(response.status == 200){ + alertOk("修改成功!"); + } else { + alertError(response.msg); + } + } + }); + return false; +} \ No newline at end of file