From 7324a4e5ae8e0c7039896a14370bf6844ad17462 Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期四, 21 九月 2023 11:36:54 +0800
Subject: [PATCH] 代码提交

---
 Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/PasswordFreeLoginController.java |   55 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/PasswordFreeLoginController.java b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/PasswordFreeLoginController.java
index 7b4157f..5cb6929 100644
--- a/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/PasswordFreeLoginController.java
+++ b/Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/controller/PasswordFreeLoginController.java
@@ -2,30 +2,73 @@
 
 import com.vci.ubcs.code.service.IPasswordFreeLoginService;
 import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.tool.api.R;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+
+import static com.vci.ubcs.starter.util.AESUtils.aesDecrypt;
+import static com.vci.ubcs.starter.util.AESUtils.aesEncrypt;
 
 /**
  * @author ludc
  * @date 2023/9/12 9:07
  */
-@RestController
+@Controller
 @RequestMapping("/passwordFree")
 @Api(value = "鍏嶅瘑鐧诲綍鎺ュ彛", tags = "鍏嶅瘑鐧诲綍鎺ュ彛")
+@Slf4j
 public class PasswordFreeLoginController {
+
+	// 鍒汉璋冪敤鎴戜滑鐨勫崟鐐归噸瀹氬悜鐨勫湴鍧�
+	@Value("${password-free.sso-redirect-addr}")
+	private String ssoRedirectAddr;
 
 	@Resource
 	private IPasswordFreeLoginService passwordFreeLoginService;
 
 	@PostMapping("/login")
-	public R passwordFreeLogin(@RequestParam String username) {
-		boolean resBoolean = passwordFreeLoginService.passwordFreeLogin(username);
-		return R.status(resBoolean);
+	@ResponseBody
+	public R passwordFreeLogin(@RequestParam("userName") String username, HttpServletRequest request) {
+		boolean status;
+		try {
+			status = passwordFreeLoginService.pwdFreeLoginByBoolean(username,request);
+		}catch (Exception e){
+			throw new ServiceException("鍏嶅瘑鐧诲綍鑾峰彇token澶辫触锛�"+e.getMessage());
+		}
+		return R.status(status);
 	}
 
-
-
+	/**
+	 * 鍗曠偣鐧诲綍
+	 * @param request
+	 * @return
+	 * @throws Exception
+	 */
+	@GetMapping("/ssoLogin")
+	public String oaSsoLogin(HttpServletRequest request) throws IOException {
+		String token;
+		try {
+			token = passwordFreeLoginService.ssoFreeLogin(request);
+		}catch (Exception e){
+			throw new ServiceException("鍗曠偣鐧诲綍鑾峰彇token澶辫触:"+e.getMessage());
+		}
+//		response.setHeader("tokenInfo",token);
+//		response.setCharacterEncoding("utf-8");
+//		response.setContentType("application/json");
+		request.setAttribute("tokenInfo",token);
+		//response.sendRedirect(ssoRedirectAddr);
+		return "forward:/sso";
+	}
 
 }

--
Gitblit v1.9.3