private void BuildTable(Cipher cipher)
        {
            // URIs
            if (UrisSection != null && Table.Root.Contains(UrisSection))
            {
                Table.Root.Remove(UrisSection);
            }
            if (Model.ShowLoginUris)
            {
                UrisSection = new TableSection(Helpers.GetEmptyTableSectionTitle());
                foreach (var uri in Model.LoginUris)
                {
                    UrisSection.Add(new UriViewCell(this, uri));
                }
                Table.Root.Add(UrisSection);
            }

            // Notes
            if (Table.Root.Contains(NotesSection))
            {
                Table.Root.Remove(NotesSection);
            }
            if (Model.ShowNotes)
            {
                Table.Root.Add(NotesSection);
            }

            // Fields
            if (Table.Root.Contains(FieldsSection))
            {
                Table.Root.Remove(FieldsSection);
            }
            if (Model.ShowFields)
            {
                FieldsSection = new TableSection(AppResources.CustomFields);
                foreach (var field in Model.Fields)
                {
                    FieldViewCell fieldCell;
                    switch (field.Type)
                    {
                    case FieldType.Text:
                        fieldCell = new FieldViewCell(this, field, null);
                        break;

                    case FieldType.Hidden:
                        fieldCell = new FieldViewCell(this, field, null, null);
                        break;

                    case FieldType.Boolean:
                        fieldCell = new FieldViewCell(this, field);
                        break;

                    default:
                        continue;
                    }
                    FieldsSection.Add(fieldCell);
                }
                Table.Root.Add(FieldsSection);
            }

            // Attachments
            CleanupAttachmentCells();
            if (Table.Root.Contains(AttachmentsSection))
            {
                Table.Root.Remove(AttachmentsSection);
            }
            if (Model.ShowAttachments && (Helpers.CanAccessPremium() || cipher.OrganizationId != null))
            {
                AttachmentsSection = new TableSection(AppResources.Attachments);
                AttachmentCells    = new List <AttachmentViewCell>();
                foreach (var attachment in Model.Attachments.OrderBy(s => s.Name))
                {
                    var attachmentCell = new AttachmentViewCell(attachment, async() =>
                    {
                        await OpenAttachmentAsync(cipher, attachment);
                    });
                    AttachmentCells.Add(attachmentCell);
                    AttachmentsSection.Add(attachmentCell);
                    attachmentCell.InitEvents();
                }
                Table.Root.Add(AttachmentsSection);
            }

            // Other
            if (Table.Root.Contains(OtherSection))
            {
                Table.Root.Remove(OtherSection);
            }
            Table.Root.Add(OtherSection);

            // Various types
            switch (cipher.Type)
            {
            case CipherType.Login:
                if (OtherSection.Contains(LoginPasswordRevisionDateCell))
                {
                    OtherSection.Remove(LoginPasswordRevisionDateCell);
                }
                if (Model.ShowPasswordRevisionDate)
                {
                    OtherSection.Add(LoginPasswordRevisionDateCell);
                }

                AddSectionCell(LoginUsernameCell, Model.ShowLoginUsername);
                AddSectionCell(LoginPasswordCell, Model.ShowLoginPassword);

                if (ItemInformationSection.Contains(LoginTotpCodeCell))
                {
                    ItemInformationSection.Remove(LoginTotpCodeCell);
                }
                if (cipher.Login?.Totp != null && (Helpers.CanAccessPremium() || cipher.OrganizationUseTotp))
                {
                    var totpKey = cipher.Login?.Totp.Decrypt(cipher.OrganizationId);
                    if (!string.IsNullOrWhiteSpace(totpKey))
                    {
                        var otpParams = new OtpAuth(totpKey);
                        Model.LoginTotpCode = Crypto.Totp(totpKey);
                        if (!string.IsNullOrWhiteSpace(Model.LoginTotpCode))
                        {
                            TotpTick(totpKey, otpParams.Period);
                            _timerStarted = DateTime.Now;
                            Device.StartTimer(new TimeSpan(0, 0, 1), () =>
                            {
                                if (_timerStarted == null || (DateTime.Now - _timerStarted) > _timerMaxLength)
                                {
                                    return(false);
                                }

                                TotpTick(totpKey, otpParams.Period);
                                return(true);
                            });

                            ItemInformationSection.Add(LoginTotpCodeCell);
                        }
                    }
                }
                break;

            case CipherType.Card:
                AddSectionCell(CardNameCell, Model.ShowCardName);
                AddSectionCell(CardNumberCell, Model.ShowCardNumber);
                AddSectionCell(CardBrandCell, Model.ShowCardBrand);
                AddSectionCell(CardExpCell, Model.ShowCardExp);
                AddSectionCell(CardCodeCell, Model.ShowCardCode);
                break;

            case CipherType.Identity:
                AddSectionCell(IdNameCell, Model.ShowIdName);
                AddSectionCell(IdUsernameCell, Model.ShowIdUsername);
                AddSectionCell(IdCompanyCell, Model.ShowIdCompany);
                AddSectionCell(IdSsnCell, Model.ShowIdSsn);
                AddSectionCell(IdPassportNumberCell, Model.ShowIdPassportNumber);
                AddSectionCell(IdLicenseNumberCell, Model.ShowIdLicenseNumber);
                AddSectionCell(IdEmailCell, Model.ShowIdEmail);
                AddSectionCell(IdPhoneCell, Model.ShowIdPhone);
                AddSectionCell(IdAddressCell, Model.ShowIdAddress);
                break;

            default:
                break;
            }
        }
Example #2
0
        private void BuildTable(Cipher cipher)
        {
            if (Table.Root.Contains(NotesSection))
            {
                Table.Root.Remove(NotesSection);
            }
            if (Model.ShowNotes)
            {
                Table.Root.Add(NotesSection);
            }

            // Attachments
            CleanupAttachmentCells();
            if (Table.Root.Contains(AttachmentsSection))
            {
                Table.Root.Remove(AttachmentsSection);
            }
            if (Model.ShowAttachments && _tokenService.TokenPremium)
            {
                AttachmentsSection = new TableSection(AppResources.Attachments);
                AttachmentCells    = new List <AttachmentViewCell>();
                foreach (var attachment in Model.Attachments.OrderBy(s => s.Name))
                {
                    var attachmentCell = new AttachmentViewCell(attachment, async() =>
                    {
                        await OpenAttachmentAsync(cipher, attachment);
                    });
                    AttachmentCells.Add(attachmentCell);
                    AttachmentsSection.Add(attachmentCell);
                    attachmentCell.InitEvents();
                }
                Table.Root.Add(AttachmentsSection);
            }

            // Fields
            if (Table.Root.Contains(FieldsSection))
            {
                Table.Root.Remove(FieldsSection);
            }
            if (Model.ShowFields)
            {
                FieldsSection = new TableSection(AppResources.CustomFields);
                foreach (var field in Model.Fields)
                {
                    FieldViewCell fieldCell;
                    switch (field.Type)
                    {
                    case FieldType.Text:
                        fieldCell = new FieldViewCell(this, field, null);
                        break;

                    case FieldType.Hidden:
                        fieldCell = new FieldViewCell(this, field, null, null);
                        break;

                    case FieldType.Boolean:
                        fieldCell = new FieldViewCell(this, field);
                        break;

                    default:
                        continue;
                    }
                    FieldsSection.Add(fieldCell);
                }
                Table.Root.Add(FieldsSection);
            }

            // Various types
            switch (cipher.Type)
            {
            case CipherType.Login:
                AddSectionCell(LoginUriCell, Model.ShowLoginUri);
                AddSectionCell(LoginUsernameCell, Model.ShowLoginUsername);
                AddSectionCell(LoginPasswordCell, Model.ShowLoginPassword);

                if (ItemInformationSection.Contains(LoginTotpCodeCell))
                {
                    ItemInformationSection.Remove(LoginTotpCodeCell);
                }
                if (cipher.Login?.Totp != null && (_tokenService.TokenPremium || cipher.OrganizationUseTotp))
                {
                    var totpKey = cipher.Login?.Totp.Decrypt(cipher.OrganizationId);
                    if (!string.IsNullOrWhiteSpace(totpKey))
                    {
                        Model.LoginTotpCode = Crypto.Totp(totpKey);
                        if (!string.IsNullOrWhiteSpace(Model.LoginTotpCode))
                        {
                            TotpTick(totpKey);
                            Device.StartTimer(new TimeSpan(0, 0, 1), () =>
                            {
                                if (_pageDisappeared)
                                {
                                    return(false);
                                }

                                TotpTick(totpKey);
                                return(true);
                            });

                            ItemInformationSection.Add(LoginTotpCodeCell);
                        }
                    }
                }
                break;

            case CipherType.Card:
                AddSectionCell(CardNameCell, Model.ShowCardName);
                AddSectionCell(CardNumberCell, Model.ShowCardNumber);
                AddSectionCell(CardBrandCell, Model.ShowCardBrand);
                AddSectionCell(CardExpCell, Model.ShowCardExp);
                AddSectionCell(CardCodeCell, Model.ShowCardCode);
                break;

            case CipherType.Identity:
                AddSectionCell(IdNameCell, Model.ShowIdName);
                AddSectionCell(IdUsernameCell, Model.ShowIdUsername);
                AddSectionCell(IdCompanyCell, Model.ShowIdCompany);
                AddSectionCell(IdSsnCell, Model.ShowIdSsn);
                AddSectionCell(IdPassportNumberCell, Model.ShowIdPassportNumber);
                AddSectionCell(IdLicenseNumberCell, Model.ShowIdLicenseNumber);
                AddSectionCell(IdEmailCell, Model.ShowIdEmail);
                AddSectionCell(IdPhoneCell, Model.ShowIdPhone);
                AddSectionCell(IdAddressCell, Model.ShowIdAddress);
                break;

            default:
                break;
            }
        }
Example #3
0
        protected async override void OnAppearing()
        {
            _pageDisappeared  = false;
            NotesCell.Tapped += NotesCell_Tapped;
            EditItem.InitEvents();

            var login = await _loginService.GetByIdAsync(_loginId);

            if (login == null)
            {
                await Navigation.PopForDeviceAsync();

                return;
            }

            Model.Update(login);

            if (LoginInformationSection.Contains(UriCell))
            {
                LoginInformationSection.Remove(UriCell);
            }
            if (Model.ShowUri)
            {
                LoginInformationSection.Add(UriCell);
            }

            if (LoginInformationSection.Contains(UsernameCell))
            {
                LoginInformationSection.Remove(UsernameCell);
            }
            if (Model.ShowUsername)
            {
                LoginInformationSection.Add(UsernameCell);
            }

            if (LoginInformationSection.Contains(PasswordCell))
            {
                LoginInformationSection.Remove(PasswordCell);
            }
            if (Model.ShowPassword)
            {
                LoginInformationSection.Add(PasswordCell);
            }

            if (Table.Root.Contains(NotesSection))
            {
                Table.Root.Remove(NotesSection);
            }
            if (Model.ShowNotes)
            {
                Table.Root.Add(NotesSection);
            }

            // Totp
            if (LoginInformationSection.Contains(TotpCodeCell))
            {
                LoginInformationSection.Remove(TotpCodeCell);
            }
            if (login.Totp != null && (_tokenService.TokenPremium || login.OrganizationUseTotp))
            {
                var totpKey = login.Totp.Decrypt(login.OrganizationId);
                if (!string.IsNullOrWhiteSpace(totpKey))
                {
                    Model.TotpCode = Crypto.Totp(totpKey);
                    if (!string.IsNullOrWhiteSpace(Model.TotpCode))
                    {
                        TotpTick(totpKey);
                        Device.StartTimer(new TimeSpan(0, 0, 1), () =>
                        {
                            if (_pageDisappeared)
                            {
                                return(false);
                            }

                            TotpTick(totpKey);
                            return(true);
                        });

                        LoginInformationSection.Add(TotpCodeCell);
                    }
                }
            }

            CleanupAttachmentCells();
            if (Table.Root.Contains(AttachmentsSection))
            {
                Table.Root.Remove(AttachmentsSection);
            }
            if (Model.ShowAttachments && _tokenService.TokenPremium)
            {
                AttachmentsSection = new TableSection(AppResources.Attachments);
                AttachmentCells    = new List <AttachmentViewCell>();
                foreach (var attachment in Model.Attachments.OrderBy(s => s.Name))
                {
                    var attachmentCell = new AttachmentViewCell(attachment, async() =>
                    {
                        await OpenAttachmentAsync(login, attachment);
                    });
                    AttachmentCells.Add(attachmentCell);
                    AttachmentsSection.Add(attachmentCell);
                    attachmentCell.InitEvents();
                }
                Table.Root.Add(AttachmentsSection);
            }

            if (Table.Root.Contains(FieldsSection))
            {
                Table.Root.Remove(FieldsSection);
            }
            if (Model.ShowFields)
            {
                FieldsSection = new TableSection(AppResources.CustomFields);
                foreach (var field in Model.Fields)
                {
                    FieldViewCell fieldCell;
                    switch (field.Type)
                    {
                    case FieldType.Text:
                        fieldCell = new FieldViewCell(this, field, null);
                        break;

                    case FieldType.Hidden:
                        fieldCell = new FieldViewCell(this, field, null, null);
                        break;

                    case FieldType.Boolean:
                        fieldCell = new FieldViewCell(this, field);
                        break;

                    default:
                        continue;
                    }
                    FieldsSection.Add(fieldCell);
                }
                Table.Root.Add(FieldsSection);
            }

            base.OnAppearing();
        }