|
|
@@ -137,28 +137,6 @@ public class LoginController extends BaseController {
|
|
|
return success(token.getId());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * token代理页面
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping(value = "/proxy", method = RequestMethod.GET)
|
|
|
- @Deprecated
|
|
|
- public ModelAndView loginProxyByToken() {
|
|
|
- WafRequestWrapper wr = new WafRequestWrapper(request);
|
|
|
- String returnUrl = wr.getParameter("returnURL");
|
|
|
- String appId = wr.getParameter("appId");
|
|
|
- String token = wr.getParameter("token");
|
|
|
- String baseUrl = wr.getParameter("baseURL");
|
|
|
- String isLoginAll = wr.getParameter("isLoginAll");
|
|
|
- ModelMap data = new ModelMap();
|
|
|
- data.put("returnUrl", returnUrl);
|
|
|
- data.put("appId", appId);
|
|
|
- data.put("token", token);
|
|
|
- data.put("baseUrl", baseUrl);
|
|
|
- data.put("isLoginAll", isLoginAll == null ? true : isLoginAll);
|
|
|
- return new ModelAndView("/sso/proxyByToken", data);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* erp和uu互联跳转
|
|
|
* 代理登录,根据tokenId拿到当前用户登录的用户uu号和企业uu号进行登录
|
|
|
@@ -240,119 +218,6 @@ public class LoginController extends BaseController {
|
|
|
return new ModelMap("token", token.getId()).addAttribute("datalist", allowedList);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 密码输错处理
|
|
|
- *
|
|
|
- * @param userUU 用户uu号
|
|
|
- * @return 错误次数
|
|
|
- */
|
|
|
- private int inputErrorPwd(Long userUU) {
|
|
|
- // 密码输错次数+1
|
|
|
- UserRecord userRecord = userRecordService.findOne(userUU);
|
|
|
- if (userRecord == null) {
|
|
|
- userRecord = new UserRecord(userUU);
|
|
|
- }
|
|
|
- int pwdErrorCount = userRecord.getPwdErrorCount();
|
|
|
- userRecord.setPwdErrorCount(++pwdErrorCount);
|
|
|
- userService.save(userRecord);
|
|
|
-
|
|
|
- // 设置返回值
|
|
|
- return pwdErrorCount;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 用户信息没问题,直接登录
|
|
|
- *
|
|
|
- * @param userAccount 用户账号信息
|
|
|
- * @param returnUrl 跳转url
|
|
|
- * @param isLoginAll 是否登录默认应用
|
|
|
- * @return
|
|
|
- */
|
|
|
- private ModelMap loginByUser(UserAccount userAccount, String returnUrl, boolean isLoginAll) {
|
|
|
- /*
|
|
|
- * 设置登录 Cookie 最后一个参数 true 时添加 cookie 同时销毁当前 JSESSIONID
|
|
|
- * 创建信任的 JSESSIONID
|
|
|
- */
|
|
|
- // 设置登录时间,并将密码输错次数设为0
|
|
|
- UserRecord userRecord = new UserRecord(userAccount.getUserUU());
|
|
|
- userRecord.setLastLoginTime(System.currentTimeMillis());
|
|
|
- userService.save(userRecord);
|
|
|
- userAccount.setLastLoginTime(userRecord.getLastLoginTime());
|
|
|
-
|
|
|
- String baseUrl = (String) request.getSession().getAttribute("baseUrl");
|
|
|
- baseUrl = HttpUtil.decodeURL(baseUrl);
|
|
|
- SSOToken st = new SSOToken(request, userAccount.getMobile());
|
|
|
- st.setData(JSON.toJSONString(userAccount));
|
|
|
- SSOHelper.setSSOCookie(request, response, st, true);
|
|
|
-
|
|
|
- // 设置返回值,通知各个应用用户已经登录
|
|
|
- ModelMap data = new ModelMap();
|
|
|
- data = addOtherAppRequestData(userAccount, data, baseUrl, isLoginAll);
|
|
|
- data.put("returnUrl", HttpUtil.decodeURL(returnUrl));
|
|
|
- return data;
|
|
|
- }
|
|
|
-
|
|
|
- private ModelMap addOtherAppRequestData(UserAccount userAccount, ModelMap data, Object loginUrl,
|
|
|
- boolean isLoginAll) {
|
|
|
- List<App> apps = appService.findAll();
|
|
|
- List<String> loginUrls = new ArrayList<>();
|
|
|
- boolean hasLoginUrl = false;
|
|
|
- if (isLoginAll) {
|
|
|
- for (App app : apps) {
|
|
|
- if (StringUtils.isEmpty(app.getLoginUrl())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (app.getLoginUrl().equals(loginUrl)) {
|
|
|
- hasLoginUrl = true;
|
|
|
- }
|
|
|
- loginUrls.add(app.getLoginUrl());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 添加baseUrl
|
|
|
- if (!hasLoginUrl && !StringUtils.isEmpty(loginUrl)) {
|
|
|
- loginUrls.add(loginUrl.toString());
|
|
|
- }
|
|
|
-
|
|
|
- data.put("loginUrls", loginUrls);
|
|
|
- data.put("currentUrl", loginUrl);
|
|
|
-
|
|
|
- // 添加传递数据
|
|
|
- JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(userAccount));
|
|
|
- Integer maxage = (Integer) request.getAttribute(SSOConfig.SSO_COOKIE_MAXAGE);
|
|
|
- jsonObject.put("maxage", maxage);
|
|
|
- data.put("data", jsonObject);
|
|
|
- return data;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取选择企业信息(id:企业uu号,name:名称)
|
|
|
- *
|
|
|
- * @param userAccounts 用户账户信息
|
|
|
- * @param personalEnable 该应用是否允许个人账户
|
|
|
- * @return
|
|
|
- */
|
|
|
- private ModelMap getSpaceSelect(List<UserAccount> userAccounts, boolean personalEnable) {
|
|
|
- List<Map<String, Object>> spaces = new ArrayList<Map<String, Object>>();
|
|
|
- Map<String, Object> space = null;
|
|
|
- // 设置带企业账号
|
|
|
- for (UserAccount userAccount : userAccounts) {
|
|
|
- space = new HashMap<String, Object>(2);
|
|
|
- space.put("id", userAccount.getSpaceUU());
|
|
|
- space.put("name", userAccount.getSpaceName());
|
|
|
- spaces.add(space);
|
|
|
- }
|
|
|
-
|
|
|
- // 设置个人账号
|
|
|
- if (personalEnable) {
|
|
|
- space = new HashMap<String, Object>(2);
|
|
|
- space.put("id", Const.SPACEUU_PERSONAL);
|
|
|
- space.put("name", String.format("%s(个人)", userAccounts.get(0).getVipName()));
|
|
|
- spaces.add(space);
|
|
|
- }
|
|
|
- return new ModelMap("spaces", spaces);
|
|
|
- }
|
|
|
-
|
|
|
@RequestMapping(value = "/checkCode", method = RequestMethod.GET)
|
|
|
public void checkCode() {
|
|
|
try {
|
|
|
@@ -536,156 +401,18 @@ public class LoginController extends BaseController {
|
|
|
return success(loginService.loginBySms(loginParam));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 登录处理
|
|
|
- * @param userUU 用户uu号
|
|
|
- * @param appId 应用id
|
|
|
- * @param spaceUU 企业uu号
|
|
|
- * @param returnUrl 跳转地址
|
|
|
- * @return
|
|
|
- */
|
|
|
- private ModelMap login(Long userUU, String appId, String spaceUU, String returnUrl) {
|
|
|
- // 登录
|
|
|
- appId = StringUtils.isEmpty(appId) ? AccountConfig.ACCOUNT_CENTER : appId;
|
|
|
- App app = appService.findOne(appId);
|
|
|
- if (app == null) {
|
|
|
- throw new VerifyError("应用不存在");
|
|
|
- }
|
|
|
- App controlApp = StringUtils.isEmpty(app.getUserControl()) ? app : appService.findOne(app.getUserControl());
|
|
|
- boolean personalEnable = Const.YES == controlApp.getPersonalEnable();
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(spaceUU)) {
|
|
|
- /*企业uu号为空,让用户选择企业*/
|
|
|
- // 找到用户账号信息
|
|
|
- List<UserAccount> userAccounts = userAccountService.findByUserUU(controlApp.getUid(), userUU);
|
|
|
-
|
|
|
- // 没有记录
|
|
|
- if (CollectionUtils.isEmpty(userAccounts)) {
|
|
|
- // 没有记录如果当前应用允许个人账号的话,查找个人账号
|
|
|
- UserAccount userAccount = personalAccountService.findOneByUserUU(controlApp.getUid(), userUU);
|
|
|
- if (!personalEnable) {
|
|
|
- // 不支持个人账号则跳转优软云
|
|
|
- returnUrl = HOME_PAGE;
|
|
|
- }
|
|
|
- return loginByUser(userAccount, returnUrl, true);
|
|
|
- }
|
|
|
-
|
|
|
- // 应用允许个人账号,并且账号未绑定企业,或者只绑定了一个企业,直接登录
|
|
|
- if (userAccounts.size() == 1) {
|
|
|
- return loginByUser(userAccounts.get(0), returnUrl, true);
|
|
|
- }
|
|
|
-
|
|
|
- // 返回企业id和名称
|
|
|
- return getSpaceSelect(userAccounts, personalEnable);
|
|
|
- } else if (personalEnable && Long.valueOf(spaceUU).equals(Const.SPACEUU_PERSONAL)) {
|
|
|
- // 使用个人账号登录
|
|
|
- UserAccount userAccount = personalAccountService.findOneByUserUU(controlApp.getUid(), userUU);
|
|
|
- return loginByUser(userAccount, returnUrl, true);
|
|
|
- } else {
|
|
|
- // 带企业登录
|
|
|
- UserAccount userAccount = userAccountService.findOneByUserUU(controlApp.getUid(), userUU, Long.valueOf(spaceUU));
|
|
|
- return loginByUser(userAccount, returnUrl, true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 微信获取code
|
|
|
- * @param code 获取用户信息的code
|
|
|
- * @param state 验证请求
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping(value = "/wxqrLogin", method = RequestMethod.POST)
|
|
|
- @Deprecated
|
|
|
- public ModelMap wxqrLogin(@RequestParam(defaultValue = "sso") String appId, String code, String state) {
|
|
|
- // TODO 校验state
|
|
|
-
|
|
|
- // 获取用户信息
|
|
|
- OAuthInfo oAuthInfo = weChatService.getForeignInfoByCode(code);
|
|
|
- User user = null;
|
|
|
- if (oAuthInfo == null || StringUtils.isEmpty(oAuthInfo.getAccess_token())) {
|
|
|
- Long userUU = (Long) request.getSession().getAttribute("userUU");
|
|
|
- if (userUU == null) {
|
|
|
- return error("验证信息过期,请重新扫码登录");
|
|
|
- }
|
|
|
- user = new User(userUU);
|
|
|
- } else {
|
|
|
- user = userService.findByWxUnionid(oAuthInfo.getUnionid());
|
|
|
- if (user == null) {
|
|
|
- // 提示前端用户微信未绑定账号
|
|
|
- ModelMap map = new ModelMap("data", oAuthInfo);
|
|
|
- map.put("type", "weixin");
|
|
|
- Token token = new Token(map, oAuthInfo.getExpires_in());
|
|
|
- tokenService.save(token);
|
|
|
- ModelMap data = new ModelMap("hasRegister", false);
|
|
|
- data.put("token", token.getId());
|
|
|
- return success(data);
|
|
|
- }
|
|
|
- request.getSession().setAttribute("userUU", user.getUserUU());
|
|
|
- }
|
|
|
-
|
|
|
- // 登录
|
|
|
- WafRequestWrapper wr = new WafRequestWrapper(request);
|
|
|
- String spaceUU = wr.getParameter("spaceUU");
|
|
|
- String returnUrl = wr.getParameter("returnUrl");
|
|
|
- String baseUrl = wr.getParameter("baseUrl");
|
|
|
- request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
- return success(login(user.getUserUU(), appId, spaceUU, returnUrl));
|
|
|
- }
|
|
|
-
|
|
|
@GetMapping("/other")
|
|
|
public void login(String appId, Long userUU, Long spaceUU) {
|
|
|
UserAccount userAccount = spaceUU == null ? personalAccountService.findOneByUserUU(appId, userUU) : userAccountService.findOneByUserUU(appId, userUU, spaceUU);
|
|
|
- loginByUser(userAccount, null, false);
|
|
|
+ SSOToken st = new SSOToken(request, userAccount.getMobile());
|
|
|
+ st.setData(JSON.toJSONString(userAccount));
|
|
|
+ SSOHelper.setSSOCookie(request, response, st, true);
|
|
|
try {
|
|
|
printJsonP("successCallback", "{success:'1'}");
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- /**
|
|
|
- * 碧合登录接口
|
|
|
- * @param appId 应用id(优软云应用id)
|
|
|
- * @param code 第三方获取用户信息code
|
|
|
- * @return
|
|
|
- */
|
|
|
- @RequestMapping(value = "/bhLogin", method = RequestMethod.POST)
|
|
|
- @Deprecated
|
|
|
- public ModelMap bhLogin(@RequestParam(defaultValue = "city") String appId, String code) {
|
|
|
- // 获取用户信息
|
|
|
- User user = null;
|
|
|
- BiHeInfo oAuthInfo = biHeService.getForeignInfoByCode(code);
|
|
|
-
|
|
|
- String accessToken = Optional.ofNullable(oAuthInfo).map(BiHeInfo::getAccessToken).orElse(null);
|
|
|
- if (StringUtils.isEmpty(accessToken)) {
|
|
|
- Long userUU = (Long) request.getSession().getAttribute("userUU");
|
|
|
- if (userUU == null) {
|
|
|
- return error("验证信息过期");
|
|
|
- }
|
|
|
- user = new User(userUU);
|
|
|
- } else {
|
|
|
- user = userService.findByBhOpenId(oAuthInfo.getOpenId());
|
|
|
- // user为空提示未注册,不为空则放入session绑定用户使用
|
|
|
- if (user == null) {
|
|
|
- // 提示前端用户微信未绑定账号
|
|
|
- ModelMap map = new ModelMap("data", oAuthInfo);
|
|
|
- map.put("type", "bihe");
|
|
|
- Token token = new Token(map, oAuthInfo.getExpires_in());
|
|
|
- tokenService.save(token);
|
|
|
- ModelMap data = new ModelMap("hasRegister", false);
|
|
|
- data.put("token", token.getId());
|
|
|
- return success(data);
|
|
|
- }
|
|
|
- request.getSession().setAttribute("userUU", user.getUserUU());
|
|
|
- }
|
|
|
-
|
|
|
- // 登录
|
|
|
- WafRequestWrapper wr = new WafRequestWrapper(request);
|
|
|
- String spaceUU = wr.getParameter("spaceUU");
|
|
|
- String returnUrl = wr.getParameter("returnUrl");
|
|
|
- String baseUrl = wr.getParameter("baseUrl");
|
|
|
- request.getSession().setAttribute("baseUrl", baseUrl);
|
|
|
- return success(login(user.getUserUU(), appId, spaceUU, returnUrl));
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 碧合登录接口
|