def setChPw(self): if len(self.entUid.get()) <= 0 : return sql = "SELECT * FROM acct WHERE uid = %s" val = (self.entUid.get(),) data = getdata_one(sql,val) if data != None : uid = data[0] password = data[2] matchpw = verify_password(self.entCurPw.get(),password) if matchpw == False: messagebox.showerror(title="Error",message="Password lama tidak sesuai") self.entCurPw.focus_set() elif (len(self.entNewPw.get()) <= 0) or (str(self.entNewPw.get()) != str(self.entConfPw.get())): messagebox.showerror(title="Error",message="Konfirmasi Password tidak sesuai") self.entConfPw.focus_set() elif messagebox.askokcancel('Change Password','Anda yakin akan mengganti Password?') == True: storepw = generate_hash(self.entNewPw.get()) sql = "UPDATE acct SET passhash=%s WHERE uid=%s" val = (storepw,uid) if (insert_data(sql,val)) == True: messagebox.showinfo(title="Change Password", \ message="Password baru sudah berhasil diupdate.") self.cancelChPw(0) else: self.cancelChPw(0)
def proses(self, event=None): sql = "SELECT * FROM acct WHERE username = %s" val = (self.entryUsername.get(), ) data = getdata_one(sql, val) if data != None: uid = data[0] user = data[1] password = data[2] dept = data[4] datecreate = GetSeconds(str(data[5])) matchpw = verify_password(self.entryPassword.get(), password) host_name = socket.gethostname() host_ip = socket.gethostbyname(host_name) # login username samakan saja menjadi lower if (str(self.entryUsername.get()).lower().strip() == user.lower()) \ and (matchpw == True): if data[6] != True: # bagian ceking aktivasi + remove acct datetodrop = datecreate.value + 604800 # 86400*7 (7 hari). Lebih baik buat custom duration = GetDuration(datetodrop - time.time()) messagebox.showerror(title="Belum Aktivasi", \ message="Tidak dapat menggunakan program.\r\nsilahkan hubungi Administrator\r\nuntuk Aktivasi Departement.\ \r\n \ \r\nSisa waktu: {}" .format(duration.value)) # bagian remove account if ((datetodrop - time.time()) <= 0 and RemoveAcct(uid).result == True): messagebox.showwarning( title="Account Info", message="Account Deleted successfully") return if data[7] == True: messagebox.showerror(title="Account dikunci", \ message="Tidak dapat menggunakan program.\r\nAccount anda telah dikunci.") return if data[12] == None: messagebox.showerror(title="Double Login Warning!", \ message="Tidak dapat login program.\r\nAccount anda sedang digunakan.") return sql = "UPDATE acct SET last_login=%s,last_host=%s,last_ip=%s,last_logout=%s WHERE uid=%s" val = (datetime.now(), host_name, host_ip, "", data[0]) if (insert_data(sql, val)) == True: self.user = user self.dept = dept self.top.destroy() else: return else: #untuk salah password self.entryPassword.delete(0, END) self.entryPassword.focus_set() else: self.entryUsername.delete(0, END) self.entryPassword.delete(0, END) self.entryUsername.focus_set()
def user_detail(self): self.entryset("clear") sql = "SELECT * FROM acct WHERE username = %s" val = (self.user,) data = getdata_one(sql,val) if data != None : self.entUid.insert(END,data[0]) self.entName.insert(END,data[1]) self.entDept.insert(END,data[4]) self.entEmail.insert(END,data[3]) self.entLastLog.insert(END,data[9]) self.entLastPC.insert(END,data[10]) self.entLastIP.insert(END,data[11]) self.entryset("read")
def mainlog_detail(self, event): try: curItem = self.tabelIfca.item(self.tabelIfca.focus()) ifca_value = curItem['values'][1] self.entrySet("mainclear") self.entrySet("disablebtn") if self.dept == "ROOT": self.btnDelete.config(state="normal") self.entTglbuat.config(state="normal") self.entJambuat.config(state="normal") self.entTgldone.config(state="normal") self.entJamdone.config(state="normal") sql = "SELECT * FROM logbook WHERE no_ifca = %s" val = (ifca_value, ) data = getdata_one(sql, val) self.entIfca.insert(END, ifca_value) self.entWo.insert(END, data[1]) self.entTglbuat.insert(END, get_date(str(data[3]))) self.entJambuat.insert(END, data[13]) self.entUnit.insert(END, data[4]) self.entWorkReq.insert(END, data[5]) self.entStaff.insert(END, data[6]) self.entTgldone.insert(END, get_date(str(data[8]))) self.entJamdone.insert(END, data[9]) self.entWorkAct.insert(END, data[7]) self.entRecDate.insert(END, get_date(str(data[12]))) self.entRecBy.insert(END, data[11]) if data[14] == "DONE": self.opsiStatus.current(1) self.btnReceived.config(state="normal") # ngapain diUpdate lagi wo sudah DONE elif data[14] == "CANCEL": self.opsiStatus.current(2) self.btnReceived.config(state="normal") elif data[14] == "PENDING": self.opsiStatus.current(3) elif data[14] == "ONPROGRESS" or data[14] == "RETURNED" or data[ 14] == "TAKEN": self.opsiStatus.current(0) else: if self.dept == "ENG": # khusus class ENG self.btnUpdate.config(state="normal") self.btnDateDone.config(state="normal") self.opsiStatus.current(0) if data[10] == True and ifca_value[:2] == "TN": # tidak dapat receive wo TN karena sudah direceive self.btnReceived.config(state="disable") # read only setelah entry terisi self.entrySet("mainreadifca") except: print('Tidak ada data di tabel')
def proses(self): sql = "SELECT * FROM acct WHERE username = %s" val = (self.entUser.get(), ) data = getdata_one(sql, val) if (self.entUser.get() == ""): self.entUser.focus_set() elif (self.entPass.get() == ""): self.entPass.focus_set() elif (self.entConf.get() == ""): self.entConf.focus_set() elif (self.entEmail.get() == ""): self.entEmail.focus_set() elif data == None: if str(self.entPass.get()).lower() != str( self.entConf.get()).lower(): # parent=self.top karena msgbox with toplevel messagebox.showerror(title="Error",parent=self.top,\ message="Konfirmasi Password tidak sesuai") self.entConf.focus_set() elif len(self.entUser.get()) < 3: messagebox.showerror(title="Error",parent=self.top,\ message="Username harus antara 3 - 10 karakter") self.entUser.focus_set() elif self.entUser.get().isalnum() == False: messagebox.showerror(title="Error",parent=self.top,\ message="Username yang diperbolehkan hanya kombinasi huruf dan angka") self.entUser.focus_set() else: storepw = generate_hash(self.entPass.get()) sql = "INSERT INTO acct (username,passhash,email,dept,date_create,last_logout)"+\ "VALUES(%s,%s,%s,%s,%s,%s)" val = (self.entUser.get().strip(), storepw, self.entEmail.get(), "USER", datetime.now(), datetime.now()) if (insert_data(sql, val)) == True: messagebox.showinfo( title="Account Info", message="Account registration is successful") self.value = self.entUser.get() self.top.destroy() else: user = data[1] password = data[2] dept = data[3] if str(self.entUser.get()).lower().strip() == user.lower(): # parent=self.top karena msgbox with toplevel messagebox.showerror(title="Error",parent=self.top, \ message="User {} sudah terdaftar.\nSilahkan pilih yang lain".format(self.entUser.get())) self.entUser.focus_set()
def checkifca(self, data): if ((data[:2] != "BM") and (data[:2] != "TN")): # print("bukan TIPE yang benar,",data[:2]) return False elif (len(data) != 10): # print("panjang =",len(data)) return False elif (data[2:].isdigit() == False): # print("8 char digit?",data[2:].isdigit()) return False else: sql = ("SELECT * FROM logbook where no_ifca LIKE %s") val = (data, ) hasil = getdata_one(sql, val) if hasil == None: # print("diterima,",data,"!-",hasil) return True if (data == hasil[2]): # print("ditolak,",data,"=",hasil[2]) return False
def progress_detail(self, event): try: curItem = self.tabelProg.item(self.tabelProg.focus()) ifca_value = curItem['values'][1] self.entrySet("progclear") self.commited_table(ifca_value) self.progIfca.insert(END, ifca_value) # sql = "SELECT no_wo, no_ifca, date_create, unit, work_req, staff, work_act, time_create, status_ifca FROM logbook WHERE no_ifca = %s" sql = "SELECT no_wo,no_ifca,date_create,time_create,unit,\ work_req,staff,status_ifca FROM logbook WHERE no_ifca = %s" val = (ifca_value, ) data = getdata_one(sql, val) self.progWo.insert(END, data[0]) #TGL buat self.progTgl.insert(END, get_date(str(data[2]))) self.progJam.insert(END, data[3]) self.progUnit.insert(END, data[4]) self.progWorkReq.insert(END, data[5]) self.progStaff.insert(END, data[6]) self.entrySet("progread") self.commitdate.config(state="disable") if (self.dept == "ENG") or (self.dept == "CS"): if data[7] == "PENDING": self.btnCommUpdate.config(state="disable") self.btnPendAccp.config(state="normal") elif data[7] == "ONPROGRESS": self.btnCommUpdate.config(state="normal") self.btnCommReturn.config(state="normal") elif (data[7] == "RETURNED") and (self.dept == "ENG"): self.btnCommTake.config(state="normal") elif (data[7] == "TAKEN") and (self.dept == "ENG"): self.btnCommDone.config(state="normal") else: pass else: pass #fungsi diatas hanya untuk cs-eng self.commitby.focus_set() except: print('Tidak ada data di tabel')
def checkwo(self, data): if (len(data) < 1): # Jika wo kosong # print("Diterima, len data",len(data),"wo bisa kosong") return data elif (len(data) >= 1 and data.isdigit() == False): # print("Ditolak, digit",data.isdigit()) return False else: # print("no awal",data) while 0 < len(data): # jika ada "0" didepan hapus aja if data[0] == '0': data = data[1:] continue break # print("no akhir",data) sql = ("SELECT * FROM logbook where no_wo LIKE %s") val = (data, ) hasil = getdata_one(sql, val) if (hasil == None): # Jika wo no. baru # print("diterima,",data,"!-",hasil) return data if (data == hasil[1]): # print("ditolak,",data,"=",hasil[1]) return False