using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Zenject; using TMPro; using YandexQuest.Models; using Cysharp.Threading.Tasks; public class Authorization : MonoBehaviour { [Inject] private readonly ClientDataService _clientDataService; [Inject] private readonly NetworkService _networkService; [SerializeField] private TMP_InputField _codeInputField; [SerializeField] private Button _codeAcceptButton; [SerializeField] private TMP_Text _errorText; private void Start() { var clientData = _clientDataService.data; if(clientData != null) { Debug.LogWarning($"данные клианта загружены: город - {clientData.city}, найдено тэгов - {clientData.games.Count}"); return; } _codeInputField.onValueChanged.AddListener(stringValue => { if(stringValue.Length != 6) { _codeAcceptButton.interactable = false; } else { _codeAcceptButton.interactable = true; } }); _codeAcceptButton.onClick.AddListener(async () => { await SendCode(_codeInputField.text); }); } private async UniTask SendCode(string inputFieldText) { CityUniqueCode cityUniqueCode = null; _networkService.OnGetResponse += CheckResponseAdmin; cityUniqueCode = await _networkService.GetAsync($"auth/admin/{inputFieldText}"); async void CheckResponseAdmin(int responseCode) { _networkService.OnGetResponse -= CheckResponseAdmin; if(responseCode == 0) Debug.LogError("Нет соединения с сервером"); else if (responseCode == 404) { Client client = new Client(); Debug.LogWarning("такого админа нет в базе. ищем город..."); _networkService.OnGetResponse += CheckResponse; client = await _networkService.GetAsync($"auth/{inputFieldText}"); void CheckResponse(int responseCode) { _networkService.OnGetResponse -= CheckResponse; if(responseCode == 404) { Debug.LogError("такого кода нет в базе"); } else if(responseCode == 0) Debug.LogError("Нет соединения с сервером"); else if( responseCode == 200) { _clientDataService.data = client; Debug.Log(client.city.ToString()); } } } else if(responseCode == 200) { Debug.Log(cityUniqueCode.city); } } } }