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

📄 useraction.java

📁 EasyJF开源新闻系统是一个由EasyJF开源团队组织开发的基于Java平台的开源新闻系统。当前系统已经实现了基本的基本的新闻的发布、审核、推荐
💻 JAVA
字号:
package com.easyjf.news.action;

import com.easyjf.news.logic.impl.FiltServiceImpl;
import com.easyjf.news.logic.impl.UserServiceImpl;
import com.easyjf.news.model.Constants;
import com.easyjf.news.model.Filter;
import com.easyjf.news.model.User;
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.AbstractCmdAction;

public class UserAction extends AbstractCmdAction {

	private UserServiceImpl userDAO = UserServiceImpl.getInstance();

	private FiltServiceImpl filtDAO = FiltServiceImpl.getInstance();

	User user = (User) ActionContext.getContext().getSession().getAttribute(
			Constants.SESSION_USER);

	public Page doInit(WebForm form, Module module) {
		// TODO 自动生成方法存根
		return module.findPage("reg");
	}

	public Page doLogin(WebForm form, Module module) {
		ActionContext.getContext().getSession().removeAttribute(
				Constants.SESSION_USER);
		String user_name = (String) form.get("user_name");
		User user = userDAO.getUserByName(user_name);
		if (user != null
				&& user.getPassword().equals((String) form.get("password"))) {
			ActionContext.getContext().getSession().setAttribute(
					Constants.SESSION_USER, user);
			form.addResult("user", user);
			return new Page("reg", "/userRegSuccess.html");
		} else {
			form.addResult("msg", "登录失败,请您检查用户名或密码!");
			return module.findPage("login");
		}

	}

	public Page doOut(WebForm form, Module module) {
		ActionContext.getContext().getSession().removeAttribute(
				Constants.SESSION_USER);
		return module.findPage("logout");
	}

	public Page doReg(WebForm form, Module module) {
		System.out.print("开始....");
		String user_name = (String) form.get("user_name");
		Filter huser = filtDAO.getFilterByName(user_name);
		if (huser != null) {
			form.addResult("msg", "您使用的用户名系统不允许!");
			return new Page("reg", "/userReg.html");
		} else {
			User puser = userDAO.getUserByName(user_name);
			if (puser == null) {
				if (user_name.equals("admin") || user_name.equals("tianyi")
						|| user_name.equals("daxia")
						|| user_name.equals("stef_wu")
						|| user_name.equals("willarmy")) {
					form.set("popedom", "3");
				}

				User user = (User) form.toPo(User.class);
				System.out.println(user_name);
				System.out.println(user.getPopedom());
				if (userDAO.saveUser(user)) {
					ActionContext.getContext().getSession().setAttribute(
							Constants.SESSION_USER, user);
					form.addResult("user", user);
					form.addResult("msg", "注册成功!");
					return new Page("reg", "/userRegSuccess.html");
				} else {
					form.addResult("msg", "注册失败!");
					return new Page("reg", "/userReg.html");
				}
			} else {
				form.addResult("msg", "用户名已经存在!");
				return new Page("reg", "/userReg.html");
			}
		}
	}

}

⌨️ 快捷键说明

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