package com.kiisoo.ic.login.controller; import com.kiisoo.ic.common.BaseController; import com.kiisoo.ic.login.bean.LoginBean; import com.kiisoo.ic.login.enums.LoginEnum; import com.kiisoo.ic.login.service.LoginService; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpSession; import java.util.HashMap; import java.util.Map; /** * @Description: 用户登入 * @Author: wangyinjia * @Date: 2020/2/18 * @Company: kiisoo * @Version: 1.0 */ @Controller @Slf4j public class LoginController extends BaseController { /** * 登录 service */ private final LoginService loginService; @Autowired public LoginController(LoginService loginService) { this.loginService = loginService; } /** * 登录账号 * @param login 用户名 * @param password 密码 * @return 成功/失败 */ @RequestMapping(value = "/login",method = RequestMethod.GET) @ResponseBody public Map loginAccount(@RequestParam(value = "login")String login, @RequestParam(value = "password")String password, @RequestParam(value = "isMD5",required = false,defaultValue = "false")Boolean isMD5){ try{ Map resultMap = new HashMap<>(); LoginBean loginBean = loginService.login(login, password,isMD5); resultMap.put("code", loginBean.getLoginInfo().get("code")); resultMap.put("results", loginBean); resultMap.put("success", Boolean.TRUE); return resultMap; }catch (Exception e){ log.error("登录失败", e); return fail(); } } /** * 登录账号 * @param login 用户名 * @param password 密码 * @param qywxUserId 企业微信账号 * @return 成功/失败 */ @RequestMapping(value = "/login/bind",method = RequestMethod.GET) @ResponseBody public Map loginAccountBind(@RequestParam("login")String login, @RequestParam("password")String password, @RequestParam("qywxUserId")String qywxUserId){ try{ Map resultMap = new HashMap<>(); LoginBean loginBean = loginService.login(login, password,false); resultMap.put("code", loginBean.getLoginInfo().get("code")); if (LoginEnum.LOGIN_SUCCEED.getCode().equals(loginBean.getLoginInfo().get("code"))){ loginService.bindQywxUserIdByUserId(loginBean.getUserId(),qywxUserId); } resultMap.put("results", loginBean); resultMap.put("success", Boolean.TRUE); return resultMap; }catch (Exception e){ log.error("登录失败", e); return fail(); } } /** * 登出 * @param session 用户会话 * @return string */ @RequestMapping("/logout") public String logOut(HttpSession session) { Subject subject = SecurityUtils.getSubject(); subject.logout(); return "login"; } }