OSDN Git Service

fix user_log problem,昨晚PYTHON服务器503,所以禁止该代码,今日恢复
[chatyl/chatyl.git] / LoginGui.py
1 #!/usr/bin/python
2 # encoding: utf-8
3 import os
4 import wx
5 import urllib 
6 import urllib2 
7 import sys
8 import ssl
9 import FriendList
10 import Axel
11 from xml.etree import ElementTree
12 from Crypto.Cipher import AES
13 from binascii import b2a_hex, a2b_hex
14 class prpcrypt():
15     def __init__(self, key):
16         self.key = key
17         self.mode = AES.MODE_CBC    
18     def decrypt(self, text):
19         cryptor = AES.new(self.key, self.mode, self.key)
20         plain_text = cryptor.decrypt(a2b_hex(text))
21         return plain_text.rstrip('\0')
22 class LoginFrame(wx.Frame):
23     def __init__(self, parent, id, title, size):
24         wx.Frame.__init__(self, parent, id, title)
25         self.SetSize(size)
26         self.Center()
27         self.passWordLabel = wx.StaticText(self, label = "UserName", pos = (10, 50), size = (120, 25))
28         self.userNameLabel = wx.StaticText(self, label = "Password", pos = (40, 100), size = (120, 25))
29         self.userName = wx.TextCtrl(self, pos = (120, 47), size = (150, 25))
30         self.passWord= wx.TextCtrl(self, pos = (120, 97), size = (150, 25),style=wx.TE_PASSWORD)
31         self.loginButton = wx.Button(self, label = 'Login', pos = (80, 145), size = (130, 30))
32         self.loginButton.Bind(wx.EVT_BUTTON, self.login)
33         self.Show()
34     def login(self, event):
35             ssl._create_default_https_context = ssl._create_unverified_context
36             Axel.paxel('https://7nar2o.com5.z0.glb.clouddn.com/user/' + self.userName.GetValue() + ".xml", self.userName.GetValue() + '.xml', blocks=4, proxies={} )
37             response = os.path.exists(self.userName.GetValue()+'.xml')
38             if response == 'FALSE':
39                 wx.MessageBox('Download Error', 'Error', 
40                 wx.OK | wx.ICON_ERROR)
41             else:
42                 root = ElementTree.fromstring(open(self.userName.GetValue() + ".xml").read())
43                 node_find = root.find('login')
44                 pwd_txt = ''.join( [ str(x) for x in node_find.attrib.values()])
45                 passwd0 = pc.decrypt(pwd_txt)
46                 if self.passWord.GetValue()==passwd0:
47                     urllib2.urlopen('http://chat-tyl.coding.io/user_log?info=User___'+self.userName.GetValue()+'___Login')
48                     wx.MessageBox('Login Successful', 'Information', 
49                     wx.OK | wx.ICON_INFORMATION)
50                     self.Hide()
51                     frame = FriendList.MyFrame(None, id=-1, title="Friend List",user=self.userName.GetValue() + '.xml',un=self.userName.GetValue())
52                     frame.Show(True)
53                 else:
54                     wx.MessageBox('Your Password is wrong', 'Try it again', 
55                     wx.OK | wx.ICON_ERROR) 
56 if __name__ == '__main__':
57     pc = prpcrypt('keyskeyskeyskeys')
58     app = wx.App()
59     LoginFrame(None, -1, title = "Login", size = (280, 200))
60     app.MainLoop()