Пример #1
0
        public EditViewLoginViewModel(LoginSimplified current, List <string> keyIds, Action positiveAction, Action negativeAction, Action <LoginSimplified, bool /* Was Security Modified */, string /* Key identifier */> edit)
        {
            this.KeyIdentifiers = new ObservableCollection <string>();
            foreach (string keyIdentifier in keyIds)
            {
                this.KeyIdentifiers.Add(keyIdentifier);
            }

            if (keyIds.Count > 0)
            {
                this.SelectedKeyIdentifier = keyIds[0];
            }

            this.onPositiveClose = positiveAction;
            this.onNegativeClose = negativeAction;
            this.editLogin       = edit;

            this.zeroBasedIndexNumber = current.zeroBasedIndexNumber;
            this.wasOriginallySecret  = current.IsSecure;
            this.IsSecret             = current.IsSecure;
            this.Title    = current.Title;
            this.URL      = current.URL;
            this.Email    = current.Email;
            this.Username = current.Username;
            this.Password = current.Password;
            this.Notes    = current.Notes;
            // TODO: Icon here once it is supported
            this.Category = current.Category;
            this.Tags     = current.Tags;
        }
        public EditViewLoginWindow(LoginSimplified current, List <string> keyIdentifiers, Action <LoginSimplified, bool /* Was Security Modified */, string /* Key identifier */> editLogin)
        {
            InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif
            DataContext = new EditViewLoginViewModel(current, keyIdentifiers, EditClose, CancelClose, editLogin);
        }
        private void GenerateLoginSimplifiedsFromCommonSecrets()
        {
            this.logins.Clear();
            List <LoginSimplified> newLogins = LoginSimplified.TurnIntoUICompatible(this.csc.loginInformations, this.csc.loginInformationSecrets, this.derivedPasswords, this.settingsData);

            foreach (LoginSimplified login in newLogins)
            {
                this.logins.Add(login);
            }
        }
        private void AddLoginToCollection(LoginSimplified newLogin, string keyIdentifier)
        {
            LoginInformation loginToAdd = new LoginInformation(newLogin.Title, newLogin.URL, newLogin.Email, newLogin.Username, newLogin.Password,
                                                               newLogin.Notes, newLogin.Icon, newLogin.Category, newLogin.Tags);

            if (newLogin.IsSecure)
            {
                this.csc.AddLoginInformationSecret(this.derivedPasswords[keyIdentifier], loginToAdd, keyIdentifier);
            }
            else
            {
                this.csc.loginInformations.Add(loginToAdd);
            }

            // Adding a login information modifies the structure
            this.isModified = true;
            this.UpdateMainTitle(this.filePath != null ? this.filePath : untitledTempName);

            this.GenerateLoginSimplifiedsFromCommonSecrets();
        }
        private void EditLoginInCollection(LoginSimplified editedLogin, bool wasSecurityModified, string keyIdentifier)
        {
            LoginInformation loginToAdd = new LoginInformation(editedLogin.Title, editedLogin.URL, editedLogin.Email, editedLogin.Username, editedLogin.Password,
                                                               editedLogin.Notes, editedLogin.Icon, editedLogin.Category, editedLogin.Tags);

            if (wasSecurityModified)
            {
                // If logininformation jumps from secure <-> unsecure
                if (editedLogin.IsSecure)
                {
                    this.csc.loginInformations.RemoveAt(editedLogin.zeroBasedIndexNumber);
                    this.csc.AddLoginInformationSecret(this.derivedPasswords[keyIdentifier], loginToAdd, keyIdentifier);
                }
                else
                {
                    this.csc.loginInformationSecrets.RemoveAt(editedLogin.zeroBasedIndexNumber);
                    this.csc.loginInformations.Add(loginToAdd);
                }
            }
            else
            {
                if (editedLogin.IsSecure)
                {
                    this.csc.ReplaceLoginInformationSecret(editedLogin.zeroBasedIndexNumber, this.derivedPasswords[keyIdentifier], loginToAdd, keyIdentifier);
                }
                else
                {
                    this.csc.loginInformations[editedLogin.zeroBasedIndexNumber] = loginToAdd;
                }
            }

            // Editing a login information modifies the structure
            this.isModified = true;
            this.UpdateMainTitle(this.filePath != null ? this.filePath : untitledTempName);

            this.GenerateLoginSimplifiedsFromCommonSecrets();
        }