/// <summary> /// Event called when the me response has been returned. /// </summary> private void OnMeResponse(object rawResponse) { var response = rawResponse as ApiResponse; if (!response.IsSuccess) { OnLoginFailed?.Invoke(); } DisposeMeRequest(true); }
// Android sign in public async Task Login() { var hasToken = await AuthService.AcquireToken(); // Trigger clear any messages on login screen ClearLoginMessages?.Invoke(); if (!hasToken) { // Authentication failed - trigger updates to login screen OnLoginFailed?.Invoke(); } // else Login success handled by permissions service which is called as a result of auth changed event which calls HandleOnAuthChanged }
// private void HandleLogin(LoginResponse loginResponse) // { // handleLogin.Invoke(loginResponse); // } private void HandleLogin_AtClient(MessageResponseNetworkData loginResponse) { if (loginResponse.IsSuccess) { IsAuthenticated = true; DebugLog.Warning("[Auth] Login successfully."); OnLoginSucceeded?.Invoke(loginResponse.Message); } else { DebugLog.Warning("[Auth] Log-in failed."); OnLoginFailed?.Invoke(loginResponse.Message); } }
/// <summary> /// Event called when the authentication response has been returned. /// </summary> private void OnAuthResponse(object rawResponse) { var response = rawResponse as ApiResponse; if (response.IsSuccess) { if (authRequest.Value is AuthRequest credentialAuth) { SaveCredentials(credentialAuth.Username, credentialAuth.Password); } } else { OnLoginFailed?.Invoke(); } DisposeAuthRequest(true); }
public int IrisLogin(string userName = "", string userPassword = "") { try { now = users.Single(u => u.Name == userName); IsLogin = true; if (LoginEvent != null) { LoginEvent(now.Level.ToString(), now.Name); } Logger.Log(ATSData.RunLog, now.Name + " 登入"); OnLogin.Invoke(this, new EventArgs()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); now = DefaultUser; IsLogin = false; OnLoginFailed.Invoke(this, new EventArgs()); } return(now.Power); }
public async Task Login() { if (isAlreadyInLoginProcess || credential != null) { CancelLogin(); } else { isAlreadyInLoginProcess = true; source = new CancellationTokenSource(new TimeSpan(0, 1, 0)); token = source.Token; FileStream stream = new FileStream(System.Windows.Forms.Application.StartupPath + "credentials.json", FileMode.Open, FileAccess.Read); string credPath = "token.json"; await Task.Run(() => { try { credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes, "NotesieveDesktopUser", token, new FileDataStore(credPath, true)).Result; } catch (System.AggregateException e) { if (token.IsCancellationRequested) { //Операция прервана } else { OnError?.Invoke(e.InnerException + " " + e.Message); } isAlreadyInLoginProcess = false; } catch (System.Net.Http.HttpRequestException e) { isAlreadyInLoginProcess = false; OnSyncStateChanged?.Invoke(gSyncState.eFailed); OnError?.Invoke("Проблема с интрнєт-соединением.\nВы можете продолжать использовать Notesieve но временно, не сможете его синхронизировать."); } }); if (credential == null) { isAlreadyInLoginProcess = false; OnLoginFailed?.Invoke(); } else { try { isAlreadyInLoginProcess = false; PeopleServiceService peopleService = new PeopleServiceService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = applicationName, }); isLogin = true; PeopleResource.GetRequest peopleRequest = peopleService.People.Get("people/me"); peopleRequest.PersonFields = "names,photos"; Person profile = peopleRequest.Execute(); string name = profile.Names[0].DisplayName; string photo = profile.Photos[0].Url; OnLoginSuccsesfull?.Invoke(name, photo); } catch (System.Net.Http.HttpRequestException e) { isAlreadyInLoginProcess = false; OnSyncStateChanged?.Invoke(gSyncState.eLostConnection); OnError?.Invoke("Проблема с интрнєт-соединением.\nВы можете продолжать использовать Notesieve но временно, не сможете его синхронизировать."); } } } }
/// <summary> /// Zajmuje sie sprawdzaniem czy cos jest na gniezdzie, wczytywaniem naglowka /// oraz calych pakietow /// </summary> private void go() { try { GaduPacketHeader header = new GaduPacketHeader(); // naglowek while (true) { if (!tcpClient.Connected || tcpClient.GetStream().DataAvailable == false || work == false) { // jezeli na gniezdzie nie ma 8 pelnych bajtow lub gniazdo nie jest podlaczone to Thread.Sleep(sleepTime); // czekamy na nowe pakiety continue; // i przechodzimy do nastepnej iteracji } header.read(tcpClient.GetStream(), 8); // czytamy naglowek if (OnPacket != null) { OnPacket.BeginInvoke(header, null, null); } switch (header.Type) { case GaduPacketConstans.GG_RECV_MSG: // ktos przyslal nam wiadomosc GaduPacketRecieveMessage msg = new GaduPacketRecieveMessage(); msg.read(tcpClient.GetStream(), header.Length); // wczytujemy wiadomosc if (OnRecieveMessage != null) // jezeli ktos podstawil swoja funkcje pod event { OnRecieveMessage.BeginInvoke(msg, null, null); // to ja wywolujemy podstawiajac jako argument pakiet z wiadomoscia } break; case GaduPacketConstans.GG_SEND_MSG_ACK: // odebralismy pakiet potwierdzajacy wiadomosc GaduPacketMessageAck ack = new GaduPacketMessageAck(); ack.read(tcpClient.GetStream(), header.Length); // wczytaj pakiet if (OnRecieveMessageAck != null) { OnRecieveMessageAck.BeginInvoke(ack, null, null); // wywolaj event } break; case GaduPacketConstans.GG_PONG: // otrzymalismy pakiet GG_PONG z servera if (OnPong != null) { OnPong.BeginInvoke(null, null); } break; case GaduPacketConstans.GG_LOGIN_OK: // otrzymalismy pakiet informujacy nas o tym ze logowanie sie powiodlo if (header.Length == 1) { tcpClient.GetStream().ReadByte(); // jeden bajt, ktory nie zawsze musi sie pojawic, przeznaczenie nie poznane } if (OnLoginOK != null) { OnLoginOK.BeginInvoke(null, null); // wywolaj event } break; case GaduPacketConstans.GG_NEED_EMAIL: // server chce abysmy uzupelnili e-mail w naszych danych if (OnLoginNeedEmail != null) { OnLoginNeedEmail.BeginInvoke(null, null); // wywolaj event } break; case GaduPacketConstans.GG_LOGIN_FAILED: // logowanie sie nie powiodlo if (OnLoginFailed != null) { OnLoginFailed.BeginInvoke(null, null); // wywolaj event } break; case GaduPacketConstans.GG_NOTIFY_REPLY77: // otrzymalismy pakiet mowiacy o tym ze ktos zmienil status GaduPacketNotifyReplay77 gaduPacketNotifyReplay77; while (header.Length > 0) // najprawdopodobnie bedzie to zlepek pakietow, a wiec bedziemy je wczytywac po kolei { gaduPacketNotifyReplay77 = new GaduPacketNotifyReplay77(); gaduPacketNotifyReplay77.read(tcpClient.GetStream(), header.Length); header.Length -= gaduPacketNotifyReplay77.getSize(); if (OnGaduNotifyReplay != null) { OnGaduNotifyReplay.BeginInvoke(gaduPacketNotifyReplay77, null, null); // dla danego pakiety wywolaj event } } break; case GaduPacketConstans.GG_STATUS77: // ktos zmienil status na gg GaduPacketStatus77 gaduPacketStatus77 = new GaduPacketStatus77(); gaduPacketStatus77.read(tcpClient.GetStream(), header.Length); // wczytujemy pakiet if (OnGaduStatus != null) { OnGaduStatus.BeginInvoke(gaduPacketStatus77, null, null); // wywolujemny event } break; case GaduPacketConstans.GG_USERLIST_REPLY: GaduPacketUserListRequest gaduPacketUserlistReplay = new GaduPacketUserListRequest(); gaduPacketUserlistReplay.read(tcpClient.GetStream(), header.Length); if (OnUserListReplay != null) { OnUserListReplay.BeginInvoke(gaduPacketUserlistReplay, null, null); } break; case GaduPacketConstans.GG_PUBDIR50_REPLY: GaduPacketPubDir50 gaduPacketPubDir50 = new GaduPacketPubDir50(); gaduPacketPubDir50.read(tcpClient.GetStream(), header.Length); if (OnPubDirReplay != null) { OnPubDirReplay.BeginInvoke(gaduPacketPubDir50, null, null); } break; case GaduPacketConstans.GG_DISCONNECTING: if (OnGaduDisconnecting != null) { OnGaduDisconnecting.BeginInvoke(null, null); } break; case GaduPacketConstans.GG_DISCONNECTING2: if (OnGaduDisconnecting != null) { OnGaduDisconnecting.BeginInvoke(null, null); } break; default: // jezeli otrzymalismy jakis pakiet, ktory jeszcze nie jest obslugiwany przez biblioteke byte[] packet = new byte[header.Length]; for (int i = 0; i < header.Length; i++) // to wczytaj tylko pakiet z gniazda i nic z nim nie rob { packet[i] = (byte)tcpClient.GetStream().ReadByte(); } if (OnUnhandledPacket != null) { OnUnhandledPacket.BeginInvoke(header, packet, null, null); } break; } } } catch (ThreadAbortException) { // nie zadreczajmy uzytkownika tym wyjatkiem, w 99% powodowany przez Thread.Abort() } catch (Exception e) { if (Gadu.GaduCriticalError() == false) { throw new GaduRecieverException(e.Message); } } }