public EditAccountContentDialog(TwoFACodeModel model) { this.InitializeComponent(); ViewModel.TwoFACodeModel = model; switch (SettingsService.Instance.AppTheme) { case Theme.System: if (RequestedTheme != SettingsService.Instance.OriginalAppTheme.ToElementTheme()) { RequestedTheme = SettingsService.Instance.OriginalAppTheme.ToElementTheme(); } break; case Theme.Dark: if (RequestedTheme != ElementTheme.Dark) { RequestedTheme = ElementTheme.Dark; } break; case Theme.Light: if (RequestedTheme != ElementTheme.Light) { RequestedTheme = ElementTheme.Light; } break; default: break; } }
/// <summary> /// Copy the 2fa code to clipboard and create a user dialog /// </summary> /// <param name="model"></param> private void Copy2FACodeToClipboard(TwoFACodeModel model) { DataPackage dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy }; dataPackage.SetText(model.TwoFACode); Clipboard.SetContent(dataPackage); }
/// <summary> /// Constructor /// </summary> public AddAccountContentDialogViewModel() { ResourceService = App.Current.Container.Resolve <IResourceService>(); _dispatcherTimer = new DispatcherTimer(); _dispatcherTimer.Interval = new TimeSpan(0, 0, 1); //every second Model = new TwoFACodeModel(); ManualInputCommand = new DelegateCommand(() => { SelectedPivotIndex = 1; ManualInput = true; }); ScanQRCodeCommand = new DelegateCommand(() => { OpeningSeconds = SettingsService.Instance.QRCodeScanSeconds; _dispatcherTimer.Tick -= OnTimedEvent; _dispatcherTimer.Tick += OnTimedEvent; Seconds = OpeningSeconds; _dispatcherTimer.Start(); ScanQRCode(); }); PrimaryButtonCommand = new DelegateCommand(() => { DataService.Instance.Collection.Add(Model); }); CameraScanCommand = new DelegateCommand(() => { IsCameraActive = true; }); Logger = App.Current.Container.Resolve <ILoggerFacade>(); //ErrorsChanged += Validation_ErrorsChanged; Window.Current.Activated += Current_Activated; }
/// <summary> /// Parses the QR code by splitting the different parts /// </summary> /// <returns>true if TOTP</returns> private bool ParseQRCode() { IProject2FAParser parser = App.Current.Container.Resolve <IProject2FAParser>(); List <KeyValuePair <string, string> > valuePair = parser.ParseQRCodeStr(_qrCodeStr); if (valuePair.Count == 0) { return(false); } Model = new TwoFACodeModel(); foreach (KeyValuePair <string, string> item in valuePair) { switch (item.Key) { case "secret": SecretKey = item.Value; break; case "label": Model.Label = item.Value; RaisePropertyChanged(nameof(Label)); //RaisePropertyChanged(nameof(Label)); break; case "issuer": Model.Issuer = item.Value; RaisePropertyChanged(nameof(Issuer)); //RaisePropertyChanged(nameof(Issuer)); break; case "algorithm": string algo = item.Value.ToLower(); switch (algo) { case "sha1": Model.HashMode = OtpHashMode.Sha1; break; case "sha256": Model.HashMode = OtpHashMode.Sha256; break; case "sha512": Model.HashMode = OtpHashMode.Sha512; break; default: break; } break; case "period": Model.Period = Convert.ToInt32(item.Value); break; case "digits": Model.TotpSize = Convert.ToInt32(item.Value); break; default: break; } } return(true); }