def ResendPassword(): conn = sqlite3.connect('Emailbox.db') cursor = conn.cursor() #get all unfinish mailbox_binding cursor.execute( '''SELECT CLIENT_ID, (strftime('%s','now') - strftime('%s', LAST_REMIND_TIME)) FROM MAILBOX_BINDING WHERE FINISH=0 ''') orders = cursor.fetchall() if orders is not None: for order in orders: client_id = order[0] last_remind = order[1] if last_remind > 60: #change password pwd = ''.join( random.choice(string.digits) for _ in range(8)) pwdHashing = MailboxRepository.PwdHashing(pwd) cursor.execute( "UPDATE MAILBOX_BINDING SET PWD=?, LAST_REMIND_TIME=CURRENT_TIMESTAMP", (pwdHashing, )) #send password to client cursor.execute( "SELECT EMAIL_ADDRESS FROM CLIENTS WHERE ID=?", (client_id, )) client_email_address = cursor.fetchone() sendMailThread = MailSender.SendPasswordMailThread( client_email_address[0], pwd) sendMailThread.start() sendMailThread.join() conn.commit() conn.close()
def ConfirmAssign(mailboxList, client): conn = sqlite3.connect('Emailbox.db') cursor = conn.cursor() idList = list() #set mailbox inused for mailbox in mailboxList: idList.append(mailbox.id) cursor.execute("UPDATE MAILBOXES SET INUSED=1 WHERE ID=?", (mailbox.id, )) #random password pwd = ''.join(random.choice(string.digits) for _ in range(8)) #get pwd hash hashPwd = MailboxRepository.PwdHashing(pwd) insertData = ( hashPwd, json.dumps(idList), client.id, ) #bind the mailbox inused, and client id, password cursor.execute( "INSERT INTO MAILBOX_BINDING VALUES(NULL,?,?,?,CURRENT_TIMESTAMP,0)", insertData) sendEmailThread = MailSender.SendPasswordMailThread( client.email_address, pwd) sendEmailThread.start() conn.commit() conn.close()