/
login.py
98 lines (75 loc) · 2.8 KB
/
login.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import curses
import curses.textpad
class TextBox(object):
def __init__(self, win, y, x, txt):
self._win = win.derwin(1, 30, y, x)
self._win.clear()
self._txtbox = curses.textpad.Textbox(self._win)
self._txtbox.stripspaces = True
if txt is not None:
self._insert(txt)
def edit(self):
return self._txtbox.edit()
def value(self):
return self._txtbox.gather()
def _insert(self, txt):
for ch in txt:
self._txtbox.do_command(ch)
class PasswordBox(TextBox):
def __init__(self, win, y, x, txt):
super(PasswordBox, self).__init__(win, y, x, txt)
self._password = ''
def edit(self, cb=None):
return self._txtbox.edit(self._validateInput)
def value(self):
return self._password
def _validateInput(self, ch):
if ch in (curses.KEY_BACKSPACE, curses.ascii.BS):
self._password = self._password[0:-1]
return ch
elif curses.ascii.isprint(ch):
self._password += chr(ch)
return '*'
else:
return ch
def _insert(self, str):
for ch in str:
self._password += ch
self._txtbox.do_command('*')
class aMSNLoginWindow(object):
def __init__(self, amsn_core, parent):
self._amsn_core = amsn_core
self.switch_to_profile(None)
self._stdscr = parent._stdscr
self._win = curses.newwin(20, 100, 5, 5)
def show(self):
self._win.border()
self._win.addstr(5, 5, "Account : ", curses.A_BOLD)
self._username_t = TextBox(self._win, 5, 17, self._username)
self._win.addstr(8, 5, "Password : ", curses.A_BOLD)
self._password_t = PasswordBox(self._win, 8, 17, self._password)
self._win.refresh()
self._username_t.edit()
self._password_t.edit()
self.signin()
def hide(self):
self._username_t = None
self._password_t = None
self._win.clear()
self._win.refresh()
def switch_to_profile(self, profile):
self.current_profile = profile
if self.current_profile is not None:
self._username = self.current_profile.username
self._password = self.current_profile.password
def signin(self):
self.current_profile.username = self._username_t.value()
self.current_profile.email = self._username_t.value()
self.current_profile.password = self._password_t.value()
self._amsn_core.signinToAccount(self, self.current_profile)
def onConnecting(self, progress, message):
self._username_t = None
self._password_t = None
self._win.clear()
self._win.addstr(10, 25, message, curses.A_BOLD | curses.A_STANDOUT)
self._win.refresh()