private async void Login() { RaiseCanExecuteChanged(); SimpleUser user; try { using (ProgressProvider.StartProgress()) { user = await _signalHelperFacade.LoginSignalHelper.Login(Username, Password).ConfigureAwait(true); } } catch (LoginFailedException e) { LoginFailed?.Invoke(new LoginFailedEventArgs(e.Message)); return; } finally { RaiseCanExecuteChanged(); } LoggedIn = true; LoginSucceeded?.Invoke(new LoginSucceededEventArgs(user)); Application.Current.Dispatcher.Invoke(RaiseCanExecuteChanged); }
protected virtual void ProcessSnipeMessage(ExpandoObject data, bool original = false) { string message_type = data.SafeGetString("type"); string error_code = data.SafeGetString("errorCode"); switch (message_type) { case "user.login": if (error_code == "ok") { LoginName = data.SafeGetString("name"); if (LoginSucceeded != null) { LoginSucceeded.Invoke(); } } else if (error_code == "wrongToken" || error_code == "userNotFound") { Authorize(); } else if (error_code == "userDisconnecting") { StartCoroutine(WaitAndRequestLogin()); } else if (error_code == "userOnline") { RequestLogout(); StartCoroutine(WaitAndRequestLogin()); } break; } MessageReceived?.Invoke(data, original); }
private void RaiseLoginSucceeded(User user) { if (LoginSucceeded != null) { LoginSucceeded.Invoke(this, user); } }
private bool SteamLogin() { if (!File.Exists("steam_appid.txt")) { try { File.WriteAllText("steam_appid.txt", Engine.AppId.ToString()); } catch (Exception e) { return(FailLogin(e.Message)); } } if (!SteamAPI.Init()) { return(FailLogin( "Could initialize SteamAPI - Make sure Steam is running and the AppID is valid.")); } SteamAPI.RunCallbacks(); SteamId = SteamUser.GetSteamID(); UserId = SteamId.GetAccountID().m_AccountID; ProfileName = SteamFriends.GetPersonaName(); LoginSucceeded.Fire(ProfileName); return(true); }
private async void LoginAsync(PasswordBox passwordBox) { try { IsLoading = true; Boolean result = await _service.LoginAsync(UserName, passwordBox.Password); if (result) { LoginSucceeded?.Invoke(this, EventArgs.Empty); } else { LoginFailed?.Invoke(this, EventArgs.Empty); } } catch (Exception ex) when(ex is NetworkException || ex is HttpRequestException) { OnMessageApplication($"Unexpected error occured! ({ex.Message})"); } finally { IsLoading = false; } }
/// <summary> /// 登陆到百度 /// </summary> /// <param name="username">用户名</param> /// <param name="password">密码</param> /// <returns>返回登陆是否成功</returns> /// <remarks>no throw, return false if failed</remarks> public bool Login(string username, string password) { Tracer.GlobalTracer.TraceInfo("BaiduOAuth.Login called: username="******", password=*"); _username = username; _password = password; try { // #1 HTTP request: token request _get_token(); // #2 HTTP request: login check var captcha_data = _v2_api__logincheck(_token, username); //需要验证码并且验证码为空时,引发CaptchaRequiredException if (!string.IsNullOrEmpty(captcha_data.codestring) && _verifycode == null) { _codestring = captcha_data.codestring; _vcodetype = captcha_data.vcodetype; LoginCaptchaRequired?.Invoke(); throw new CaptchaRequiredException(); } // #3 HTTP request: get public key (RSA password encryption) var rsa_key = _v2_getpublickey(_token, _get_guid()); // #4 HTTP request: post login var login_result = _v2_api__login(_token, _codestring, _get_guid(), username, password, rsa_key.key, rsa_key.pubkey, _verifycode); //对登陆结果返回的验证码字段进行赋值 if (!string.IsNullOrEmpty(login_result.vcodetype)) { _vcodetype = login_result.vcodetype; } if (!string.IsNullOrEmpty(login_result.codestring)) { _codestring = login_result.codestring; } switch (login_result.errno) { case "0": //登陆成功 LoginSucceeded?.Invoke(); return(true); case "257": LoginCaptchaRequired?.Invoke(); throw new CaptchaRequiredException(); default: _failed_code = int.Parse(login_result.errno); _failed_reason = ""; throw new LoginFailedException("Login failed with response code " + login_result.errno); } } catch (Exception ex) { Tracer.GlobalTracer.TraceError(ex); LoginFailed?.Invoke(); return(false); } }
private async void LoginSubmitButton_OnClicked(object sender, EventArgs e) { bool succeeded = await App.AccountService.LoginAsync(LoginData); if (succeeded) { LoginSucceeded?.Invoke(this, EventArgs.Empty); } else { errorLabel.IsVisible = true; } }
/// <summary> /// Contacts the backend API using the route /api/authentication/login and passes the provided LoginDetails to it /// if the login is successfull a JWT Token is returned and stored in the session store, a flag is set to show login /// was successfull, and things like the user name, roles etc are made available to be used in the app, followed by /// a LoginSuccessfull event being raised for any callers that require it /// </summary> /// <param name="loginDetails">LoginDetails class holding username & password to be used for authentication</param> /// <returns>Async Task</returns> public async Task Login(LoginParameters loginDetails) { var response = await _httpClient.PostAsync("/user/authenticate", new StringContent(Json.Serialize(loginDetails), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { await SaveToken(response); await SetAuthorizationHeader(); await _jwtDecoder.LoadToken(AuthTokenName); UserName = _jwtDecoder.GetName(); FullName = _jwtDecoder.GetFullName(); UserRoles = _jwtDecoder.GetRoles(); IsLoggedIn = true; LoginSucceeded?.Invoke(this, null); } }
private async Task OnLogin(string password) { // TODO check if username and password has been filled string email = Email; // TODO only for quick test if (string.IsNullOrWhiteSpace(email) && string.IsNullOrWhiteSpace(password)) { try { var lines = System.IO.File.ReadAllLines(System.IO.Path.Combine( new System.IO.DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.Parent.FullName, "super-secret-folder\\credentials.properties")); foreach (var line in lines) { var splits = line.Split('='); switch (splits[0].ToLower()) { case "email": email = splits[1]; break; case "password": password = splits[1]; break; default: break; } } } catch { } } var service = new ImapService(); await service.LoginAsync(email, password); LoginSucceeded?.Invoke(this, new MailAccount(email, service)); }
protected void ProcessMessage(byte[] raw_data_buffer) { if (mServerReactionStopwatch != null) { mServerReactionStopwatch.Stop(); ServerReaction = mServerReactionStopwatch.Elapsed; } StopCheckConnection(); var message = MessagePackDeserializer.Parse(raw_data_buffer) as SnipeObject; if (message != null) { string message_type = message.SafeGetString("t"); string error_code = message.SafeGetString("errorCode"); int request_id = message.SafeGetValue <int>("id"); SnipeObject response_data = message.SafeGetValue <SnipeObject>("data"); DebugLogger.Log($"[SnipeClient] [{ConnectionId}] ProcessMessage - {request_id} - {message_type} {error_code} {response_data?.ToJSONString()}"); if (!mLoggedIn) { if (message_type == SnipeMessageTypes.USER_LOGIN) { if (error_code == SnipeErrorCodes.OK) { DebugLogger.Log($"[SnipeClient] [{ConnectionId}] ProcessMessage - Login Succeeded"); mLoggedIn = true; if (response_data != null) { this.ConnectionId = response_data.SafeGetString("connectionID"); } else { this.ConnectionId = ""; } try { LoginSucceeded?.Invoke(); } catch (Exception e) { DebugLogger.Log($"[SnipeClient] [{ConnectionId}] ProcessMessage - LoginSucceeded invokation error: " + e.Message); } if (mHeartbeatEnabled) { StartHeartbeat(); } } else { DebugLogger.Log($"[SnipeClient] [{ConnectionId}] ProcessMessage - Login Failed"); try { LoginFailed?.Invoke(error_code); } catch (Exception e) { DebugLogger.Log($"[SnipeClient] [{ConnectionId}] ProcessMessage - LoginFailed invokation error: " + e.Message); } } } } if (MessageReceived != null) { try { MessageReceived.Invoke(message_type, error_code, response_data, request_id); } catch (Exception e) { DebugLogger.Log($"[SnipeClient] [{ConnectionId}] ProcessMessage - MessageReceived invokation error: " + e.Message + "\n" + e.StackTrace); } } else { DebugLogger.Log($"[SnipeClient] [{ConnectionId}] ProcessMessage - no MessageReceived listeners"); } if (mHeartbeatEnabled) { ResetHeartbeatTimer(); } } }
protected void OnLoginSucceeded() { LoginSucceeded?.Invoke(); }
protected virtual void OnLoginSucceeded() { LoginSucceeded?.Invoke(this, null); }
protected virtual void OnLoginSucceeded(EventArgs e) { LoginSucceeded?.Invoke(this, e); }