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 |   78 +++++++++++++++++++++++++++++++--------
 1 files changed, 62 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 81ed905..e12d6ee 100644
--- a/src/main/java/com/qxueyou/scc/sys/action/LoginController.java
+++ b/src/main/java/com/qxueyou/scc/sys/action/LoginController.java
@@ -24,6 +24,7 @@
 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;
@@ -115,6 +116,18 @@
 	@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";
 
@@ -128,8 +141,19 @@
 	 * @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("寰俊鐧诲綍")
+	@ApiOperation("寰俊灏忕▼搴忕櫥褰�")
 	@ResponseBody
 	public Result wechatLogin(String code,String number) {
 		JSONObject sessionKeyOrOpenId = wechatService.getSessionKeyOrOpenId(code);
@@ -163,10 +187,20 @@
 			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({
@@ -183,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, "鐢ㄦ埛璐︽埛銆佸瘑鐮侀敊璇�");
@@ -213,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));
 	}
@@ -374,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 account = ? and password = ? ";
-            params =  CollectionUtils.newList(account,password);
+            hql = "from User where deleteFlag is false and account = ?";
+            params =  CollectionUtils.newList(account);
         }
 
     	if(StringUtils.isNotEmpty(organizationId)){
@@ -406,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);
@@ -602,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