From 96286178ee1c257c130cb2ad964a781f36c4eee5 Mon Sep 17 00:00:00 2001 From: yn147 <2270338776@qq.com> Date: 星期三, 10 五月 2023 16:23:27 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- src/main/java/com/qxueyou/scc/sys/action/LoginController.java | 149 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 133 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/qxueyou/scc/sys/action/LoginController.java b/src/main/java/com/qxueyou/scc/sys/action/LoginController.java index 7aa42d1..e12d6ee 100644 --- a/src/main/java/com/qxueyou/scc/sys/action/LoginController.java +++ b/src/main/java/com/qxueyou/scc/sys/action/LoginController.java @@ -1,5 +1,6 @@ package com.qxueyou.scc.sys.action; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -9,14 +10,21 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import com.alibaba.fastjson.JSONObject; import com.qxueyou.scc.base.util.*; +import com.qxueyou.scc.wx.service.IWechatService; +import freemarker.template.utility.StringUtil; import org.apache.commons.lang3.StringUtils; +import org.apache.kafka.common.network.LoginType; +import org.apache.tomcat.util.net.openssl.ciphers.Authentication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Controller; +import org.springframework.util.DigestUtils; import org.springframework.web.bind.annotation.*; import com.qxueyou.scc.admin.teacher.service.ITeacherService; @@ -95,7 +103,104 @@ @Autowired private IOrganizationService organizationService; - public static String UUNUMBER="QXYUUNUMBER"; + /** + * 灏忕▼搴廰ppID + */ + @Value("${wx.appId}") + private String appId; + + + /** + * 灏忕▼搴弒ecret + */ + @Value("${wx.secret}") + private String secret; + + /** + * 鍏紬鍙穉ppID + */ + @Value("${wx.app.appId}") + private String wxappId; + + + /** + * 鍏紬鍙穝ecret + */ + @Value("${wx.app.secret}") + private String wxsecret; + + public static String UUNUMBER="QXYUUNUMBER"; + + @Autowired + IWechatService wechatService; + + /** + * 寰俊鐧诲綍 + * + * @param uid + * @throws IOException + */ + + @PostMapping("/wxAccountsLogin") + @ApiOperation("寰俊鍏紬鍙风櫥褰�") + @ResponseBody + public Result wxAccountsLogin(String code) { + JSONObject gettoken = wechatService.gettoken(wxappId, wxsecret); + JSONObject OpenId = wechatService.getSessionKeyOrOpenId(code); + JSONObject user = wechatService.getUser(gettoken.get("access_token").toString(), OpenId.get("openid").toString()); + return new Result(true,"鎴愬姛",user); + } + + + @PostMapping("/wxlogin") + @ApiOperation("寰俊灏忕▼搴忕櫥褰�") + @ResponseBody + public Result wechatLogin(String code,String number) { + JSONObject sessionKeyOrOpenId = wechatService.getSessionKeyOrOpenId(code); + JSONObject gettoken = wechatService.gettoken(appId, secret); + Result phone = wechatService.getNumber(gettoken.get("access_token").toString(), number); + if(phone.getSuccess()){ + String hql = "from User where deleteFlag is false and mobilePhone = ? "; + System.out.println(phone.getData()); + List<Object> params = CollectionUtils.newList(phone.getData()); + User user = commonDAO.findUnique(hql,params, User.class); + if(user==null){ + //鏂板鐢ㄦ埛 + User user1=new User(); + user1.setMobilePhone(phone.getData().toString()); + user1.setOpenId(sessionKeyOrOpenId.get("openid").toString()); + commonDAO.save(user1); + //鏂板鍏宠仈瀛﹀憳 + String addUserSql = "from User where deleteFlag is false and mobilePhone = ? "; + List<Object> newParams = CollectionUtils.newList(phone.getData()); + User newUser = commonDAO.findUnique(addUserSql,newParams, User.class); + StuStudent stuStudent=new StuStudent(); + stuStudent.setStatus(StuStudent.STATUS_REGISTER); + stuStudent.setUserId(newUser.getUserId()); + stuStudent.setMobilePhone(newUser.getMobilePhone()); + commonDAO.save(stuStudent); + } + if(StringUtils.isEmpty(user.getOpenId())){ + user.setOpenId(sessionKeyOrOpenId.get("openid").toString()); + commonDAO.saveOrUpdate(user); + } + String studentSql = "from StuStudent where deleteFlag is false and userId = ? "; + List<Object> stuParams = CollectionUtils.newList(user.getUserId()); + StuStudent stuStudent = commonDAO.findUnique(studentSql, stuParams, StuStudent.class); + CacheParamters param = new CacheParamters(); + param.setUserId(user.getUserId()); + param.setCustomRoleValue(user.getEmail()); + param.setCustomOrgId(user.getImei()); + param.setCacheIpFlag(true); + // 缂撳瓨鍒拌姹傜嚎绋� + UserInfoWrapper wrapper = cacheUserInfo(param, null); + // 瀛樺埌redis + redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); + return new Result(true,"鎺堟潈鎴愬姛",CollectionUtils.newObjectMap("user",user,"ClassId",stuStudent.getClassId())); + } + return phone; + } + @ApiOperation(value = "鐧诲叆鎺ュ彛", notes = "") @ApiImplicitParams({ @@ -112,8 +217,8 @@ // 鏌ヨ鐢ㄦ埛淇℃伅 String uuNumber=null; String uuReNumber=null; - String hql = "from User where deleteFlag is false and account = ? and password = ? "; - List<Object> params = CollectionUtils.newList(account,password); + String hql = "from User where deleteFlag is false and account = ?"; + List<Object> params = CollectionUtils.newList(account); User user = commonDAO.findUnique(hql,params, User.class); if (user == null ) { return new Result(false, "鐢ㄦ埛璐︽埛銆佸瘑鐮侀敊璇�"); @@ -142,6 +247,12 @@ } // 鎻掑叆鏃ュ織 insertLoginLog(request, user, account, "SYS-LOGIN"); + String salt = user.getSalt(); + String newPassword= DigestUtils.md5DigestAsHex((salt+password).getBytes()); + //姣旇緝鐢ㄦ埛杈撳叆鐨勫瘑鐮佸姞瀵嗗悗鐨勫瓧绗︿覆鏄惁璺熸敞鍐屾椂濉啓鐨勫姞瀵嗗瘑鐮佺浉鍚� + if (!newPassword.equals(user.getPassword())) { + return new Result(false, "鐢ㄦ埛璐︽埛銆佸瘑鐮侀敊璇垨缂哄皯鍑瘉"); + } // 杩斿洖 return new Result(true, "楠岃瘉鎴愬姛",CollectionUtils.newObjectMap("uuNumber",uuNumber,"uuReNumber",uuReNumber)); } @@ -303,17 +414,17 @@ List<Object> params = null; // boolean flag=true; if ("study".equals(logType)) { - hql = "from User where deleteFlag is false and account = ? and password = ? "; - params = CollectionUtils.newList(account, password); + hql = "from User where deleteFlag is false and account = ?"; + params = CollectionUtils.newList(account); }else if("portal".equals(logType)){ - hql = "from User where deleteFlag is false and mobilePhone = ? and password = ? "; - params = CollectionUtils.newList(account, password); + hql = "from User where deleteFlag is false and mobilePhone = ?"; + params = CollectionUtils.newList(account); }else{ if(StringUtils.isEmpty(password)) { return new Result(false, "鐢ㄦ埛瀵嗙爜涓嶈兘涓虹┖"); } - hql = "from User where deleteFlag is false and mobilePhone = ? and password = ? "; - params = CollectionUtils.newList(account,password); + hql = "from User where deleteFlag is false and account = ?"; + params = CollectionUtils.newList(account); } if(StringUtils.isNotEmpty(organizationId)){ @@ -335,13 +446,19 @@ // request.getSession().removeAttribute("uuReNumber"); // } + if (user == null) { + return new Result(false, "鐢ㄦ埛璐︽埛涓嶅瓨鍦�"); + } // 鎻掑叆鏃ュ織 insertLoginLog(request, user, account, "SYS-LOGIN"); - - //鑰冭瘯鐧诲綍浼氭帶鍒秄lag鍙橀噺 鍏朵粬鐧诲綍涓嶄細 榛樿true - if (user == null) { - return new Result(false, "鐢ㄦ埛璐︽埛銆佸瘑鐮侀敊璇垨缂哄皯鍑瘉"); - } + String salt = user.getSalt(); + String newPassword= DigestUtils.md5DigestAsHex((salt+password).getBytes()); + //姣旇緝鐢ㄦ埛杈撳叆鐨勫瘑鐮佸姞瀵嗗悗鐨勫瓧绗︿覆鏄惁璺熸敞鍐屾椂濉啓鐨勫姞瀵嗗瘑鐮佺浉鍚� + if("study".equals(logType) || "portal".equals(logType) || "adminis".equals(logType)){ + if (!newPassword.equals(user.getPassword())) { + return new Result(false, "鐢ㄦ埛璐︽埛銆佸瘑鐮侀敊璇垨缂哄皯鍑瘉"); + } + } // 杩斿洖鐢ㄦ埛鍩烘湰淇℃伅 return this.loginValidate(user, 1, request, response, logType, platForm, organizationId); @@ -374,7 +491,7 @@ // 瀛樺埌redis redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); request.getSession().setAttribute(UserInfoWrapper.SESSION_USER_INFO_KEY, wrapper); - if ("study".equals(logType)) { + if ("study".equals(logType) || "portal".equals(logType)) { /*if (StringUtils.isEmpty(ClientUtils.getClassId()) && user.getRoles() == null) { return new Result(false, "璇ョ敤鎴锋湭鍔犲叆浠讳綍鐝骇鎴栨湭婵�娲伙紝璇疯仈绯荤彮涓讳换"); }*/ @@ -531,7 +648,7 @@ @ApiOperation(value = "淇敼瀵嗙爜", notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "usedPass", value = "鑰佸瘑鐮�", required = false, paramType="query", dataType = "String"), - @ApiImplicitParam(name = "pass", value = "鏂板瘑鐮�", required = false, paramType="query", dataType = "String"), + @ApiImplicitParam(name = "pass", value = "鏂板瘑鐮�", required = false, paramType=" query", dataType = "String"), }) @RequestMapping(value = "updatePassword", method = RequestMethod.POST) @ResponseBody -- Gitblit v1.8.0