/*     */ package com.picc.grab.controller.login;
/*     */ 
/*     */ import com.alibaba.fastjson.JSON;
/*     */ import com.alibaba.fastjson.JSONObject;
/*     */ import com.picc.grab.common.shiro.ShiroExt;
/*     */ import com.picc.grab.common.shiro.service.IShiroService;
/*     */ import com.picc.grab.common.shiro.service.impl.ShiroServiceImpl;
/*     */ import com.picc.grab.config.SystemInfoProperties;
/*     */ import com.picc.grab.entity.ShiroUser;
/*     */ import com.picc.grab.entity.common.vo.ResultVO;
/*     */ import com.picc.grab.util.VerificationCodeUtil;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.apache.shiro.authc.CredentialsException;
/*     */ import org.apache.shiro.authc.IncorrectCredentialsException;
/*     */ import org.apache.shiro.authc.UnknownAccountException;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.ui.ModelMap;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.bind.annotation.RestController;
/*     */ import org.springframework.web.servlet.ModelAndView;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @RestController
/*     */ public class LoginController
/*     */ {
/*  33 */   private static Logger logger = LoggerFactory.getLogger(LoginController.class);
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @Autowired
/*     */   private SystemInfoProperties systemInfoProperties;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/"})
/*     */   public ModelAndView index(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws Exception {
/*  48 */     ShiroExt shiroExt = new ShiroExt();
/*  49 */     ShiroUser shiroUser = shiroExt.getUser();
/*  50 */     if (shiroUser != null) {
/*  51 */       response.sendRedirect(request.getContextPath() + "/loginSuccess");
/*  52 */       return null;
/*     */     } 
/*     */     
/*  55 */     model.put("systemInfo", this.systemInfoProperties);
/*  56 */     return new ModelAndView("login/login");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/login"})
/*     */   @ResponseBody
/*     */   public ResultVO login(HttpServletRequest request, HttpServletResponse response) throws Exception {
/*  71 */     logger.info("LoginController.login()");
/*  72 */     ShiroExt shiroExt = new ShiroExt();
/*     */     
/*  74 */     ShiroUser shiroUser = shiroExt.getUser();
/*  75 */     if (shiroUser != null)
/*     */     {
/*  77 */       return ResultVO.success();
/*     */     }
/*     */ 
/*     */     
/*  81 */     String exception = (String)request.getAttribute("shiroLoginFailure");
/*     */     
/*  83 */     logger.info("exception=" + exception);
/*     */ 
/*     */     
/*  86 */     String username = request.getParameter("username");
/*     */     
/*  88 */     if (StringUtils.isBlank(username) && shiroExt.getUser() == null) {
/*  89 */       response.sendRedirect(request.getContextPath() + "/");
/*  90 */       return null;
/*     */     } 
/*  92 */     logger.info("--------------------- 账号登陆 ---------------" + username);
/*     */     
/*  94 */     IShiroService shiroService = ShiroServiceImpl.me();
/*  95 */     ShiroUser user = shiroService.shiroUser(username);
/*     */     
/*  97 */     String msg = "";
/*  98 */     if (exception != null) {
/*  99 */       if (UnknownAccountException.class.getName().equals(exception)) {
/* 100 */         logger.info("UnknownAccountException -- > 账号不存在：");
/* 101 */         msg = "账号不存在!";
/* 102 */       } else if (IncorrectCredentialsException.class.getName().equals(exception)) {
/* 103 */         logger.info("IncorrectCredentialsException -- > 密码不正确：");
/* 104 */         msg = "密码不正确!";
/* 105 */       } else if ("kaptchaValidateFailed".equals(exception)) {
/* 106 */         logger.info("kaptchaValidateFailed -- > 验证码错误");
/* 107 */         msg = "验证码错误!";
/* 108 */       } else if (CredentialsException.class.getName().equals(exception)) {
/* 109 */         logger.info("CredentialsException -- > 账号不存在：");
/* 110 */         msg = "账号不存在!";
/*     */       } else {
/* 112 */         msg = "登录异常!";
/* 113 */         logger.info("else -- >" + exception);
/*     */       } 
/*     */     }
/* 116 */     return ResultVO.error(msg);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/verCode"})
/*     */   @ResponseBody
/*     */   public JSONObject getVerCode(HttpServletRequest req) {
/* 129 */     String[] arr = VerificationCodeUtil.getVerificationCode();
/*     */     
/* 131 */     req.getSession().setAttribute("verCode", arr[0].toLowerCase());
/* 132 */     return JSON.parseObject("{\"verCode\": \"" + arr[1] + "\"}");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"isVerCode"})
/*     */   @ResponseBody
/*     */   public JSONObject isVerCode(String verCode, HttpServletRequest req) {
/* 146 */     String code = (String)req.getSession().getAttribute("verCode");
/* 147 */     if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(verCode) && StringUtils.equals(verCode.toLowerCase(), code)) {
/* 148 */       return JSON.parseObject("{\"success\": true}");
/*     */     }
/* 150 */     return JSON.parseObject("{\"success\": false}");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/loginSuccess"})
/*     */   public ModelAndView loginSuccess(HttpServletRequest request, ModelMap map) {
/* 161 */     logger.info("---------------------loginSuccess   登陆成功--------------- 重定向至 grab");
/*     */     
/* 163 */     return new ModelAndView("redirect:/grab");
/*     */   }
/*     */ }


/* Location:              C:\Users\Administrator\Desktop\ROOT\WEB-INF\classes\!\com\picc\grab\controller\login\LoginController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */