prompt to log out/in when logged in/out
This commit is contained in:
@@ -52,12 +52,14 @@ def show_notification(stdscr, message):
|
|||||||
for index, line in enumerate(message, start=1):
|
for index, line in enumerate(message, start=1):
|
||||||
window.addstr(index, 1, line)
|
window.addstr(index, 1, line)
|
||||||
window.refresh()
|
window.refresh()
|
||||||
stdscr.getch()
|
ch = stdscr.getch()
|
||||||
|
|
||||||
window.clear()
|
window.clear()
|
||||||
window = None
|
window = None
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
|
return ch
|
||||||
|
|
||||||
|
|
||||||
def show_help(stdscr):
|
def show_help(stdscr):
|
||||||
"""
|
"""
|
||||||
|
|||||||
55
rtv/page.py
55
rtv/page.py
@@ -229,34 +229,41 @@ class BasePage(object):
|
|||||||
|
|
||||||
@BaseController.register('u')
|
@BaseController.register('u')
|
||||||
def login(self):
|
def login(self):
|
||||||
username = self.prompt_input('Enter username: ')
|
"""
|
||||||
password = self.prompt_input('Enter password: ', hide=True)
|
Prompt to log out if logged in.
|
||||||
|
Prompt to log in if looged out.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.reddit.is_logged_in():
|
||||||
|
ch = show_notification(self.stdscr, ["Log out? (y/N)"])
|
||||||
|
|
||||||
|
if ch == 121: # 'y'
|
||||||
|
self.reddit.clear_authentication()
|
||||||
|
show_notification(self.stdscr,
|
||||||
|
['Logged out'])
|
||||||
|
else:
|
||||||
|
curses.flash()
|
||||||
|
|
||||||
if username == '' or username is None:
|
|
||||||
self.reddit.clear_authentication()
|
|
||||||
show_notification(self.stdscr,
|
|
||||||
['Logged out'])
|
|
||||||
return
|
|
||||||
elif password == '' or password is None:
|
|
||||||
curses.flash()
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
curses.endwin()
|
|
||||||
print('Connecting...')
|
|
||||||
_reddit = praw.Reddit(user_agent=AGENT)
|
|
||||||
_reddit.login(username, password)
|
|
||||||
curses.doupdate()
|
|
||||||
except praw.errors.InvalidUserPass:
|
|
||||||
show_notification(self.stdscr,
|
|
||||||
['Invalid password for username: {}'.format(username)])
|
|
||||||
else:
|
else:
|
||||||
self.reddit.login(username, password)
|
username = self.prompt_input('Enter username: ')
|
||||||
show_notification(self.stdscr,
|
password = self.prompt_input('Enter password: ', hide=True)
|
||||||
['Successfully logged in as: {}'.format(username)])
|
|
||||||
|
if (username == '' or username is None) \
|
||||||
|
or (password == '' or password is None):
|
||||||
|
curses.flash()
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.reddit.login(username, password)
|
||||||
|
except praw.errors.InvalidUserPass:
|
||||||
|
show_notification(self.stdscr,
|
||||||
|
['Invalid password for username: {}'.format(username)])
|
||||||
|
else:
|
||||||
|
show_notification(self.stdscr,
|
||||||
|
['Successfully logged in as: {}'.format(username)])
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def prompt_input(self, prompt, hide=False):
|
def prompt_input(self, prompt, hide=False):
|
||||||
"""Prompt the user for input"""
|
"""Prompt the user for input"""
|
||||||
attr = curses.A_BOLD | Color.CYAN
|
attr = curses.A_BOLD | Color.CYAN
|
||||||
|
|||||||
Reference in New Issue
Block a user