loginservice.java

来自「本平台是以web2.0为基本的标准」· Java 代码 · 共 85 行

JAVA
85
字号
package com.afuer.hib.dao.orgModel.Dao.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.afuer.hib.dao.orgModel.Idao.ILoginDao;
import com.afuer.hib.form.UserAcl;
import com.afuer.hib.form.UserInfo;
import com.afuer.hib.form.Userrole;
import com.common.login.UserSessionForm;
import com.common.util.StringTool;

public class LoginService implements Controller {
	private static final Log log = LogFactory.getLog(LoginService.class);

	private ILoginDao loginDao;

	public ILoginDao getLoginDao() {
		return loginDao;
	}

	public void setLoginDao(ILoginDao loginDao) {
		this.loginDao = loginDao;
	}

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub

		String username = StringTool.InitStr(request.getParameter("username")).trim();
		String password = StringTool.InitStr(request.getParameter("password")).trim();
		UserInfo user = new UserInfo();
		int login_flag = 0;
		login_flag = loginDao.getUserInfoDao().getAccounts(username, password)
				.intValue();
		log.warn("user:loginname," + username);
		if (login_flag > 0) {

			// 对用户进行授权
			List roles = new ArrayList();
			user = loginDao.getUserInfoDao().getUserInfo(username);
			UserSessionForm usf = new UserSessionForm();

			// 添加用户的基本信息
			usf.setUi(user);

			// 添加用户的角色
			List list = loginDao.getUserroleDao().findRolesByUser(user.getId());
			Iterator it = list.iterator();
			while (it.hasNext()) {
				Userrole ur = (Userrole) it.next();
				roles.add(ur.getRoleid());
			}
			usf.setRoles(roles);

			//设置session
			HttpSession sess = request.getSession(true);
			sess.setAttribute("UserInfo", usf);
			usf.setUrlTree(list);

			log.warn("用户" + user.getLoginname() + "登陆系统!");
			return new ModelAndView("/admin/login/index");
		} else {
			log.warn("用户" + StringTool.InitStr(username) + "尝试登陆系统失败!");

			return new ModelAndView("/admin/login/login", "errMsg",
					"您的用户名或密码错误!");
		}

	}

}

⌨️ 快捷键说明

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