def init_session():
email = xbmcgui.Dialog().input(translation(30001), addon.getSetting('email'), xbmcgui.INPUT_ALPHANUM)
if email == '': return False
addon.setSetting('email', email)
clave = xbmcgui.Dialog().input(translation(30002), '', xbmcgui.INPUT_ALPHANUM, xbmcgui.ALPHANUM_HIDE_INPUT)
if clave == '': return False
url = '{0}/auth/login'.format(ID_URL)
response = requests.post(url, {'email': email, 'password': clave}, headers=get_headers())
data, errmsg = decode_json(response)
if data:
addon.setSetting('token', data['token'])
return True
else:
xbmcgui.Dialog().ok(translation(30003), errmsg)
return False
python类ALPHANUM_HIDE_INPUT的实例源码
def login_dialog():
username = dialog.input(u'???:', type=xbmcgui.INPUT_ALPHANUM)
password = dialog.input(u'??:', type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)
if username and password:
cookie,tokens = get_auth.run(username,password)
if tokens:
save_user_info(username,password,cookie,tokens)
homemenu = plugin.get_storage('homemenu')
homemenu.clear()
dialog.ok('',u'????', u'???????????')
items = [{'label': u'<< ????', 'path': plugin.url_for('main_menu')}]
return plugin.finish(items, update_listing=True)
else:
dialog.ok('Error',u'??????????')
return None
def show_password_dialog(self):
"""
Shows password input
:returns: string - Password characters
"""
dlg = xbmcgui.Dialog()
return dlg.input(
self.utils.get_local_string(string_id=32004),
type=xbmcgui.INPUT_ALPHANUM,
option=xbmcgui.ALPHANUM_HIDE_INPUT)
def show_password_dialog(self):
"""
Asks the user for its Netflix password
:returns: str - Netflix password
"""
dlg = xbmcgui.Dialog()
dialog = dlg.input(
heading=self.get_local_string(string_id=30004),
type=xbmcgui.INPUT_ALPHANUM,
option=xbmcgui.ALPHANUM_HIDE_INPUT)
return dialog
def login():
username = addon.getSetting('username')
password = addon.getSetting('password')
subscription_type = [SubscriptionType.hifi, SubscriptionType.premium][int('0' + addon.getSetting('subscription_type'))]
if not username or not password:
# Ask for username/password
dialog = xbmcgui.Dialog()
username = dialog.input(_T(30008), username)
if not username:
return
password = dialog.input(_T(30009), option=xbmcgui.ALPHANUM_HIDE_INPUT)
if not password:
return
selected = dialog.select(_T(30010), [SubscriptionType.hifi, SubscriptionType.premium])
if selected < 0:
return
subscription_type = [SubscriptionType.hifi, SubscriptionType.premium][selected]
ok = session.login(username, password, subscription_type)
if ok and (not addon.getSetting('username') or not addon.getSetting('password')):
# Ask about remembering username/password
dialog = xbmcgui.Dialog()
if dialog.yesno(plugin.name, _T(30209)):
addon.setSetting('username', username)
addon.setSetting('password', password)
else:
addon.setSetting('password', '')
if not ok:
xbmcgui.Dialog().notification(plugin.name, _T(30253) , icon=xbmcgui.NOTIFICATION_ERROR)
xbmc.executebuiltin('Container.Refresh()')
def login(self):
if self.username == '':
dialog = xbmcgui.Dialog()
self.username = dialog.input(self.localized(30202), type=xbmcgui.INPUT_ALPHANUM)
if self.username != '':
self.addon.setSetting(id='username', value=self.username)
else:
sys.exit()
if self.password == '':
dialog = xbmcgui.Dialog()
self.password = dialog.input(self.localized(30203), type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)
if self.password != '':
self.addon.setSetting(id='password', value=self.password)
else:
sys.exit()
if self.username != '' and self.password != '':
url = self.api_url + '/ssocookie'
headers = {"Accept": "*/*",
"Content-type": "application/x-www-form-urlencoded",
"Origin": "https://id.sonyentertainmentnetwork.com",
"Accept-Language": "en-US,en;q=0.8",
"Accept-Encoding": "deflate",
"User-Agent": self.ua_android_tv,
"X-Requested-With": "com.snei.vue.atv",
"Connection": "Keep-Alive"
}
payload = 'authentication_type=password&username='+urllib.quote_plus(self.username)+'&password='+urllib.quote_plus(self.password)+'&client_id='+self.andriod_tv_client_id
r = requests.post(url, headers=headers, cookies=self.load_cookies(), data=payload, verify=self.verify)
json_source = r.json()
self.save_cookies(r.cookies)
if 'npsso' in json_source:
npsso = json_source['npsso']
self.addon.setSetting(id='npsso', value=npsso)
elif 'authentication_type' in json_source:
if json_source['authentication_type'] == 'two_step':
ticket_uuid = json_source['ticket_uuid']
self.two_step_verification(ticket_uuid)
elif 'error_description' in json_source:
msg = json_source['error_description']
self.notification_msg(self.localized(30200), msg)
sys.exit()
else:
# Something went wrong during login
self.notification_msg(self.localized(30200), self.localized(30201))
sys.exit()
def wizard():
addon = xbmcaddon.Addon("service.vpn.manager")
addon_name = addon.getAddonInfo("name")
# Indicate the wizard has been run, regardless of if it is to avoid asking again
addon.setSetting("vpn_wizard_run", "true")
# Wizard or settings?
if xbmcgui.Dialog().yesno(addon_name, "No primary VPN connection has been set up. Would you like to do this using the set up wizard or using the Settings dialog?", "", "", "Settings", "Wizard"):
# Select the VPN provider
provider_list = list(provider_display)
provider_list.sort()
vpn = xbmcgui.Dialog().select("Select your VPN provider.", provider_list)
vpn = provider_display.index(provider_list[vpn])
vpn_provider = provider_display[vpn]
success = True
# If User Defined VPN then offer to run the wizard
if isUserDefined(vpn_provider):
success = importWizard()
if success:
# Get the username and password
vpn_username = ""
vpn_password = ""
if usesPassAuth(vpn_provider):
vpn_username = xbmcgui.Dialog().input("Enter your " + vpn_provider + " username.", type=xbmcgui.INPUT_ALPHANUM)
if not vpn_username == "":
vpn_password = xbmcgui.Dialog().input("Enter your " + vpn_provider + " password.", type=xbmcgui.INPUT_ALPHANUM, option=xbmcgui.ALPHANUM_HIDE_INPUT)
# Try and connect if we've gotten all the data
if (not usesPassAuth(vpn_provider)) or (not vpn_password == ""):
addon.setSetting("vpn_provider", vpn_provider)
addon.setSetting("vpn_username", vpn_username)
addon.setSetting("vpn_password", vpn_password)
connectVPN("1", vpn_provider)
# Need to reinitialise addon here for some reason...
addon = xbmcaddon.Addon("service.vpn.manager")
if connectionValidated(addon):
xbmcgui.Dialog().ok(addon_name, "Successfully connected to " + vpn_provider + ". Use the Settings dialog to add additional VPN connections. You can also define add-on filters to dynamically change the VPN connection being used.")
else:
xbmcgui.Dialog().ok(addon_name, "Could not connect to " + vpn_provider + ". Use the Settings dialog to correct any issues and try connecting again.")
else:
xbmcgui.Dialog().ok(addon_name, "You need to enter both a VPN username and password to connect.")
else:
xbmcgui.Dialog().ok(addon_name, "There was a problem setting up the User Defined provider. Fix any issues and run the wizard again from the VPN Configuration tab.")