package com.xpx.controller;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * @author 夏培轩
 */
@Controller
public class AdminController {

    @RequestMapping("login")
    public String login(HttpServletRequest request) {
        Object ex = request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
        if(ex.equals(UnknownAccountException.class.getName())){
            request.setAttribute("msg","用户名错误");
        }else if(ex.equals(IncorrectCredentialsException.class.getName())){
            request.setAttribute("msg","密码错误");
        }else {
            request.setAttribute("msg","位置异常");
        }
        return "forward:/error.jsp";
    }
}
