Search in sources :

Example 1 with InvalidKaptchaException

use of com.ikoori.vip.common.exception.InvalidKaptchaException in project vip by guangdada.

the class LoginController method loginVali.

/**
 * 点击登录执行的动作
 */
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String loginVali() {
    String username = super.getPara("username").trim();
    String password = super.getPara("password").trim();
    // 验证验证码是否正确
    if (ToolUtil.getKaptchaOnOff()) {
        String kaptcha = super.getPara("kaptcha").trim();
        String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
        if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equals(code)) {
            throw new InvalidKaptchaException();
        }
    }
    Subject currentUser = ShiroKit.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(username, password.toCharArray());
    token.setRememberMe(true);
    currentUser.login(token);
    ShiroUser shiroUser = ShiroKit.getUser();
    super.getSession().setAttribute("shiroUser", shiroUser);
    super.getSession().setAttribute("username", shiroUser.getAccount());
    LogManager.me().executeLog(LogTaskFactory.loginLog(shiroUser.getId(), getIp()));
    ShiroKit.getSession().setAttribute("sessionFlag", true);
    return REDIRECT + "/";
}
Also used : InvalidKaptchaException(com.ikoori.vip.common.exception.InvalidKaptchaException) ShiroUser(com.ikoori.vip.server.core.shiro.ShiroUser) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

InvalidKaptchaException (com.ikoori.vip.common.exception.InvalidKaptchaException)1 ShiroUser (com.ikoori.vip.server.core.shiro.ShiroUser)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 Subject (org.apache.shiro.subject.Subject)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1