コード例 #1
0
    def edit_account(self):
        validation_result = self.validation()

        if validation_result:
            title = validation_result[0]
            login = validation_result[1]
            associated_email = validation_result[2]
            password = validation_result[3]

            DbManager.update('Accounts', 'title', title, 'id', self.accId)
            DbManager.update('Accounts', 'login', login, 'id', self.accId)
            DbManager.update('Accounts', 'associated_email', associated_email,
                             'id', self.accId)
            DbManager.update('Accounts', 'password', password, 'id',
                             self.accId)

            self.refreshAccountListMethod()
            Window.close_top_level(self, self.toDisable)
コード例 #2
0
    def add_account(self):
        validation_result = self.validation()

        if validation_result:
            title = validation_result[0]
            login = validation_result[1]
            associated_email = validation_result[2]
            password = validation_result[3]

            user_id = DbManager.get_column_value_where('Users', 'id', 'login',
                                                       self.user['login'])
            DbManager.insert(
                'Accounts',
                'title, login, associated_email, password, user_id',
                (title, login, associated_email, password, user_id))

            self.refreshAccountListMethod()
            Window.close_top_level(self, self.toDisable)
コード例 #3
0
    def save_new_security(self):
        old_security = self.oldSecurityEntry.get()
        new_security = self.newSecurityEntry.get()
        confirm_security = self.confirmSecurityEntry.get()

        if not (old_security and new_security and confirm_security):
            messagebox.showerror('Error', 'All fields required.')
            Window.delete_entries(self.oldSecurityEntry, self.newSecurityEntry,
                                  self.confirmSecurityEntry)
            return

        if old_security != DbManager.get_column_value_where(
                'Users', self.mode, 'id', self.user["id"]):
            messagebox.showerror('Error', 'Invalid old PIN.')
            Window.delete_entries(self.oldSecurityEntry, self.newSecurityEntry,
                                  self.confirmSecurityEntry)
            return

        if self.mode == 'password':
            if len(new_security) < 8:  # minimum password length
                messagebox.showerror(
                    'Error', 'Password must be at least 8 characters long.')
                Window.delete_entries(self.oldSecurityEntry,
                                      self.newSecurityEntry,
                                      self.confirmSecurityEntry)
                return

        if new_security != confirm_security:
            messagebox.showerror(
                'Error',
                '\'New password\' and \'Confirm password\' entries don\'t match.'
            )
            Window.delete_entries(self.oldSecurityEntry, self.newSecurityEntry,
                                  self.confirmSecurityEntry)
            return

        DbManager.update('Users', self.mode, new_security, 'id',
                         self.user['id'])  # mode is pwd or pin
        messagebox.showinfo(
            'Success',
            f'Your {self.mode} has been successfully changed.\nRemember not to share it '
            'with anyone else.')
        self.master.user[self.mode] = new_security  # update user
        Window.close_top_level(self, self.master.toDisable)
コード例 #4
0
    def __init__(self, master, mode, language):
        super().__init__(master.root)
        self.language = language
        self.user = master.user
        self.mode = mode
        self.toDisable = master.toDisable
        self.accId = None

        self.refreshAccountListMethod = master.display_accounts

        self.bg_color = master.bg_color
        self.width, self.height = pag.size()

        self.canvas = tk.Canvas(self,
                                width=self.width / 7,
                                height=self.height / 2,
                                bg=self.bg_color)
        self.addAccountLabel = tk.Label(self,
                                        text=f'{self.mode} account',
                                        bg=self.bg_color,
                                        font='12')
        self.accTitleLabel = tk.Label(self, text='Title:', bg=self.bg_color)
        self.accTitleEntry = tk.Entry(self, width=25)
        self.loginLabel = tk.Label(self, text='Login*:', bg=self.bg_color)
        self.loginEntry = tk.Entry(self, width=25)
        self.associatedEmailLabel = tk.Label(self,
                                             text='Associated Email*:',
                                             bg=self.bg_color)
        self.associatedEmailEntry = tk.Entry(self, width=25)
        self.requiredInfo = tk.Label(
            self,
            text='* At least one of these two\nis required.',
            bg=self.bg_color)
        self.saveBtn = tk.Button(self, text='Save', bg='white')

        if mode == 'Add':
            self.saveBtn['command'] = self.add_account
        elif mode == 'Edit':
            self.saveBtn['command'] = self.edit_account
        else:
            self.saveBtn['command'] = None

        self.passwordLabel = tk.Label(self, text='Password:'******'*')
        self.passwordConfirmLabel = tk.Label(self,
                                             text='Confirm Password:'******'*')
        self.pinLabel = tk.Label(self, text='PIN:', bg=self.bg_color)
        self.pinEntry = tk.Entry(self, width=25, show='*')

        self.place_widgets()
        self.protocol('WM_DELETE_WINDOW',
                      lambda: Window.close_top_level(self, self.toDisable))
コード例 #5
0
    def remind_password(self):
        login = self.widgetsForEntries[1].get()
        email = self.widgetsForEntries[3].get()

        if '' in (login, email):
            messagebox.showerror(lp[self.language]['error'],
                                 lp[self.language]['fill_all_entries'])
            return

        if not re.match(r'[^@]+@[^@]+\.[^@]+', email):
            messagebox.showerror(lp[self.language]['error'],
                                 lp[self.language]['invalid_email'])
            return

        log_in_db = DbManager.get_column_values('Users', 'login')

        if login not in log_in_db:
            messagebox.showerror(
                lp[self.language]['error'],
                lp[self.language]['incorrect_login'].format(login=login))
            return

        if email != DbManager.get_column_value_where('Users', 'email', 'login',
                                                     login):
            messagebox.showerror(
                lp[self.language]['error'],
                lp[self.language]['email_doesnt_match'].format(email=email))
            return

        password = DbManager.get_column_value_where('Users', 'password',
                                                    'login', login)

        if MailManager.send_mail(self.language,
                                 email,
                                 msg_type='password_request',
                                 data=password,
                                 data2=login):
            messagebox.showinfo(
                lp[self.language]['password_reminder_req'],
                lp[self.language]['password_reminder_accepted'])
        Window.close_top_level(self, self.btnsToDisable)
コード例 #6
0
    def reset_pin(self):
        new_pin = self.widgetsForEntries[1].get()
        pin_confirm = self.widgetsForEntries[3].get()

        if not (new_pin and pin_confirm):
            messagebox.showerror(
                'Error', 'New PIN and PIN confirmation are both required.')
            Window.delete_entries(self.widgetsForEntries[1],
                                  self.widgetsForEntries[3])
            return

        if new_pin != pin_confirm:
            messagebox.showerror('Error',
                                 'New PIN and PIN confirmation do not match.')
            Window.delete_entries(self.widgetsForEntries[1],
                                  self.widgetsForEntries[3])
            return

        DbManager.update('Users', 'pin', new_pin, 'id', self.user['id'])
        self.user['pin'] = new_pin
        messagebox.showinfo('Success',
                            'Your new PIN has been successfully set.')

        Window.close_top_level(self, self.btnsToDisable)
コード例 #7
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])
コード例 #8
0
    def __init__(self, master, mode, language):
        super().__init__()
        self.language = language
        self.master = master
        self.user = master.user
        self.mode = mode
        self.bg_color = master.bg_color

        self.width, self.height = pag.size().width / 5, pag.size().height / 4

        self.canvas = tk.Canvas(self,
                                width=self.width,
                                height=self.height,
                                bg=self.bg_color)

        self.titleLabel = tk.Label(self,
                                   text=f'Change {mode}',
                                   bg=self.bg_color,
                                   font=10)
        self.oldSecurityLabel = tk.Label(self,
                                         text=f'Old {mode}:',
                                         bg=self.bg_color)
        self.oldSecurityEntry = tk.Entry(self, width=20, bg='white', show='*')
        self.newSecurityLabel = tk.Label(self,
                                         text=f'New {mode}:',
                                         bg=self.bg_color)
        self.newSecurityEntry = tk.Entry(self, width=20, bg='white', show='*')
        self.confirmSecurityLabel = tk.Label(self,
                                             text=f'Confirm {mode}:',
                                             bg=self.bg_color)
        self.confirmSecurityEntry = tk.Entry(self,
                                             width=20,
                                             bg='white',
                                             show='*')
        self.saveBtn = tk.Button(self,
                                 text='Save',
                                 width=20,
                                 bg='white',
                                 command=self.save_new_security)

        self.place_widgets()
        self.protocol('WM_DELETE_WINDOW',
                      lambda: Window.close_top_level(self, master.toDisable))
コード例 #9
0
    def __init__(self, master, title, entries, user, btns_to_disable, bg_color,
                 language):
        super().__init__(master)
        self.language = language
        self.master = master
        self.width, self.height = pag.size()
        self.widgetsForEntries = []
        self.btnsToDisable = btns_to_disable
        self.user = user
        self.jobs = {
            'Forgot password?': self.remind_password,
            'Export data': self.export,
            'Reset PIN': self.reset_pin,
        }

        self.canvas = tk.Canvas(self,
                                width=self.width / 5,
                                height=self.height / 5,
                                bg=bg_color)
        self.titleLabel = tk.Label(self, text=title, font='12', bg=bg_color)

        for i in range(0, len(entries)):
            self.widgetsForEntries.append(
                tk.Label(self, text=entries[i] + ':', bg=bg_color))

            asterisk_entry = tk.Entry(self, width=25)
            self.widgetsForEntries.append(asterisk_entry)
            if lp[self.language][
                    title] != 'Forgot password?':  # if it's password recovery don't hide entries
                asterisk_entry['show'] = '*'  # for login and email

        self.ConfirmBtn = tk.Button(
            self,
            text='OK',
            bg='white',
            command=self.jobs[lp[self.language][title]])

        self.place_widgets()
        AskValuesWindow.disable_buttons(self.btnsToDisable)

        self.protocol('WM_DELETE_WINDOW',
                      lambda: Window.close_top_level(self, self.btnsToDisable))