Exemple #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="translationService"></param>
        /// <param name="databaseRepository"></param>
        /// <param name="passwordService"></param>
        /// <param name="iconsService"></param>
        /// <param name="clipboardService"></param>
        public EntryViewModel(ITranslationService translationService,
                              IDatabaseRepository databaseRepository,
                              IPasswordService passwordService,
                              IIconsService iconsService,
                              IClipboardService clipboardService)
            : base(translationService)
        {
            this.databaseRepository = databaseRepository;
            this.passwordService    = passwordService;
            this.iconsService       = iconsService;
            this.clipboardService   = clipboardService;

            iconsService.IconDownloadedEvent += IconDownloadedEventHandler;

            backupPasswordEntry                = new PasswordEntryModel();
            Categories                         = new ObservableCollection <string>();
            UserControlVisibility              = false;
            DeletionConfimationVisibility      = false;
            PasswordGenerationDialogVisibility = false;

            Messenger.Default.Register <DatabaseUnloadedMessage>(this, DatabaseUnloadedHandler);
            Messenger.Default.Register <EntrySelectedMessage>(this, EntrySelectedHandler);
            Messenger.Default.Register <ShowNewEntryViewMessage>(this, StartEntryCreation);
            Messenger.Default.Register <CategoryAddedMessage>(this, HandleNewCategory);
            Messenger.Default.Register <CategoryDeletedMessage>(this, CategoryDeletedHandler);
            Messenger.Default.Register <CategoryEditedMessage>(this, CategoryEditedHandler);
            Messenger.Default.Register <LanguageChangedMessage>(this, LanguageChangedHandler);
        }
Exemple #2
0
        public IActionResult Update([FromBody] PasswordEntryModel model)
        {
            var user = User.GetUser(_userService);

            if (user != null)
            {
                if (model.Id != null)
                {
                    var passwordEntry = _passwordEntryService.GetById(model.Id.Value, user.Id);
                    if (passwordEntry != null)
                    {
                        passwordEntry.Username       = model.Username;
                        passwordEntry.Password       = model.Password;
                        passwordEntry.Title          = model.Title;
                        passwordEntry.Description    = model.Description;
                        passwordEntry.Url            = model.Url;
                        passwordEntry.ExpirationDate = model.ExpirationDate.HasValue ? (DateTime?)null : new DateTime(model.ExpirationDate.Value);
                        _passwordEntryService.Save(passwordEntry);
                        return(Ok(ResultMessages.Update_Success));
                    }
                    return(NotFound(ResultMessages.PasswordEntry_NotFound));
                }
                return(NotFound(ResultMessages.PasswordEntry_IdNotSet));
            }
            return(Unauthorized(ResultMessages.User_Authorization_NotOnDb));
        }
Exemple #3
0
 /// <summary>
 /// Reset the view and the database related ressources
 /// </summary>
 /// <param name="obj"></param>
 private void DatabaseUnloadedHandler(DatabaseUnloadedMessage obj)
 {
     Categories.Clear();
     backupPasswordEntry = null;
     PasswordEntry       = null;
     SetElementsVisibility(ViewModes.View);
     UserControlVisibility = false;
 }
Exemple #4
0
 /// <summary>
 /// Set the view mode to edition
 /// </summary>
 /// <param name="obj"></param>
 private void StartEntryCreation(ShowNewEntryViewMessage obj)
 {
     AddCategories();
     PasswordEntry = new PasswordEntryModel();
     PasswordEntry.PropertyChanged += PasswordPropertyChanged;
     PasswordEntry.Password         = passwordService.GeneratePassword(PasswordTypes.Full, 20);
     UserControlVisibility          = true;
     SetElementsVisibility(ViewModes.Creation);
 }
 /// <summary>
 /// Create a copy of a PasswordEntryModel
 /// </summary>
 /// <param name="entry"></param>
 /// <returns></returns>
 public static PasswordEntryModel Copy(this PasswordEntryModel entry)
 {
     return(new PasswordEntryModel()
     {
         Id = entry.Id,
         Name = entry.Name,
         Website = entry.Website,
         Category = entry.Category,
         Username = entry.Username,
         Password = entry.Password,
         PasswordStrength = entry.PasswordStrength,
         Notes = entry.Notes
     });
 }
        /// <summary>
        /// Update the cache's corresponding PasswordEntry with the given entry
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public bool UpdatePasswordEntry(PasswordEntryModel entry)
        {
            entry.LastEditionDate = DateTime.Now;
            for (int i = 0; i < cache?.PasswordEntries?.Count; i++)
            {
                if (cache.PasswordEntries[i].Id == entry.Id)
                {
                    cache.PasswordEntries[i] = entry;
                    InternalWriteDatabase();
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Open the Website property of the given PasswordEntryModel in the default browser
        /// </summary>
        /// <param name="entry"></param>
        public static void OpenWebsite(this PasswordEntryModel entry)
        {
            var url = entry.Website;

            if (string.IsNullOrWhiteSpace(url))
            {
                return;
            }

            // Need to add the protocol to be considered as a website url
            if (!url.StartsWith("https://") || !url.StartsWith("http://"))
            {
                url = $"https://{url}";
            }

            System.Diagnostics.Process.Start(url);
        }
Exemple #8
0
        public IActionResult Create([FromBody] PasswordEntryModel model)
        {
            var user = User.GetUser(_userService);

            if (user != null)
            {
                var cat = _categoryService.GetById(model.CategoryId, user.Id);
                if (cat != null)
                {
                    var passwordEntry = PasswordEntry.CreateNew(model.Username, model.Password, model.Title, model.Description, model.Url, model.ExpirationDate, cat.Id);
                    _passwordEntryService.Save(passwordEntry);
                    return(Ok(ResultMessages.Creation_Success));
                }
                return(BadRequest(ResultMessages.Creation_Failed));
            }
            return(Unauthorized(ResultMessages.User_Authorization_NotOnDb));
        }
        /// <summary>
        /// Copy to the clipboard the given property of a PasswordEntryModel
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="property"></param>
        public void CopyDataToClipboard(PasswordEntryModel entry, string property)
        {
            var data = string.Empty;

            switch (property)
            {
            case "Password":
                data = entry.Password;
                break;

            case "Username":
                data = entry.Username;
                break;

            case "Website":
                data = entry.Website;
                break;
            }

            if (data is null)
            {
                return;
            }

            clipboardTimer?.Stop();

            var duration = settingsService.GetClipboardTimerDuration();

            if (duration != 0)
            {
                clipboardTimer = new Timer(settingsService.GetClipboardTimerDuration() * 1000)
                {
                    AutoReset = false,
                    Enabled   = false
                };
                clipboardTimer.Elapsed += ClipboardTimerElapsed;

                CopyDataStart?.Invoke(null, null);
                clipboardTimer.Start();
            }

            Clipboard.SetText(data);
        }
        public ActionResult Password(PasswordEntryModel entryModel)
        {
            var currentUser = User.Identity.Name;

            if (!string.IsNullOrWhiteSpace(entryModel.CurrentPassword))
            {
                var user = _userManager.Find(currentUser, entryModel.CurrentPassword);
                if (user == null)
                {
                    ModelState.AddModelError("CurrentPassword", "Invalid current password.");
                }
            }

            if (ModelState.IsValid)
            {
                _userManager.UpdatePassword(currentUser, entryModel.NewPassword);
                TempData["PasswordChanged"] = true;

                return(RedirectToAction("Password"));
            }

            return(Password());
        }
Exemple #11
0
 public EntrySelectedMessage(object sender, PasswordEntryModel model)
     : base(sender)
 {
     this.passwordEntry = model;
 }
 public EntryEditedMessage(object sender, PasswordEntryModel entry)
     : base(sender)
 {
     this.Entry = entry;
 }
Exemple #13
0
 /// <summary>
 /// Call the OpenWebsite extension method
 /// </summary>
 /// <param name="obj"></param>
 private void OpenWebsite(PasswordEntryModel obj)
 {
     obj.OpenWebsite();
 }
Exemple #14
0
 /// <summary>
 /// Call the CopyDataToClipboard extension method
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="property"></param>
 private void CopyToClipboard(PasswordEntryModel obj, string property)
 {
     clipboardService.CopyDataToClipboard(obj, property);
 }
Exemple #15
0
 /// <summary>
 /// Set SelectedPasswordEntry and send a new EntrySelectedMessage
 /// </summary>
 /// <param name="selectedPasswordEntry"></param>
 private void SelectEntry(PasswordEntryModel selectedPasswordEntry)
 {
     SelectedPasswordEntry = selectedPasswordEntry;
     Messenger.Default.Send(new EntrySelectedMessage(this, selectedPasswordEntry.Copy()));
 }
Exemple #16
0
 /// <summary>
 /// Set the view mode to edition
 /// </summary>
 private void StartEdition()
 {
     backupPasswordEntry            = PasswordEntry.Copy();
     PasswordEntry.PropertyChanged += PasswordPropertyChanged;
     SetElementsVisibility(ViewModes.Edition);
 }
 /// <summary>
 /// Add the given password entry to the cache
 /// </summary>
 /// <param name="entry"></param>
 /// <returns></returns>
 public bool AddPasswordEntry(PasswordEntryModel entry)
 {
     entry.LastEditionDate = DateTime.Now;
     cache.PasswordEntries.Add(entry);
     return(InternalWriteDatabase());
 }
 /// <summary>
 /// Delete the given password entry from the cache
 /// </summary>
 /// <param name="entry"></param>
 /// <returns></returns>
 public bool DeletePasswordEntry(PasswordEntryModel entry)
 {
     cache.DeletedEntries.Add(entry.Id);
     cache.PasswordEntries.RemoveAll(x => x.Id == entry.Id);
     return(InternalWriteDatabase());
 }
Exemple #19
0
 public EntryDeletedMessage(object sender, PasswordEntryModel entry)
     : base(sender)
 {
     Entry = entry;
 }