private async Task LogInAsync() { if (string.IsNullOrWhiteSpace(CodeCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.VerificationCode), AppResources.Ok); return; } _userDialogs.ShowLoading(AppResources.ValidatingCode, MaskType.Black); var response = await _authService.TokenPostTwoFactorAsync(CodeCell.Entry.Text, _email, _masterPasswordHash, _key); _userDialogs.HideLoading(); if (!response.Success) { await DisplayAlert(AppResources.AnErrorHasOccurred, response.ErrorMessage, AppResources.Ok); return; } _googleAnalyticsService.TrackAppEvent("LoggedIn From Two-step"); if (Device.OS == TargetPlatform.Android) { _pushNotification.Register(); } var task = Task.Run(async() => await _syncService.FullSyncAsync(true)); Application.Current.MainPage = new MainPage(); }
private async Task LogIn() { if (string.IsNullOrWhiteSpace(EmailCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok); return; } if (string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok); return; } _userDialogs.ShowLoading(AppResources.LoggingIn, MaskType.Black); var result = await _authService.TokenPostAsync(EmailCell.Entry.Text, PasswordCell.Entry.Text); _userDialogs.HideLoading(); if (!result.Success) { await DisplayAlert(AppResources.AnErrorHasOccurred, result.ErrorMessage, AppResources.Ok); return; } PasswordCell.Entry.Text = string.Empty; if (result.TwoFactorRequired) { _googleAnalyticsService.TrackAppEvent("LoggedIn To Two-step"); await Navigation.PushAsync(new LoginTwoFactorPage(EmailCell.Entry.Text, result)); return; } _googleAnalyticsService.TrackAppEvent("LoggedIn"); if (Device.RuntimePlatform == Device.Android) { _pushNotification.Register(); } var task = Task.Run(async() => await _syncService.FullSyncAsync(true)); Application.Current.MainPage = new MainPage(); }
private async Task LogIn() { if (string.IsNullOrWhiteSpace(CodeCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.VerificationCode), AppResources.Ok); return; } var request = new TokenRequest { Email = _email, MasterPasswordHash = _masterPasswordHash, Token = CodeCell.Entry.Text.Replace(" ", ""), Provider = 0, // Authenticator app (only 1 provider for now, so hard coded) Device = new DeviceRequest(_appIdService, _deviceInfoService) }; _userDialogs.ShowLoading(AppResources.ValidatingCode, MaskType.Black); var response = await _authService.TokenPostAsync(request); _userDialogs.HideLoading(); if (!response.Succeeded) { await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok); return; } _cryptoService.Key = _key; _tokenService.Token = response.Result.AccessToken; _tokenService.RefreshToken = response.Result.RefreshToken; _authService.UserId = _tokenService.TokenUserId; _authService.Email = _tokenService.TokenEmail; _settings.AddOrUpdateValue(Constants.LastLoginEmail, _authService.Email); _googleAnalyticsService.RefreshUserId(); _googleAnalyticsService.TrackAppEvent("LoggedIn From Two-step"); if (Device.OS == TargetPlatform.Android) { _pushNotification.Register(); } var task = Task.Run(async() => await _syncService.FullSyncAsync(true)); Application.Current.MainPage = new MainPage(); }
private async Task LogIn() { if (string.IsNullOrWhiteSpace(EmailCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.EmailAddress), AppResources.Ok); return; } if (string.IsNullOrWhiteSpace(PasswordCell.Entry.Text)) { await DisplayAlert(AppResources.AnErrorHasOccurred, string.Format(AppResources.ValidationFieldRequired, AppResources.MasterPassword), AppResources.Ok); return; } var normalizedEmail = EmailCell.Entry.Text.ToLower(); var key = _cryptoService.MakeKeyFromPassword(PasswordCell.Entry.Text, normalizedEmail); var request = new TokenRequest { Email = normalizedEmail, MasterPasswordHash = _cryptoService.HashPasswordBase64(key, PasswordCell.Entry.Text), Device = new DeviceRequest(_appIdService, _deviceInfoService) }; _userDialogs.ShowLoading(AppResources.LoggingIn, MaskType.Black); var response = await _authService.TokenPostAsync(request); _userDialogs.HideLoading(); if (!response.Succeeded) { await DisplayAlert(AppResources.AnErrorHasOccurred, response.Errors.FirstOrDefault()?.Message, AppResources.Ok); return; } _cryptoService.Key = key; _authService.Token = response.Result.Token; _authService.UserId = response.Result?.Profile?.Id; _authService.Email = response.Result?.Profile?.Email; _settings.AddOrUpdateValue(Constants.LastLoginEmail, _authService.Email); _googleAnalyticsService.RefreshUserId(); _googleAnalyticsService.TrackAppEvent("LoggedIn"); if (Device.OS == TargetPlatform.Android) { _pushNotification.Register(); } if (_authService.IsAuthenticatedTwoFactor) { await Navigation.PushAsync(new LoginTwoFactorPage()); } else { var task = Task.Run(async() => await _syncService.FullSyncAsync()); Application.Current.MainPage = new MainPage(); } }