package cn.damai.guestbook.action;
import java.io.UnsupportedEncodingException;
import javax.servlet.http.Cookie;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import cn.damai.guestbook.common.Utils;
import cn.damai.guestbook.domain.MessageDomain;
import cn.damai.guestbook.domain.UserDomain;
import cn.damai.guestbook.service.MessageService;
import cn.damai.guestbook.service.UserService;
/**
* 公共ajax模块
*
* @author Administrator
*
*/
@Controller("ajaxHandlerController")
@Scope("prototype")
@Namespace("/ajax")
public class AjaxHandlerController extends BaseController {
/**
*
*/
private static final long serialVersionUID = -3044242937012925573L;
@Autowired
private UserService userService;
@Autowired
private MessageService messageService;
private String userName;
/**
* 密码&&留言内容&&回复内容
*/
private String inputPassword;
private String nickName;
/**
* 用户级别&&回复留言ID
*/
private int userLevel = 0;
private String oldPass;
private MessageDomain messageDomain;
public MessageDomain getMessageDomain() {
return messageDomain;
}
public void setMessageDomain(MessageDomain messageDomain) {
this.messageDomain = messageDomain;
}
public int getUserLevel() {
return userLevel;
}
public void setUserLevel(int userLevel) {
this.userLevel = userLevel;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getInputPassword() {
return inputPassword;
}
public void setInputPassword(String inputPassword) {
this.inputPassword = inputPassword;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getOldPass() {
return oldPass;
}
public void setOldPass(String oldPass) {
this.oldPass = oldPass;
}
/**
* 注册弹出层模块
*
* @return
*/
@Action(value = "registerForm", results = { @Result(name = "registerForm", location = "ajax/registerForm.httl", type = "httl") })
public String registerForm() {
return "registerForm";
}
/**
* 完成注册
*
* @return
*/
@Action(value = "register", results = { @Result(name = "register", type = "json", params = {
"includeProperties", "status,msg", "excludeNullProperties", "true",
"ignoreHierarchy", "false" }) })
public String register() {
if (!StringUtils.isBlank(userName)
&& !StringUtils.isBlank(inputPassword)
&& !StringUtils.isBlank(nickName)) {
if (!Utils.isUserName(userName) || !Utils.isPassWord(inputPassword)
|| !Utils.isNickName(nickName)) {
status = 101;
msg = "请输入正确的用户名、昵称或密码";
} else {
UserDomain user = userService.registerUser(userName,
inputPassword, nickName);
if (user != null) {
WriteUserCookie(user);
status = 200;
msg = "恭喜您,注册成功!";
} else {
status = 102;
msg = "注册失败,可能用户名、昵称重复或系统错误!";
}
}
} else {
status = 100;
msg = "请输入正确的用户名、昵称或密码";
}
return "register";
}
/**
* 登录模块
*
* @return
*/
@Action(value = "loginForm", results = { @Result(name = "loginForm", location = "ajax/loginForm.httl", type = "httl") })
public String loginForm() {
return "loginForm";
}
/**
* 校验登录信息
*
* @return
* @throws UnsupportedEncodingException
*/
@Action(value = "checkLogin", results = { @Result(name = "checkLogin", type = "json", params = {
"includeProperties", "status,msg", "excludeNullProperties", "true",
"ignoreHierarchy", "false" }) })
public String checkLogin() throws UnsupportedEncodingException {
if (!StringUtils.isBlank(userName)
&& !StringUtils.isBlank(inputPassword)) {
if (!Utils.isUserName(userName) || !Utils.isPassWord(inputPassword)) {
status = 101;
msg = "请输入正确的用户名或密码";
} else {
UserDomain user = userService.login(userName, inputPassword);
if (user != null) {
WriteUserCookie(user);
status = 200;
msg = "系统登录成功!";
} else {
status = 102;
msg = "用户名或密码错误";
}
}
} else {
status = 100;
msg = "请输入用户名和密码";
}
return "checkLogin";
}
/**
* 判断是否登录
*
* @return
*/
@Action(value = "isLogin", results = { @Result(name = "isLogin", type = "json", params = {
"includeProperties", "status,msg,nickName,userLevel",
"excludeNullProperties", "true", "ignoreHierarchy", "false" }) })
public String isLogin() {
// 获取已经校验过的登录用户信息
UserDomain user = getLoginUserDomain();
if (user != null) {
nickName = user.getNickName();
userLevel = user.getUserLevel();
status = 200;
msg = "恭喜您,您已经登录过了!";
} else {
status = 101;
msg = "您尚未登录";
}
return "isLogin";
}
/**
* 退出系统
*
* @return
*/
@Action(value = "logout", results = { @Result(name = "logout", type = "json", params = {
"includeProperties", "status,msg", "excludeNullProperties", "true",
"ignoreHierarchy", "false" }) })
public String logout() {
// 创建Cookie
Cookie cookieID = new Cookie("id", "0");
cookieID.setPath("/");
cookieID.setMaxAge(0);
response.addCookie(cookieID);
Cookie cookieSign = new Cookie("sign", "");
cookieSign.setPath("/");
cookieSign.setMaxAge(0);
response.addCookie(cookieSign);
status = 200;
msg = "退出系统成功";
return "logout";
}
/**
* 更新信息表单
*
* @return
*/
@Action(value = "changeForm", results = { @Result(name = "changeForm", location = "ajax/changeForm.httl", type = "httl") })
public String changeForm() {
return "changeForm";
}
/**
* 修改用户密码
*
* @return
*/
@Action(value = "change", results = { @Result(name = "change", type = "json", params = {
"includeProperties", "status,msg", "excludeNullProperties", "true",
"ignoreHierarchy", "false" }) })
public String change() {
if (!StringUtils.isBlank(inputPassword)
&& !StringUtils.isBlank(oldPass)) {
if (!Utils.isPassWord(oldPass) || !Utils.isPassWord(inputPassword)) {
status = 101;
msg = "请输入正确的原密码和新密码";
} else {
UserDomain u = getLoginUserDomain();
if (u != null) {
String md5pass = DigestUtils.md5Hex(oldPass
+ u.getUserKey());
if (md5pass.equals(u.getUserPass())) {
// 更新新密码
String newPass = DigestUtils.md5Hex(inputPassword
+ u.getUserKey());
int rv = userService.updateUserPass(u.getId(), newPass);
if (rv > 0) {
status = 200;
msg = "恭喜您,密码修改成功!";
} else {
status = 104;
msg = "密码修改失败";
}
} else {
status = 103;
msg = "原密码错误";
}
} else {
status = 102;
msg = "未登录或未找到登录信息";
}
}
} else {
status = 100;
msg = "请输入新密码";
}
return "change";
}
/**
* 生成留言用的表单
*
* @return
*/
@Action(value = "messageForm", results = { @Result(name = "messageForm", location = "ajax/messageForm.httl", typ
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
自己学习用的,基本上采用都是最新版的程序,jre7编译 不建议直接导入,自己新建maven项目,然后一步步的导入文件,这样有利于学习 1分只是象征,如果一分都没有 http://yunpan.cn/QNVzMR8U3gKck 或者SVN:http://code.taobao.org/svn/guestbook/trunk 互相学习,互相进步吧!">自己学习用的,基本上采用都是最新版的程序,jre7编译 不建议直接导入,自己新建maven项目,然后一步步的导入文件,这样有利于学习 1分只是象征,如果一分都没有 http://yunpan.cn/QNVzMR8U3gKck 或者SVN:http://code.taobao.org/svn/guestbook/ [更多]
资源推荐
资源详情
资源评论
收起资源包目录
基于maven管理的 spring4 0 3+struts2 2 3 16 1+hibernate4 3 4 Final+httl1 0 11 的简单留言本 (125个子文件)
AjaxHandlerController.class 10KB
AjaxHandlerController.class 10KB
BaseDao.class 7KB
BaseDao.class 7KB
BaseController.class 6KB
BaseController.class 6KB
UserService.class 6KB
UserService.class 6KB
UserTest.class 3KB
MessageService.class 3KB
MessageService.class 3KB
MessageDomain.class 3KB
MessageDomain.class 3KB
UserDomain.class 3KB
UserDomain.class 3KB
IndexController.class 2KB
IndexController.class 2KB
ManageController.class 2KB
ManageController.class 2KB
MessageTest.class 2KB
Utils.class 2KB
Utils.class 2KB
MessageDao.class 525B
MessageDao.class 525B
UserDao.class 510B
UserDao.class 510B
BaseDomain.class 399B
BaseDomain.class 399B
.classpath 1KB
org.eclipse.wst.common.component 759B
org.eclipse.wst.jsdt.ui.superType.container 49B
bootstrap.min.css 102KB
css.css 168B
error.html 899B
index.html 310B
registerForm.httl 2KB
changeForm.httl 2KB
index.httl 2KB
manage.httl 1KB
loginForm.httl 1KB
replayForm.httl 1KB
messageForm.httl 1KB
header.httl 835B
error.httl 746B
utils.httl 592B
footer.httl 44B
guestbook-sources.jar 15KB
AjaxHandlerController.java 12KB
BaseController.java 5KB
UserService.java 5KB
BaseDao.java 4KB
MessageDomain.java 2KB
UserDomain.java 2KB
MessageService.java 2KB
UserTest.java 2KB
IndexController.java 2KB
ManageController.java 2KB
MessageTest.java 1KB
Utils.java 1KB
MessageDao.java 229B
BaseDomain.java 222B
UserDao.java 217B
bootstrap.min.js 28KB
base.min.js 14KB
default.js 8KB
manage.js 2KB
.jsdtscope 508B
variables.less 25KB
bootswatch.less 2KB
inputFiles.lst 1KB
createdFiles.lst 487B
inputFiles.lst 165B
createdFiles.lst 39B
MANIFEST.MF 114B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.springframework.ide.eclipse.core.prefs 6KB
org.eclipse.jdt.core.prefs 430B
org.eclipse.core.resources.prefs 155B
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.ws.service.policy.prefs 87B
org.eclipse.wst.validation.prefs 50B
.project 1KB
log4j.properties 2KB
log4j.properties 2KB
log4j.properties 2KB
log4j.properties 2KB
log4j.properties 2KB
log4j.properties 2KB
jdbc.properties 812B
jdbc.properties 812B
jdbc.properties 812B
jdbc.properties 812B
jdbc.properties 812B
jdbc.properties 812B
httl.properties 390B
httl.properties 390B
httl.properties 390B
httl.properties 318B
httl.properties 318B
httl.properties 318B
共 125 条
- 1
- 2
资源评论
- NM_IT2014-12-23可以使用,,入门级
- cnsquirrel2015-04-01我是初学者,搭建成功,少走了弯路
- blog_Shao2014-10-10做为入门示例可以,感觉HTTL比VM功能差好多,性能还不知道怎么样
lyfeixue
- 粉丝: 3
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功