首页>代码>spring mvc maven,websocket在线简单聊天室系统,ace master,extjs>/chatwebsocket/src/main/java/com/chatwebsocket/controller/system/login/LoginController.java
package com.chatwebsocket.controller.system.login;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.chatwebsocket.controller.base.BaseController;
import com.chatwebsocket.service.UserManager;
import com.chatwebsocket.util.Const;
import com.chatwebsocket.util.PageData;

/**
 * 登录控制器
 * @author zhangmingjie
 * @date 2019年4月13日 上午11:34:10
 * @version 1.0
 */
@Controller
public class LoginController extends BaseController{

	@Resource(name="userService")
	private UserManager userService;
	
	/**访问登录页
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/login_toLogin")
	public ModelAndView toLogin()throws Exception{
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		pd = this.getPageData();
		mv.setViewName("login");
		mv.addObject("pd",pd);
		return mv;
	}
	
	/*
	 * 登录
	 */
	@RequestMapping(value="/login_login")
	@ResponseBody
	public Object login_login() throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		PageData pd = new PageData();
		pd = this.getPageData();

		String errorInfo = "";
		String username = pd.getString("username");
		String password = pd.getString("password");
		String code = pd.getString("code");

		HttpSession session = getRequest().getSession();
		String sessionCode = (String) session.getAttribute(Const.SESSION_SECURITY_CODE);

		if ("".equals(code) || code == null) {
			errorInfo = "nullcode";
		} else {
			pd.put("username", username);
			if (null != sessionCode && sessionCode.equalsIgnoreCase(code)) {
				String passwd = new SimpleHash("SHA-1", username, password).toString(); // 密码加密
				pd.put("password", passwd);
				pd = userService.getUserByNameAndPwd(pd);
				session.setAttribute(Const.SESSION_userpds, pd);
				session.setAttribute(Const.SESSION_USERNAME, username);
				if (pd != null) {
					
				} else {
					errorInfo = "usererror";
					logBefore(logger, username + "登录系统密码或用户名错误");
				}
			} else {
				errorInfo = "codeerror";
			}

			if (errorInfo.equals("")) {
				errorInfo = "success";
			}
		}
		map.put("result", errorInfo);
		return map;
	}
	
	/**
	 * 登录成功进入主页
	 * 
	 * @return
	 * @date 2019年4月13日 上午11:56:42
	 * @version 1.0
	 * @author zhangmingjie
	 */
	@RequestMapping(value="/main/index")
	public ModelAndView main(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("main");
		return mv;
	}
	
	@RequestMapping(value="/tab")
	public ModelAndView tab(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("tab");
		return mv;
	}
	
}
最近下载更多
80730176  LV7 2023年12月8日
云淡风轻jh  LV10 2023年11月28日
Tg171017  LV12 2023年2月18日
lironggang  LV38 2023年2月16日
nanaland  LV9 2023年2月9日
yangguang  LV8 2022年5月20日
xiex909  LV27 2022年5月18日
17岁的孩子想糖吃  LV7 2021年12月31日
137455054  LV9 2021年12月2日
18219194576  LV7 2021年11月10日
最近浏览更多
WBelong  LV7 4月2日
dafeiyu  LV10 3月1日
lilong007  LV20 3月1日
阿凡达  LV9 2月29日
云淡风轻jh  LV10 2023年11月28日
CrystalQ  LV8 2023年10月26日
Jackson1 2023年9月8日
暂无贡献等级
陈小灏  LV14 2023年5月16日
微信网友_6444139264921600  LV6 2023年4月29日
gzryue  LV6 2023年4月23日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友