UserAction

`package cn.bdqn.jboa.action;

import java.util.Map;
import cn.bdqn.jboa.entity.Employee;
import cn.bdqn.jboa.service.EmployeeService;
import cn.bdqn.jboa.utils.MD5;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
* 用户登录action。
*
* @author 北大青鸟
* @version 1.0
*/
public class UserAction extends ActionSupport {

private static final long serialVersionUID = -6095372451084071851L;

private Employee employee = null;

private EmployeeService employeeService = null;

/**
 * 用户登录。
 * 
 * @return
 * @throws Exception
 */
public String login() throws Exception {

    Employee newEmployee = null;
    try {
        // 对登录密码进行MD5加密
        // employee.setPassword(new MD5(employee.getPassword()).compute());
        newEmployee = employeeService.login(employee);
    } catch (Exception e) {
        this.addActionMessage(e.getMessage());
    }

    String ret = INPUT;
    if (newEmployee == null) {
        ret = INPUT;
    } else {
        Map<String, Object> session = ActionContext.getContext()
                .getSession();
        session.put("employee", newEmployee);
        String nameCn = newEmployee.getPosition().getNameCn();
        if ("普通员工".equals(nameCn)) {
            ret = "staff";
        } else if ("部门经理".equals(nameCn)) {
            ret = "deptManager";
        } else if ("总经理".equals(nameCn)) {
            ret = "manager";
        } else if ("财务".equals(nameCn)) {
            ret = "cashier";
        }
    }

    return ret;

}

/**
 * 用户退出。
 * 
 * @return
 * @throws Exception
 */
public String logout() throws Exception {
    ActionContext ac = ActionContext.getContext();
    ac.getSession().remove("employee");
    return SUCCESS;
}

public void setEmployee(Employee employee) {
    this.employee = employee;
}

public void setEmployeeService(EmployeeService employeeService) {
    this.employeeService = employeeService;
}

public Employee getEmployee() {
    return employee;
}

public EmployeeService getEmployeeService() {
    return employeeService;
}

}
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值