Skip to content

Commit

Permalink
add resend mail active users
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed May 3, 2016
1 parent cb85a5b commit 4d0fb61
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 230 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/javachina/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum Types {
allow_signup,
forgot,
sinks,
topic_sinks
topic_sinks,
resend

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,6 +44,9 @@ public class IndexController extends BaseController {
@Inject
private SettingsService settingsService;

@Inject
private ActivecodeService activecodeService;

/**
* 首页
*/
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/javachina/service/ActivecodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ public interface ActivecodeService {
String save(User user, String type);

boolean useCode(String code);

boolean resend(Long uid);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,9 @@ public class ActivecodeServiceImpl implements ActivecodeService {
@Inject
private SendMailService sendMailService;

@Inject
private UserService userService;

@Inject
private UserinfoService userinfoService;

Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down
163 changes: 82 additions & 81 deletions src/main/webapp/WEB-INF/views/admin/users.html
Original file line number Diff line number Diff line change
@@ -1,82 +1,83 @@
#include("./header.html", {active:'users', title:'用户管理'})
<div class=main-content>
<div class="panel mb25">
<div class="panel-heading">用户列表</div>
<div class="panel-body">
<div class="table-responsive">
<div class="row">
<div class="pull-left pl10">
<form action="${base_url('/admin/users')}" method="post">
<label>
<input type="search" class="form-control" name="email" placeholder="搜索..." value="${email}"/>
</label>
<button type="submit" class="btn btn-icon-icon btn-sm btn-google-plus btn-round"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
<table class="table table-bordered table-striped mb0">
<thead>
<tr>
<th width="20%">用户名</th>
<th width="20%">用户邮箱</th>
<th width="20%">注册日期</th>
<th width="20%">用户状态</th>
<th align="center">操作</th>
</tr>
</thead>
<tbody class="user-table">
#for(user : userPage.results)
<tr>
<td>
<a href="${base_url('/member/') + user.login_name}" target="_blank">${user.login_name}</a>
</td>
<td>${user.email}</td>
<td>${fmtdate(user.create_time, 'yyyy-MM-dd HH:mm')}</td>
<td>
#if(user.status == 0)
未激活
#elseif(user.status == 1)
正常
#elseif(user.status == 2)
已拉黑
#end
</td>
<td>
#if(user.status == 0)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm activeAccount">激活账户</a>
#elseif(user.status == 1)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm disable">拉黑</a>
#if(user.role_id == 3)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm removeAdmin">取消管理员</a>
#else
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm setAdmin">设置管理员</a>
#end
#elseif(user.status == 2)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm recoveryAccount">恢复账户</a>
#end
</td>
</tr>
#end
</tbody>
</table>
</div>
<div class="datatable-bottom pt10">
<div class="pull-right">
#if(userPage.totalPage > 1)
<ul class="pager">
#if(userPage.page > 1)
<li class="pull-left"><a href="${base_url('/admin/users?p=') + userPage.prev_page}">上一页</a></li>
#end
#if(userPage.totalPage > 1 && userPage.page != userPage.totalPage)
<li class="pull-right"><a href="${base_url('/admin/users?p=') + userPage.next_page}">下一页</a></li>
#end
</ul>
#end
</div>
</div>
</div>
</div>
</div>
#include("./footer.html")
</body>
#include("./header.html", {active:'users', title:'用户管理'})
<div class=main-content>
<div class="panel mb25">
<div class="panel-heading">用户列表</div>
<div class="panel-body">
<div class="table-responsive">
<div class="row">
<div class="pull-left pl10">
<form action="${base_url('/admin/users')}" method="post">
<label>
<input type="search" class="form-control" name="email" placeholder="搜索..." value="${email}"/>
</label>
<button type="submit" class="btn btn-icon-icon btn-sm btn-google-plus btn-round"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
<table class="table table-bordered table-striped mb0">
<thead>
<tr>
<th width="20%">用户名</th>
<th width="20%">用户邮箱</th>
<th width="20%">注册日期</th>
<th width="20%">用户状态</th>
<th align="center">操作</th>
</tr>
</thead>
<tbody class="user-table">
#for(user : userPage.results)
<tr>
<td>
<a href="${base_url('/member/') + user.login_name}" target="_blank">${user.login_name}</a>
</td>
<td>${user.email}</td>
<td>${fmtdate(user.create_time, 'yyyy-MM-dd HH:mm')}</td>
<td>
#if(user.status == 0)
未激活
#elseif(user.status == 1)
正常
#elseif(user.status == 2)
已拉黑
#end
</td>
<td>
#if(user.status == 0)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm activeAccount">激活账户</a>
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm resendMail">重新发送邮件激活</a>
#elseif(user.status == 1)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm disable">拉黑</a>
#if(user.role_id == 3)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm removeAdmin">取消管理员</a>
#else
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm setAdmin">设置管理员</a>
#end
#elseif(user.status == 2)
<a href="javascript:;" uid="${user.uid}" class="btn btn-danger btn-outline btn-sm recoveryAccount">恢复账户</a>
#end
</td>
</tr>
#end
</tbody>
</table>
</div>
<div class="datatable-bottom pt10">
<div class="pull-right">
#if(userPage.totalPage > 1)
<ul class="pager">
#if(userPage.page > 1)
<li class="pull-left"><a href="${base_url('/admin/users?p=') + userPage.prev_page}">上一页</a></li>
#end
#if(userPage.totalPage > 1 && userPage.page != userPage.totalPage)
<li class="pull-right"><a href="${base_url('/admin/users?p=') + userPage.next_page}">下一页</a></li>
#end
</ul>
#end
</div>
</div>
</div>
</div>
</div>
#include("./footer.html")
</body>
</html>

0 comments on commit 4d0fb61

Please sign in to comment.