首页>代码>s2sh政府电子政务网站>/dzzw/src/com/my/dzzw/action/LoginAction.java
package com.my.dzzw.action;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.my.dzzw.model.Manage;
import com.my.dzzw.model.News;
import com.my.dzzw.model.User;
import com.my.dzzw.service.ManageService;
import com.my.dzzw.service.NewsService;
import com.my.dzzw.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport {

//============依赖注入start================
		@Autowired
		private ManageService manageService;//管理
		@Autowired
		private UserService userService;//用户
		@Autowired
		private NewsService newsService;
		
		
		//===========依赖注入end==================
		
		//-------------------------华丽分割线---------------------------------------------
		
		//============自定义参数start=============
		 private String userName;
		   private String passWord;
		   private String phone;//手机号
			private String realName;//真实名
			private String email;
			private String newName;
		   public String getNewName() {
				return newName;
			}
			public void setNewName(String newName) {
				this.newName = newName;
			}
		public String getEmail() {
				return email;
			}
			public void setEmail(String email) {
				this.email = email;
			}
		public String getPhone() {
				return phone;
			}
			public void setPhone(String phone) {
				this.phone = phone;
			}
			public String getRealName() {
				return realName;
			}
			public void setRealName(String realName) {
				this.realName = realName;
			}

		   private int role;
		   private Integer keyword1;
		   private Integer keyword2;
		
		public Integer getKeyword1() {
			return keyword1;
		}
		public void setKeyword1(Integer keyword1) {
			this.keyword1 = keyword1;
		}
		public Integer getKeyword2() {
			return keyword2;
		}
		public void setKeyword2(Integer keyword2) {
			this.keyword2 = keyword2;
		}
		public String getUserName() {
			return userName;
		}
		public void setUserName(String userName) {
			this.userName = userName;
		}
		public String getPassWord() {
			return passWord;
		}
		public void setPassWord(String passWord) {
			this.passWord = passWord;
		}
		public int getRole() {
			return role;
		}
		public void setRole(int role) {
			this.role = role;
		}
		//============自定义参数end=============
		
		//-------------------------华丽分割线---------------------------------------------
		
		//============文件上传start=============
		private File file;
		//提交过来的file的名字
	    private String fileFileName;
	    //提交过来的file的MIME类型
	    private String fileContentType;
	    public File getFile() {
			return file;
		}
		public void setFile(File file) {
			this.file = file;
		}
		public String getFileFileName() {
			return fileFileName;
		}
		public void setFileFileName(String fileFileName) {
			this.fileFileName = fileFileName;
		}
		public String getFileContentType() {
			return fileContentType;
		}
		public void setFileContentType(String fileContentType) {
			this.fileContentType = fileContentType;
		}
		//============文件上传end=============
		
		//-------------------------华丽分割线---------------------------------------------

		//登陆页面
		public String uIndex() {
//			private Integer type;//类型 1政务公开 2. 通知公告 3.人事信息 4.规划计划 5.新闻
//			private Integer isDelete;//0否 1 是
			List<News> list1 = newsService.select5ByType(1,newName);
			List<News> list2 = newsService.select5ByType(2,newName);
			List<News> list3 = newsService.select5ByType(3,newName);
			List<News> list4 = newsService.select5ByType(4,newName);
			List<News> list5 = newsService.select5ByType(5,newName);
			ActionContext.getContext().put("list1", list1);
			ActionContext.getContext().put("list2", list2);
			ActionContext.getContext().put("list3", list3);
			ActionContext.getContext().put("list4", list4);
			ActionContext.getContext().put("list5", list5);
			ActionContext.getContext().put("newName", newName);
			return "uIndex";
		}
		//注册页面(只有前台有注册)
				public String register() {
					User u = new User();
					u.setCreateTime(new Date());
					u.setPassWord(passWord);
					u.setPhone(phone);
					u.setRealName(realName);
					u.setUserName(userName);
					u.setEmail(email);
			        userService.save(u);
					return "uLogin";
				}
				//用户到登陆
				public String ulogin() {
					return "uLogin";
				}
	
		
       //登录
		public String toLogin(){
//			  <option value="1">超级管理员</option>
//              <option value="2">管理员</option>
			
			if(role==3){//用户
				String hql = "from User where userName = :userName and passWord = :passWord";
				  Map<String,Object> alias = new HashMap<String,Object>();
				  alias.put("userName",userName);
				  alias.put("passWord", passWord);
				  List<User> userList= userService.getByHQL(hql, alias);
				if(userList.size()>0){
					//将用户信息放入session
					HttpSession session = ServletActionContext.getRequest()
							.getSession();
					session.setAttribute("userId",userList.get(0).getId() );
					session.setAttribute("user", userList.get(0));
					session.setAttribute("roleId", role);
					List<News> list1 = newsService.select5ByType(1,newName);
					List<News> list2 = newsService.select5ByType(2,newName);
					List<News> list3 = newsService.select5ByType(3,newName);
					List<News> list4 = newsService.select5ByType(4,newName);
					List<News> list5 = newsService.select5ByType(5,newName);
					ActionContext.getContext().put("list1", list1);
					ActionContext.getContext().put("list2", list2);
					ActionContext.getContext().put("list3", list3);
					ActionContext.getContext().put("list4", list4);
					ActionContext.getContext().put("list5", list5);
					ActionContext.getContext().put("newName", newName);
					return "uIndex";
				}else{
					return "uLogin";
				}
			}else{
				
					String hql = "from Manage where name = :userName and passWord = :passWord and type="+role;
					  Map<String,Object> alias = new HashMap<String,Object>();
					  alias.put("userName",userName);
					  alias.put("passWord", passWord);
					List<Manage> manageList=manageService.getByHQL(hql, alias);
					if(manageList.size()>0){
						//将用户信息放入session
						HttpSession session = ServletActionContext.getRequest()
								.getSession();
						session.setAttribute("userName", manageList.get(0).getRealName());
						session.setAttribute("userId2",manageList.get(0).getId() );
						session.setAttribute("manage", manageList.get(0));
						session.setAttribute("roleId", role);
						return "manageIndex";
					}else{
						return "manageLogin";
					}
				}
			
		}
		
		   //退出
			public String tuichu() {
				ActionContext ac = ActionContext.getContext();
				Map session = ac.getSession();
				session.remove("userName");
				session.remove("userId");
				if(role==1){
					return "userLogin";
				}else{
					return "manageLogin";
				}
			
			}
	
}
最近下载更多
justoday  LV11 2024年9月11日
guo0326  LV1 2024年3月28日
笑得很美  LV11 2024年3月13日
xiongwei11231  LV9 2023年8月31日
北方菜  LV11 2022年12月30日
12koko  LV3 2022年11月3日
zhaoyangwfd  LV17 2022年9月28日
唐僧洗头爱飘柔  LV22 2022年8月22日
testuser1234567  LV24 2022年6月30日
ᯤ⁵²¹ᴳ⁺  LV8 2022年4月6日
最近浏览更多
nieshuai0928 7月25日
暂无贡献等级
暂无贡献等级
zhanghna799  LV3 3月10日
2602275348  LV12 2024年12月23日
china_hdh  LV7 2024年10月10日
lqzixi  LV4 2024年10月9日
求学的熊猫  LV11 2024年9月24日
justoday  LV11 2024年9月11日
sunlea  LV20 2024年5月9日
203163  LV5 2024年4月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友