Java Code Examples for org.jeecg.common.api.vo.Result#isSuccess()
The following examples show how to use
org.jeecg.common.api.vo.Result#isSuccess() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThirdLoginController.java From jeecg-boot with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @RequestMapping(value = "/getLoginUser/{token}", method = RequestMethod.GET) @ResponseBody public Result<JSONObject> getLoginUser(@PathVariable("token") String token) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); String username = JwtUtil.getUsername(token); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } JSONObject obj = new JSONObject(); //用户登录信息 obj.put("userInfo", sysUser); //token 信息 obj.put("token", token); result.setResult(obj); result.setSuccess(true); result.setCode(200); sysBaseAPI.addLog("用户名: " + username + ",登录成功[第三方用户]!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 2
Source File: ThirdLoginController.java From jeecg-cloud with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @RequestMapping(value = "/getLoginUser/{token}", method = RequestMethod.GET) @ResponseBody public Result<JSONObject> getLoginUser(@PathVariable("token") String token) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); String username = JwtUtil.getUsername(token); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } JSONObject obj = new JSONObject(); //用户登录信息 obj.put("userInfo", sysUser); //token 信息 obj.put("token", token); result.setResult(obj); result.setSuccess(true); result.setCode(200); sysBaseAPI.addLog("用户名: " + username + ",登录成功[第三方用户]!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 3
Source File: LoginController.java From jeecg-cloud with Apache License 2.0 | 5 votes |
/** * 手机号登录接口 * * @param jsonObject * @return */ @ApiOperation("手机号登录接口") @PostMapping("/phoneLogin") public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) { Result<JSONObject> result = new Result<JSONObject>(); String phone = jsonObject.getString("mobile"); //校验用户有效性 SysUser sysUser = sysUserService.getUserByPhone(phone); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String smscode = jsonObject.getString("captcha"); Object code = redisUtil.get(phone); if (!smscode.equals(code)) { result.setMessage("手机验证码错误"); return result; } //用户信息 userInfo(sysUser, result); //添加日志 sysBaseAPI.addLog("用户名: " + sysUser.getUsername() + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 4
Source File: LoginController.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 手机号登录接口 * * @param jsonObject * @return */ @ApiOperation("手机号登录接口") @PostMapping("/phoneLogin") public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) { Result<JSONObject> result = new Result<JSONObject>(); String phone = jsonObject.getString("mobile"); //校验用户有效性 SysUser sysUser = sysUserService.getUserByPhone(phone); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String smscode = jsonObject.getString("captcha"); Object code = redisUtil.get(phone); if (!smscode.equals(code)) { result.setMessage("手机验证码错误"); return result; } //用户信息 userInfo(sysUser, result); //添加日志 sysBaseAPI.addLog("用户名: " + sysUser.getUsername() + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 5
Source File: LoginController.java From jeecg-boot-with-activiti with MIT License | 5 votes |
/** * 手机号登录接口 * * @param jsonObject * @return */ @ApiOperation("手机号登录接口") @PostMapping("/phoneLogin") public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) { Result<JSONObject> result = new Result<JSONObject>(); String phone = jsonObject.getString("mobile"); //校验用户有效性 SysUser sysUser = sysUserService.getUserByPhone(phone); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String smscode = jsonObject.getString("captcha"); Object code = redisUtil.get(phone); if (!smscode.equals(code)) { result.setMessage("手机验证码错误"); return result; } //用户信息 userInfo(sysUser, result); //添加日志 sysBaseAPI.addLog("用户名: " + sysUser.getUsername() + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 6
Source File: LoginController.java From teaching with Apache License 2.0 | 5 votes |
/** * 手机号登录接口 * * @param jsonObject * @return */ @ApiOperation("手机号登录接口") @PostMapping("/phoneLogin") public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) { Result<JSONObject> result = new Result<JSONObject>(); String phone = jsonObject.getString("mobile"); //校验用户有效性 SysUser sysUser = sysUserService.getUserByPhone(phone); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String smscode = jsonObject.getString("captcha"); Object code = redisUtil.get(phone); if (!smscode.equals(code)) { result.setMessage("手机验证码错误"); return result; } //用户信息 userInfo(sysUser, result); //添加日志 sysBaseAPI.addLog("用户名: " + sysUser.getUsername() + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 7
Source File: CasClientController.java From teaching with Apache License 2.0 | 4 votes |
@GetMapping("/validateLogin") public Object validateLogin(@RequestParam(name="ticket") String ticket, @RequestParam(name="service") String service, HttpServletRequest request, HttpServletResponse response) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); log.info("Rest api login."); try { String validateUrl = prefixUrl+"/p3/serviceValidate"; String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service); log.info("res."+res); final String error = XmlUtils.getTextForElement(res, "authenticationFailure"); if(StringUtils.isNotEmpty(error)) { throw new Exception(error); } final String principal = XmlUtils.getTextForElement(res, "user"); if (StringUtils.isEmpty(principal)) { throw new Exception("No principal was found in the response from the CAS server."); } log.info("-------token----username---"+principal); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(principal); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword()); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //获取用户部门信息 JSONObject obj = new JSONObject(); List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); obj.put("departs", departs); if (departs == null || departs.size() == 0) { obj.put("multi_depart", 0); } else if (departs.size() == 1) { sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode()); obj.put("multi_depart", 1); } else { obj.put("multi_depart", 2); } obj.put("token", token); obj.put("userInfo", sysUser); result.setResult(obj); result.success("登录成功"); } catch (Exception e) { //e.printStackTrace(); result.error500(e.getMessage()); } return new HttpEntity<>(result); }
Example 8
Source File: LoginController.java From jeecg-boot with Apache License 2.0 | 4 votes |
/** * app登录 * @param sysLoginModel * @return * @throws Exception */ @RequestMapping(value = "/mLogin", method = RequestMethod.POST) public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } String orgCode = sysUser.getOrgCode(); if(oConvertUtils.isEmpty(orgCode)) { //如果当前用户无选择部门 查看部门关联信息 List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); if (departs == null || departs.size() == 0) { result.error500("用户暂未归属部门,不可登录!"); return result; } orgCode = departs.get(0).getOrgCode(); sysUser.setOrgCode(orgCode); this.sysUserService.updateUserDepart(username, orgCode); } JSONObject obj = new JSONObject(); //用户登录信息 obj.put("userInfo", sysUser); // 生成token String token = JwtUtil.sign(username, syspassword); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //token 信息 obj.put("token", token); result.setResult(obj); result.setSuccess(true); result.setCode(200); sysBaseAPI.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 9
Source File: LoginController.java From jeecg-boot with Apache License 2.0 | 4 votes |
@ApiOperation("登录接口") @RequestMapping(value = "/login", method = RequestMethod.POST) public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){ Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //前端密码加密,后端进行密码解密 //password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密 //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //update-begin-author:taoyan date:20190828 for:校验验证码 String captcha = sysLoginModel.getCaptcha(); if(captcha==null){ result.error500("验证码无效"); return result; } String lowerCaseCaptcha = captcha.toLowerCase(); String realKey = MD5Util.MD5Encode(lowerCaseCaptcha+sysLoginModel.getCheckKey(), "utf-8"); Object checkCode = redisUtil.get(realKey); if(checkCode==null || !checkCode.equals(lowerCaseCaptcha)) { result.error500("验证码错误"); return result; } //update-end-author:taoyan date:20190828 for:校验验证码 //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } //用户登录信息 userInfo(sysUser, result); sysBaseAPI.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 10
Source File: CasClientController.java From jeecg-boot with Apache License 2.0 | 4 votes |
@GetMapping("/validateLogin") public Object validateLogin(@RequestParam(name="ticket") String ticket, @RequestParam(name="service") String service, HttpServletRequest request, HttpServletResponse response) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); log.info("Rest api login."); try { String validateUrl = prefixUrl+"/p3/serviceValidate"; String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service); log.info("res."+res); final String error = XmlUtils.getTextForElement(res, "authenticationFailure"); if(StringUtils.isNotEmpty(error)) { throw new Exception(error); } final String principal = XmlUtils.getTextForElement(res, "user"); if (StringUtils.isEmpty(principal)) { throw new Exception("No principal was found in the response from the CAS server."); } log.info("-------token----username---"+principal); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(principal); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword()); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //获取用户部门信息 JSONObject obj = new JSONObject(); List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); obj.put("departs", departs); if (departs == null || departs.size() == 0) { obj.put("multi_depart", 0); } else if (departs.size() == 1) { sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode()); obj.put("multi_depart", 1); } else { obj.put("multi_depart", 2); } obj.put("token", token); obj.put("userInfo", sysUser); result.setResult(obj); result.success("登录成功"); } catch (Exception e) { //e.printStackTrace(); result.error500(e.getMessage()); } return new HttpEntity<>(result); }
Example 11
Source File: LoginController.java From teaching with Apache License 2.0 | 4 votes |
/** * app登录 * @param sysLoginModel * @return * @throws Exception */ @RequestMapping(value = "/mLogin", method = RequestMethod.POST) public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } String orgCode = sysUser.getOrgCode(); if(oConvertUtils.isEmpty(orgCode)) { //如果当前用户无选择部门 查看部门关联信息 List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); if (departs == null || departs.size() == 0) { result.error500("用户暂未归属部门,不可登录!"); return result; } orgCode = departs.get(0).getOrgCode(); sysUser.setOrgCode(orgCode); this.sysUserService.updateUserDepart(username, orgCode); } JSONObject obj = new JSONObject(); //用户登录信息 obj.put("userInfo", sysUser); // 生成token String token = JwtUtil.sign(username, syspassword); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //token 信息 obj.put("token", token); result.setResult(obj); result.setSuccess(true); result.setCode(200); sysBaseAPI.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 12
Source File: LoginController.java From teaching with Apache License 2.0 | 4 votes |
@ApiOperation("登录接口") @RequestMapping(value = "/login", method = RequestMethod.POST) public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){ Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //前端密码加密,后端进行密码解密 //password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密 //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //update-begin-author:taoyan date:20190828 for:校验验证码 String captcha = sysLoginModel.getCaptcha(); if(captcha==null){ result.error500("验证码无效"); return result; } String lowerCaseCaptcha = captcha.toLowerCase(); String realKey = MD5Util.MD5Encode(lowerCaseCaptcha+sysLoginModel.getCheckKey(), "utf-8"); Object checkCode = redisUtil.get(realKey); if(checkCode==null || !checkCode.equals(lowerCaseCaptcha)) { result.error500("验证码错误"); return result; } //update-end-author:taoyan date:20190828 for:校验验证码 //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } //用户登录信息 userInfo(sysUser, result); sysBaseAPI.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 13
Source File: CasClientController.java From jeecg-cloud with Apache License 2.0 | 4 votes |
@GetMapping("/validateLogin") public Object validateLogin(@RequestParam(name="ticket") String ticket, @RequestParam(name="service") String service, HttpServletRequest request, HttpServletResponse response) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); log.info("Rest api login."); try { String validateUrl = prefixUrl+"/p3/serviceValidate"; String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service); log.info("res."+res); final String error = XmlUtils.getTextForElement(res, "authenticationFailure"); if(StringUtils.isNotEmpty(error)) { throw new Exception(error); } final String principal = XmlUtils.getTextForElement(res, "user"); if (StringUtils.isEmpty(principal)) { throw new Exception("No principal was found in the response from the CAS server."); } log.info("-------token----username---"+principal); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(principal); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword()); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //获取用户部门信息 JSONObject obj = new JSONObject(); List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); obj.put("departs", departs); if (departs == null || departs.size() == 0) { obj.put("multi_depart", 0); } else if (departs.size() == 1) { sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode()); obj.put("multi_depart", 1); } else { obj.put("multi_depart", 2); } obj.put("token", token); obj.put("userInfo", sysUser); result.setResult(obj); result.success("登录成功"); } catch (Exception e) { //e.printStackTrace(); result.error500(e.getMessage()); } return new HttpEntity<>(result); }
Example 14
Source File: LoginController.java From jeecg-boot-with-activiti with MIT License | 4 votes |
/** * app登录 * @param sysLoginModel * @return * @throws Exception */ @RequestMapping(value = "/mLogin", method = RequestMethod.POST) public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } String orgCode = sysUser.getOrgCode(); if(oConvertUtils.isEmpty(orgCode)) { //如果当前用户无选择部门 查看部门关联信息 List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); if (departs == null || departs.size() == 0) { result.error500("用户暂未归属部门,不可登录!"); return result; } orgCode = departs.get(0).getOrgCode(); sysUser.setOrgCode(orgCode); this.sysUserService.updateUserDepart(username, orgCode); } JSONObject obj = new JSONObject(); //用户登录信息 obj.put("userInfo", sysUser); // 生成token String token = JwtUtil.sign(username, syspassword); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //token 信息 obj.put("token", token); result.setResult(obj); result.setSuccess(true); result.setCode(200); sysBaseAPI.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 15
Source File: LoginController.java From jeecg-boot-with-activiti with MIT License | 4 votes |
@ApiOperation("登录接口") @RequestMapping(value = "/login", method = RequestMethod.POST) public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){ Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //前端密码加密,后端进行密码解密 //password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密 //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //update-begin-author:taoyan date:20190828 for:校验验证码 Object checkCode = redisUtil.get(sysLoginModel.getCheckKey()); if(checkCode==null) { result.error500("验证码失效"); return result; } if(!checkCode.equals(sysLoginModel.getCaptcha())) { result.error500("验证码错误"); return result; } //update-end-author:taoyan date:20190828 for:校验验证码 //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } //用户登录信息 userInfo(sysUser, result); sysBaseAPI.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 16
Source File: CasClientController.java From jeecg-boot-with-activiti with MIT License | 4 votes |
@GetMapping("/validateLogin") public Object validateLogin(@RequestParam(name="ticket") String ticket, @RequestParam(name="service") String service, HttpServletRequest request, HttpServletResponse response) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); log.info("Rest api login."); try { String validateUrl = prefixUrl+"/p3/serviceValidate"; String res = CASServiceUtil.getSTValidate(validateUrl, ticket, service); log.info("res."+res); final String error = XmlUtils.getTextForElement(res, "authenticationFailure"); if(StringUtils.isNotEmpty(error)) { throw new Exception(error); } final String principal = XmlUtils.getTextForElement(res, "user"); if (StringUtils.isEmpty(principal)) { throw new Exception("No principal was found in the response from the CAS server."); } log.info("-------token----username---"+principal); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(principal); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } String token = JwtUtil.sign(sysUser.getUsername(), sysUser.getPassword()); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //获取用户部门信息 JSONObject obj = new JSONObject(); List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); obj.put("departs", departs); if (departs == null || departs.size() == 0) { obj.put("multi_depart", 0); } else if (departs.size() == 1) { sysUserService.updateUserDepart(principal, departs.get(0).getOrgCode()); obj.put("multi_depart", 1); } else { obj.put("multi_depart", 2); } obj.put("token", token); obj.put("userInfo", sysUser); result.setResult(obj); result.success("登录成功"); } catch (Exception e) { //e.printStackTrace(); result.error500(e.getMessage()); } return new HttpEntity<>(result); }
Example 17
Source File: LoginController.java From jeecg-cloud with Apache License 2.0 | 4 votes |
/** * app登录 * @param sysLoginModel * @return * @throws Exception */ @RequestMapping(value = "/mLogin", method = RequestMethod.POST) public Result<JSONObject> mLogin(@RequestBody SysLoginModel sysLoginModel) throws Exception { Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } String orgCode = sysUser.getOrgCode(); if(oConvertUtils.isEmpty(orgCode)) { //如果当前用户无选择部门 查看部门关联信息 List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId()); if (departs == null || departs.size() == 0) { result.error500("用户暂未归属部门,不可登录!"); return result; } orgCode = departs.get(0).getOrgCode(); sysUser.setOrgCode(orgCode); this.sysUserService.updateUserDepart(username, orgCode); } JSONObject obj = new JSONObject(); //用户登录信息 obj.put("userInfo", sysUser); // 生成token String token = JwtUtil.sign(username, syspassword); // 设置超时时间 redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000); //token 信息 obj.put("token", token); result.setResult(obj); result.setSuccess(true); result.setCode(200); sysBaseAPI.addLog("用户名: " + username + ",登录成功[移动端]!", CommonConstant.LOG_TYPE_1, null); return result; }
Example 18
Source File: LoginController.java From jeecg-cloud with Apache License 2.0 | 4 votes |
@ApiOperation("登录接口") @RequestMapping(value = "/login", method = RequestMethod.POST) public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){ Result<JSONObject> result = new Result<JSONObject>(); String username = sysLoginModel.getUsername(); String password = sysLoginModel.getPassword(); //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //前端密码加密,后端进行密码解密 //password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密 //update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题 //update-begin-author:taoyan date:20190828 for:校验验证码 String captcha = sysLoginModel.getCaptcha(); if(captcha==null){ result.error500("验证码无效"); return result; } String lowerCaseCaptcha = captcha.toLowerCase(); String realKey = MD5Util.MD5Encode(lowerCaseCaptcha+sysLoginModel.getCheckKey(), "utf-8"); Object checkCode = redisUtil.get(realKey); if(checkCode==null || !checkCode.equals(lowerCaseCaptcha)) { result.error500("验证码错误"); return result; } //update-end-author:taoyan date:20190828 for:校验验证码 //1. 校验用户是否有效 SysUser sysUser = sysUserService.getUserByName(username); result = sysUserService.checkUserIsEffective(sysUser); if(!result.isSuccess()) { return result; } //2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); String syspassword = sysUser.getPassword(); if (!syspassword.equals(userpassword)) { result.error500("用户名或密码错误"); return result; } //用户登录信息 userInfo(sysUser, result); sysBaseAPI.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null); return result; }