午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

Unity&Springboot實(shí)現(xiàn)本地登陸驗證

瀏覽:21日期:2023-02-22 17:38:09
目錄Springboot使用IDEA編譯器IDEA上實(shí)現(xiàn)登錄驗證返回登錄是否成功和登陸用戶的id信息Unity端的請求Springboot使用IDEA編譯器IDEA上實(shí)現(xiàn)登錄驗證

因為這里只能返回網(wǎng)頁,但是我們需要返回登陸是否成功的數(shù)據(jù)所以下面還需要寫一個請求方法。如果登陸失敗則將session域中的id刪除,這樣在unity判斷是否登錄成功時會直接按請求錯誤抓取

//登錄操作 @RequestMapping('/login') public String login(HttpServletRequest request, @RequestParam('userType') String userType, Map<String, Object> map,HttpSession session) {session.setAttribute('id',request.getParameter('id'));String id = session.getAttribute('id').toString();String password = request.getParameter('password');//如果是管理員登錄則查詢管理員信息表if(userType.equals('0')){ Administrators administrator = administratorsService.login(id, password); if(administrator != null){System.out.println('登陸成功');return 'redirect:/ScheduleInfo'; }else {map.put('msg','賬號或密碼錯誤');//如果登陸失敗則將session域中的id刪除,這樣在unity判斷是否登錄成功時會直接按請求錯誤抓取session.removeAttribute('id');return 'login'; }}else { //如果是普通用戶登錄則查找普通用戶表 Employees employee = employeesService.login(id, password); if(employee != null){if (employeesService.findJobById(id).getJob().equals('巡檢人員')){ System.out.println('登陸成功'); return 'redirect:/xInfo';}else { System.out.println('登陸成功'); return 'redirect:/wInfo';} }else {map.put('msg','賬號或密碼錯誤');session.removeAttribute('id');return 'login'; }} }返回登錄是否成功和登陸用戶的id信息

這里使用 @ResponseBody注解,使返回的是數(shù)據(jù)而不是網(wǎng)頁

@RequestMapping('/getUserInfo') @ResponseBody public String getUserInfo(HttpSession session){System.out.println('收到unity登錄請求');//因為登陸失敗以后session域中的id會被刪除,所以判斷為null則登錄失敗if(session.getAttribute('id') != null){ String id = session.getAttribute('id').toString(); System.out.println('登陸成功'); return id ;}else { System.out.println('登陸失敗'); return null;} }Unity端的請求

一個簡單的登陸注冊界面

Unity&Springboot實(shí)現(xiàn)本地登陸驗證

Unity&Springboot實(shí)現(xiàn)本地登陸驗證

上腳本,看注釋

using System.Collections;using UnityEngine;using UnityEngine.UI;using UnityEngine.SceneManagement;using UnityEngine.Networking;public class HttpHelper : MonoBehaviour{//發(fā)出登錄請求 private string postUrl = 'http://47.xx.75.xx:8080/login';//如果是本地運(yùn)行則將前面的47.96.75.29換成localhost //獲得登錄是否成功的數(shù)據(jù),也就是運(yùn)行上面第二個代碼的內(nèi)瓤 private string postUrl2 = 'http://47.xx.75.xx:8080/getUserInfo'; public GameObject[] uis; public GameObject backLoginObj; public Text massage; public Text countText; public Text passwordText; private const string userType = 'userType'; private const string userName = 'id'; private const string password = 'password'; public void loginTest() { //這個方法和登錄按鈕綁定,用于觸發(fā)異步方法PostStartCoroutine('Post'); } [System.Obsolete] IEnumerator Post() { //發(fā)送登錄表單,每個人不一樣,根據(jù)自己需要的表單參數(shù)來,一般就是賬號密碼,這里的userType就是管理員和員工的分類,0是管理員,1是員工。WWWForm form = new WWWForm();form.AddField(userType, '0');form.AddField(userName, countText.text);form.AddField(password, passwordText.text);//這里發(fā)出了登錄請求//利用UnityWebRequest通過請求路徑這個和postman的操作類似,將表單發(fā)送出去UnityWebRequest request = UnityWebRequest.Post(postUrl, form);yield return request.SendWebRequest();if (request.isHttpError || request.isNetworkError){ Debug.LogError(request.error);}//這里獲取了登錄是否成功的數(shù)據(jù)UnityWebRequest request2 = UnityWebRequest.Get(postUrl2);yield return request2.SendWebRequest();//如果登陸失敗的Session域中的id是空的,所以會報錯,也就是判斷登陸是否成功的依據(jù)。if (request2.isHttpError || request2.isNetworkError){ massage.text = '登陸失敗,賬號或密碼錯誤';}else{//反之如果登錄成功則獲得返回的數(shù)據(jù),這里就是用戶的id string receiveContent = request2.downloadHandler.text;//這是個普通的ui操作,我的構(gòu)想是如果登錄成功則將這些ui隱藏只顯示massage和一個返回鍵 foreach (GameObject ui in uis) {ui.SetActive(false); } massage.gameObject.SetActive(true); backLoginObj.SetActive(true);//如果返回的數(shù)據(jù)和用戶輸入時的賬號一樣時則判斷登陸成功 if (receiveContent == countText.text) {massage.text = '登陸成功,歡迎管理員' + receiveContent; } else//反之登陸失敗 {massage.text = '登陸失敗,賬號或密碼錯誤'; }}StopCoroutine('Post'); } public void backLogin() {SceneManager.LoadScene('SampleScene'); }}

最后的運(yùn)行結(jié)果

Unity&Springboot實(shí)現(xiàn)本地登陸驗證

Unity&Springboot實(shí)現(xiàn)本地登陸驗證

Unity&Springboot實(shí)現(xiàn)本地登陸驗證

到此這篇關(guān)于Unity&Springboot服務(wù)器/本地登陸驗證的文章就介紹到這了,更多相關(guān)Unity&Springboot服務(wù)器/本地登陸驗證內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 四虎成人免费 | 亚洲综合一区二区 | 99热这里只有精品1 中文字幕第18页 | 亚洲精品久久久久久久久 | 国产精品久久久国产盗摄 | 一区在线观看 | 91福利视频网 | 97潮色| 日韩久久久精品 | 污污视频在线观看免费 | av狠狠操 | 国产丰满美女做爰 | 国产天天骚 | 伊人网在线 | 午夜羞羞网站 | 亚洲国产精品欧美久久 | 免费黄色在线网站 | 国产精品666| 中文字幕综合 | 午夜黄色福利视频 | xxxxxx在线观看 | 亚洲乱熟 | 日本久久久久久 | 男人天堂视频网 | 中文字幕在线视频观看 | 亚洲网在线观看 | 美女激情av | 久久青 | 97在线公开视频 | 超碰碰碰 | 欧美日本韩国一区二区三区 | 国产一区亚洲 | 天天射寡妇 | 亚洲视频免费 | 成人在线观看小视频 | 一级真人毛片 | 色综合天天综合网天天狠天天 | 免费的黄色网 | 欧美在线网 | 97国产超碰 | 国产伦精品一区二区三区四区视频 |