You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.5 KiB
Java

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<String, Object> loginAccount(@RequestParam(value = "login")String login,
@RequestParam(value = "password")String password,
@RequestParam(value = "isMD5",required = false,defaultValue = "false")Boolean isMD5){
try{
Map<String, Object> 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<String, Object> loginAccountBind(@RequestParam("login")String login, @RequestParam("password")String password,
@RequestParam("qywxUserId")String qywxUserId){
try{
Map<String, Object> 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";
}
}