8 from Crypto.Cipher import AES
9 from binascii import b2a_hex, a2b_hex
11 import simplejson as json
12 from gi.repository import Notify
17 if locale.getdefaultlocale()[0] == 'zh_CN':
18 gettext.install('messages', './locale', unicode=False)
19 gettext.translation('messages', './locale', languages=['cn']).install(True)
21 def __init__(self, key):
23 self.mode = AES.MODE_CBC
24 def decrypt(self, text):
25 cryptor = AES.new(self.key, self.mode, self.key)
26 plain_text = cryptor.decrypt(a2b_hex(text))
27 return plain_text.rstrip('\0')
28 class LoginFrame(wx.Frame):
29 def __init__(self, parent, id, title, size):
30 wx.Frame.__init__(self, parent, id, title)
33 self.passWordLabel = wx.StaticText(self, label = _("UserName"), pos = (30, 50), size = (120, 25))
34 self.userNameLabel = wx.StaticText(self, label = _("Password"), pos = (30, 100), size = (120, 25))
35 self.userName = wx.TextCtrl(self, pos = (100, 47), size = (150, 25))
36 self.passWord= wx.TextCtrl(self, pos = (100, 97), size = (150, 25),style=wx.TE_PASSWORD)
37 self.loginButton = wx.Button(self, label = _('Login'), pos = (80, 145), size = (130, 30))
38 self.loginButton.Bind(wx.EVT_BUTTON,self.login_thread)
40 def login_thread(self,event):
41 thread.start_new_thread(self.login, ())
42 self.loginButton.Disable()
44 if not self.userName.GetValue():
45 wx.CallAfter(wx.MessageBox,_('Please enter the username'), _('Error'),
46 wx.OK | wx.ICON_ERROR)
47 wx.CallAfter(self.loginButton.Enable)
48 elif not self.passWord.GetValue():
49 wx.CallAfter(wx.MessageBox,_('Please enter the password'), _('Error'),
50 wx.OK | wx.ICON_ERROR)
51 wx.CallAfter(self.loginButton.Enable)
54 db=MySQLdb.connect(host="sql6.freesqldatabase.com",user="sql685198",passwd="jH8*bX3*",db="sql685198",port=3306 )
56 sql = "SELECT uncompress(password) FROM user WHERE name = '%s' LIMIT 1"%(self.userName.GetValue())
58 results = cursor.fetchall()
63 wx.CallAfter(wx.MessageBox,_('Unable to fecth data,Please check your username'),_('Try it again'),
64 wx.OK | wx.ICON_ERROR)
65 wx.CallAfter(self.loginButton.Enable)
66 except MySQLdb.Error, e:
67 wx.CallAfter(wx.MessageBox,'Error %d: %s' % (e.args[0], e.args[1]),_('Try it again'),
68 wx.OK | wx.ICON_ERROR)
69 wx.CallAfter(self.loginButton.Enable)
70 passwd0 = pc.decrypt(password)
71 if self.passWord.GetValue()==passwd0:
73 cursor.execute("SELECT uncompress(Data) FROM friendlist WHERE name = '%s' LIMIT 1"%(self.userName.GetValue()))
74 data = json.loads(cursor.fetchone()[0])
79 wx.CallAfter(wx.MessageBox,'Error %d: %s' % (e.args[0], e.args[1]),_('Try it again'),
80 wx.OK | wx.ICON_ERROR)
81 wx.CallAfter(self.loginButton.Enable)
82 #urllib2.urlopen('http://chat-tyl.coding.io/user_log?info=User___'+self.userName.GetValue()+'___Login')
83 wx.CallAfter(Notify.init,"Chat-TYL")
84 wx.CallAfter(Notify.init ,"Chat-TYL")
85 bubble_notify = Notify.Notification.new (_("Information"),_("Login Successful"),"file://" + os.path.abspath(os.path.curdir) + "/Chat-TYL.ico")
86 wx.CallAfter(bubble_notify.show)
87 wx.CallAfter(self.Hide)
89 frame = FriendList.MyFrame(None, id=-1, title=_("Friend List"),user=data,un=self.userName.GetValue())
90 wx.CallAfter(frame.Show,True)
92 wx.CallAfter(wx.MessageBox,_('Your Password is wrong'), _('Try it again'),
93 wx.OK | wx.ICON_ERROR)
94 if __name__ == '__main__':
95 pc = prpcrypt('keyskeyskeyskeys')
97 LoginFrame(None, -1, title = _("Login"), size = (280, 180))