예제 #1
0
    def export(self):
        pin = self.widgetsForEntries[1].get()
        password = self.widgetsForEntries[3].get()

        if not (pin and password):
            messagebox.showerror(lp[self.language]['error'],
                                 lp[self.language]['pin_and_password_req'])
            Window.delete_entries(self.widgetsForEntries[1],
                                  self.widgetsForEntries[3])
            return

        if pin == DbManager.get_column_value_where('Users', 'pin', 'id', self.user['id']) \
                and password == DbManager.get_column_value_where('Users', 'password', 'id', self.user['id']):
            Window.close_top_level(self, self.btnsToDisable)

            path = filedialog.askdirectory()
            path += '/exported_accounts.txt'

            accounts = DbManager.get_user_accounts(self.user['id'])

            try:
                with open(path, 'w') as file:
                    for account in accounts:
                        row = 'title: ' + account['title'] + '\tlogin: '******'login'] + '\tassociated email: ' + \
                              account['associated_email'] + '\tpassword: '******'password'] + '\n'
                        file.write(row)
                messagebox.showinfo(lp[self.language]['data_exported'],
                                    lp[self.language]['data_exported_info'])

            except PermissionError:
                pass
        else:
            messagebox.showerror(lp[self.language]['error'],
                                 lp[self.language]['pin_or_password_invalid'])
            Window.delete_entries(self.widgetsForEntries[1],
                                  self.widgetsForEntries[3])
예제 #2
0
    def display_accounts(self):
        self.showButtons.clear()
        self.toDisable.clear()
        for row in self.accountsRowsWidgets:
            for widget in row.values():
                widget.destroy()

        self.accountsRowsWidgets.clear()
        accounts = DbManager.get_user_accounts(self.user['id'])

        for i in range(len(accounts)):
            title = tk.Label(self.scrollframe.viewPort,
                             text=accounts[i]['title'],
                             bg=self.bg_color)
            title.grid(row=i + 1, column=0)

            login = tk.Label(self.scrollframe.viewPort,
                             text=accounts[i]['login'],
                             bg=self.bg_color)
            login.grid(row=i + 1, column=1)

            associated_email = tk.Label(self.scrollframe.viewPort,
                                        text=accounts[i]['associated_email'],
                                        bg=self.bg_color)
            associated_email.grid(row=i + 1, column=2)

            # SHOW BTN
            show_btn = tk.Button(self.scrollframe.viewPort,
                                 text=lp[self.language]['enter_pin_to_show'],
                                 bg='white')
            show_btn.grid(row=i + 1, column=3)
            self.showButtons.append({
                'btn': show_btn,
                'y': i + 1,
                'x': self.passwordWidth,
                'acc_id': accounts[i]['id']
            })
            self.showButtons[i]['btn'][
                'command'] = lambda btn=self.showButtons[
                    i]: self.show_password(btn)

            # EDIT BTN
            edit_btn = tk.Button(self.scrollframe.viewPort,
                                 text=lp[self.language]['edit'],
                                 bg='white',
                                 command=lambda index=i: self.edit_account(
                                     accounts[index]['id']))
            edit_btn.grid(row=i + 1, column=99)
            self.editButtons.append({
                'btn': edit_btn,
                'x': self.editWidth,
                'y': 0.05 * i
            })

            # DELETE BTN
            delete_btn = tk.Button(self.scrollframe.viewPort,
                                   text=lp[self.language]['delete'],
                                   bg='red',
                                   fg='white',
                                   command=lambda index=i: self.delete_account(
                                       accounts[index]['id']))
            delete_btn.grid(row=i + 1, column=100)

            row = {
                'title': title,
                'login': login,
                'associated_email': associated_email,
                'show_btn': show_btn,
                'edit_btn': edit_btn,
                'delete_btn': delete_btn
            }

            self.accountsRowsWidgets.append(row)

            self.toDisable.append(edit_btn)
            self.toDisable.append(delete_btn)

        self.toDisable.append(self.addAccountBtn)