⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bloguseraction.java

📁 EasyJF开源Blog系统是一个由EasyJF开源团队组织开发的基于Java平台的开源博客系统。当前Blog已经实现了基本的基本的博客的书写、流量统计、排名、个人像册、RSS、支持自定义模板、静态h
💻 JAVA
字号:
package com.easyjf.blog.web.action;

import com.easyjf.blog.domain.BlogInfo;
import com.easyjf.blog.logic.BlogUserService;
import com.easyjf.blog.logic.CurrentUser;
import com.easyjf.blog.logic.impl.BlogUserServiceImpl;
import com.easyjf.util.CommUtil;
import com.easyjf.util.MD5;
import com.easyjf.web.ActionContext;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.ActiveUser;
import com.easyjf.web.tools.IActiveUser;

public class BlogUserAction extends BaseCmdAction {
	private BlogUserService userService=BlogUserServiceImpl.getInstance();	
	public Page doInit(WebForm form, Module module) {
		// TODO Auto-generated method stub
		return null;
	}
	public Page doRegister(WebForm form, Module module) {
		IActiveUser user=this.getCurrentUser(form);
		if(user==null)
		{
			//请先登录
			form.addResult("url", "blogUser.ejf?easyJWebCommand=register");
			form.addResult("msg","请先登录!");
			return module.findPage("login");
		}
		form.addResult("userName", user.getUserName());
		BlogInfo blog=userService.getUserBlog(user.getUserName());
		if(blog!=null)return doSetting(form,module);		
		return module.findPage("register");
	}
	
	public Page doSaveRegister(WebForm form, Module module) {
		boolean ret=userService.register((BlogInfo)form2Obj(form));
		if(ret)
		{
			form.addResult("msg", "注册成功,请等待我们审批!");
			return new Page("index","/blog.ejf","html");
		}
		else
		{
			form.addResult("msg", "注册失败,请检查所需填写的各项是否正确!");
			return module.findPage("register");
		}		
	}	
	public Page doShowLogin(WebForm form, Module module) {
		return module.findPage("login");
	}
	public Page doLogin(WebForm form, Module module) {
		ActionContext.getContext().getSession().removeAttribute("bbsuser");
		Page page = null;
		String randomCode = (String) ActionContext.getContext().getSession()
				.getAttribute("rand");
		if (!randomCode.equals((String) form.get("randomCode"))) {
			form.addResult("msg", "验证码不正确,请重新输入!");
			return module.findPage("login");
		}
		IActiveUser user = userService.login(CommUtil.null2String(form
				.get("userName")), CommUtil.null2String(form.get("password")),ActionContext
						.getContext().getRequest().getRemoteAddr());
		if (user != null) {			
			ActionContext.getContext().getSession().setAttribute("bbsuser",
					user);// 登录标志			
			//page = module.findPage("loginSuccess");
			String url=CommUtil.null2String(form.get("url"));
			if("".equals(url))url="manage.ejf";
			form.addResult("js","top.location.replace('"+url+"');");
			page =new Page("index","/manage/javascript.html","template");
		} else {
			form.addResult("msg", "用户名或者密码不正确,请重新输入!");
			page = module.findPage("login");
		}
		return page;
	}
	public Page doSetting(WebForm form, Module module) {		
		BlogInfo blog=userService.getUserBlog(CurrentUser.getActiveUser().getUserName());
		form.addPo(blog);
		return module.findPage("setting");
	}
	public Page doSaveSetting(WebForm form, Module module) {			
		boolean ret=userService.settingBlogInfo((BlogInfo)form2Obj(form));
		form.addResult("msg",ret?"设置成功!":"设置失败!");
		return module.findPage("setting");
	}
	public Page doShowChangePassword(WebForm form, Module module) {
		return module.findPage("changePassword");
	}
	public Page doChangePassword(WebForm form, Module module) {
		String oldPassword=CommUtil.null2String(form.get("oldPassword"));
		String password=CommUtil.null2String(form.get("password"));
		String password1=CommUtil.null2String(form.get("password1"));		
		if(!MD5.encode(oldPassword).equals(((ActiveUser)this.getCurrentUser(form)).getPassword()))
		{
			form.addResult("msg","旧密码不正确,不能修改密码!");
			return module.findPage("changePassword");
		}		
		if(!password.equals(password1))
		{
			form.addResult("msg", "两次输入的密码不正确!");
			return module.findPage("changePassword");
		}	
		if(userService.changePassword(this.getCurrentUser(form).getUserName(), oldPassword, password))
		{
		
		form.addResult("js","alert('密码修改成功,请使用新密码重新登录!');top.location.replace('/manage.ejf');");
		return new Page("exit","/manage/javascript.html","template");
		}
		return module.findPage("changePassword");
	}
	public Page doShowChoiceTemplate(WebForm form, Module module) {
		return module.findPage("choiceTemplate");
	}
	public Page doChangeTemplate(WebForm form, Module module) {
		return module.findPage("choiceTemplate");
	}
	public Page doLogout(WebForm form, Module module) {
		ActionContext.getContext().getSession().removeAttribute("bbsuser");
		form.addResult("url", "/blog.ejf");
		return new Page("clientforward", "/blog/forward.html", "template");
	}
	public Page doVisitCount(WebForm form, Module module) {
		String cid=CommUtil.null2String(form.get("cid"));
		BlogInfo blog=userService.getBlogInfo(cid);
		blog.setReadTimes(new Integer(blog.getReadTimes()!=null?blog.getReadTimes().intValue()+1:1));
		userService.settingBlogInfo(blog);
		return null;	
	}
	public Object form2Obj(WebForm form) {
		String cid =CommUtil.null2String(form.get("cid"));
	   BlogInfo obj=userService.getBlogInfo(cid);
	   if(obj==null)obj=new BlogInfo();
	   //此处需要修改,妨止系统字段被从外面非法赋值
	   form.toPo(obj);
	   return obj;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -