900781d3
王富生
提交
|
1
2
3
4
5
|
package com.zteits.oa.report.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
|
9ce77292
xiejianpeng
员工管理
|
6
|
import com.zteits.oa.api.service.report.query.AsraOpQueryService;
|
900781d3
王富生
提交
|
7
8
9
10
11
12
13
|
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
|
d365b3fa
王富生
提交
|
14
|
import org.springframework.web.bind.annotation.RequestMethod;
|
900781d3
王富生
提交
|
15
16
|
import org.springframework.web.bind.annotation.RestController;
|
d365b3fa
王富生
提交
|
17
|
import com.alibaba.fastjson.JSONObject;
|
900781d3
王富生
提交
|
18
19
20
21
22
23
24
|
import com.zteits.oa.api.base.bean.BizResult;
import com.zteits.oa.api.base.constants.ErrorType;
import com.zteits.oa.api.base.constants.SessionEnum;
import com.zteits.oa.api.dto.asraop.AsraOpDTO;
import com.zteits.oa.api.dto.asraop.LoginOathRes;
import com.zteits.oa.api.dto.asraop.param.AsraOpQueryReq;
import com.zteits.oa.api.dto.asraop.param.LoginOauthReq;
|
0b156ed7
王富生
提交
|
25
|
import com.zteits.oa.report.vo.OAuthResult;
|
900781d3
王富生
提交
|
26
27
28
29
30
31
32
33
34
35
36
37
|
import com.zteits.oa.util.MD5Utils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api("用户登录授权")
@RestController
@RequestMapping("/oauth")
public class OAuthController {
private static final Logger logger = LoggerFactory.getLogger(OAuthController.class);
@Autowired
|
9ce77292
xiejianpeng
员工管理
|
38
|
private AsraOpQueryService asraOpQueryService;
|
900781d3
王富生
提交
|
39
40
41
42
43
44
|
@Autowired
private HttpServletRequest request;
@ApiOperation("用户登录")
@PostMapping("/login")
|
0b156ed7
王富生
提交
|
45
46
|
public OAuthResult<LoginOathRes> login(@RequestBody LoginOauthReq req ) throws Exception {
OAuthResult<LoginOathRes> result = this._login(req);
|
900781d3
王富生
提交
|
47
48
49
50
51
52
53
54
|
return result;
}
/**
* 登陆验证.<br/>
* @param req
* @return
* 2018年7月31日 wangfs.<br/>
*/
|
0b156ed7
王富生
提交
|
55
56
|
private OAuthResult<LoginOathRes> _login(LoginOauthReq req ){
OAuthResult<LoginOathRes> result = new OAuthResult<LoginOathRes>(false);
|
900781d3
王富生
提交
|
57
58
59
60
61
|
LoginOathRes loginOathRes = new LoginOathRes();
String loginCode = req.getLoginCode();
String passWord = req.getPassWord();
if(StringUtils.isEmpty(loginCode) || StringUtils.isEmpty(passWord)) {
logger.info("校验登录信息,用户名 或者 登录密码为空!");
|
0b156ed7
王富生
提交
|
62
|
result.setErrorType(ErrorType.PARAMM_NULL, "用户名 或者 登录密码为空");
|
900781d3
王富生
提交
|
63
64
65
66
67
68
|
}
AsraOpQueryReq asraOpQueryRe = new AsraOpQueryReq();
AsraOpDTO asraOpDTO = new AsraOpDTO();
boolean isCheckSuccess = false;
//1.判断登录账号/密码
asraOpQueryRe.setLoginCode(loginCode);
|
9ce77292
xiejianpeng
员工管理
|
69
|
BizResult<AsraOpDTO> asraOpReult = asraOpQueryService.queryAsraOp(asraOpQueryRe);
|
900781d3
王富生
提交
|
70
71
72
73
|
if(asraOpReult != null && asraOpReult.getData() != null){
asraOpDTO = asraOpReult.getData();
if(StringUtils.isEmpty(asraOpDTO.getLoginCode())){
logger.info("{}登录账号不存在",loginCode);
|
0b156ed7
王富生
提交
|
74
|
result.setErrorType(ErrorType.AUTH_LOGIN_ERROR, "登录账号不存在!");
|
900781d3
王富生
提交
|
75
76
77
|
}else{
if(!asraOpDTO.getLoginPassword().equalsIgnoreCase(MD5Utils.enMD5(passWord))){
logger.info("{}登录账号输入的密码不正确",loginCode);
|
0b156ed7
王富生
提交
|
78
|
result.setErrorType(ErrorType.AUTH_PASS_ERROR, "登录密码不匹配!");
|
900781d3
王富生
提交
|
79
80
81
82
83
84
|
}else{
isCheckSuccess = true;
}
}
}else{
|
0b156ed7
王富生
提交
|
85
|
result.setErrorType(ErrorType.BIZ_ERROR, "用户登录失败");
|
900781d3
王富生
提交
|
86
87
88
89
90
91
92
93
94
95
96
97
98
|
}
if(isCheckSuccess){
HttpSession session = request.getSession();
session.setAttribute(SessionEnum.USER_INFO.key(), asraOpDTO);
logger.info("---获取到的session_id={}",session.getId());
loginOathRes.setOpId(asraOpDTO.getId());
loginOathRes.setLoginCode(loginCode);
loginOathRes.setUserName(asraOpDTO.getOpName());
loginOathRes.setCityId(asraOpDTO.getCityId());
loginOathRes.setCityName(asraOpDTO.getCityName());
loginOathRes.setAccessToken(session.getId());
|
0b156ed7
王富生
提交
|
99
|
loginOathRes.setRoleId(asraOpDTO.getRoleId());
|
900781d3
王富生
提交
|
100
|
result.setData(loginOathRes);
|
0b156ed7
王富生
提交
|
101
|
result.setErrorType(ErrorType.BIZ_SUCCESS, "登录成功");
|
900781d3
王富生
提交
|
102
103
104
105
106
|
}
return result;
}
|
d365b3fa
王富生
提交
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/**
* 退出登录
* @param req
* @return
* 2018年7月31日 wangfs.<br/>
*/
@ApiOperation("用户登出")
@RequestMapping("/loginout")
public OAuthResult<LoginOathRes> loginOut() {
HttpSession session = request.getSession();
AsraOpDTO userInfo = (AsraOpDTO)request.getSession().getAttribute(SessionEnum.USER_INFO.key());
//登出
session.invalidate();
if(userInfo==null){
return new OAuthResult<>(true);
}
logger.info("end用户登出..");
return new OAuthResult<>(true);
}
|
900781d3
王富生
提交
|
126
127
128
|
}
|