首页>代码>s2sh(spring+struts2+hibernate)开发实验室信息管理系统>/Laboratory/src/com/xznu/edu/leave/action/LoginAction.java
package com.xznu.edu.leave.action;
/**
 * 和登陆有关的都在这里
 */

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.xznu.edu.leave.model.Role;
import com.xznu.edu.leave.model.User;
import com.xznu.edu.leave.service.RoleService;
import com.xznu.edu.leave.service.UserService;
import com.xznu.edu.leave.utils.JsonUtils;
import com.xznu.edu.leave.utils.UserUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller("loginAction")
@Scope("prototype")
public class LoginAction extends ActionSupport {
    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;
    private User user;
    private Map<String, Object> map = new HashMap();
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    /**
 * 用户登陆
 * @return
 */
	public void index() throws IOException {
       User user1 = userService.getUser(user);
        if (user1 != null){
            if (user1.getIsSh() == 1){
                if (user1.getRole().getEnName().equals("admin")){
                    ActionContext.getContext().getSession().put("user", user1);
                }
                if (user1.getRole().getEnName().equals("js")){
                    ActionContext.getContext().getSession().put("user1", user1);
                }
                if (user1.getRole().getEnName().equals("xs")){
                    ActionContext.getContext().getSession().put("user2", user1);
                }
                map.put("flag", 1);
                map.put("url", "login_indexs.do");
                map.put("id", user1.getId());
                JsonUtils.toJson(map);
            } else {
                map.put("flag", 2);
                JsonUtils.toJson(map);
            }
        } else {
            map.put("flag", 3);
            JsonUtils.toJson(map);
        }
    }

    public String indexs() throws IOException {
        User u = UserUtils.getUser();
        if (u != null){
            ActionContext.getContext().put("user", u);
            String ss = u.getRole().getEnName();
            ActionContext.getContext().put("role", u.getRole().getEnName());
        }
        return SUCCESS;
    }
	//登陆页面
	public String login() {

        return SUCCESS;
	}

   //退出
	public String tuichu() {
		ActionContext ac = ActionContext.getContext();
		Map session = ac.getSession();
		session.remove("userName");
		session.remove("userId");
		return "login";
	}

}
最近下载更多
zolscy  LV12 4月5日
acid111  LV1 2月26日
hbj1285984841  LV4 2023年10月19日
hxzyhxzy  LV1 2023年10月3日
LongTory  LV2 2023年5月9日
ming_123_9715  LV23 2023年4月27日
王培龚  LV4 2023年4月11日
kevinkg  LV12 2023年4月3日
wxxgyh  LV2 2023年3月23日
东方之珠_1628  LV6 2022年12月1日
最近浏览更多
zolscy  LV12 4月5日
WBelong  LV7 3月8日
acid111  LV1 2月26日
359469859 1月31日
暂无贡献等级
admin_z  LV22 2023年12月28日
lasttimeapp 2023年11月27日
暂无贡献等级
hbj1285984841  LV4 2023年10月19日
hxzyhxzy  LV1 2023年10月3日
186092  LV4 2023年9月20日
Huangyinghai  LV1 2023年7月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友