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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
"""
Provider Setup Validation Page,
used if First Run Wizard
"""
import logging
import json
import socket
import time
from PyQt4 import QtGui
import requests
from leap.gui.progress import ValidationPage
from leap.base import auth
from leap.gui.constants import APP_LOGO
logger = logging.getLogger(__name__)
class RegisterUserValidationPage(ValidationPage):
def __init__(self, parent=None):
super(RegisterUserValidationPage, self).__init__(parent)
self.setTitle("User Creation")
self.setSubTitle(
"Registering account with provider.")
self.setPixmap(
QtGui.QWizard.LogoPixmap,
QtGui.QPixmap(APP_LOGO))
def _do_checks(self, update_signal=None):
"""
executes actual checks in a separate thread
we initialize the srp protocol register
and try to register user.
"""
print 'register user checks'
wizard = self.wizard()
domain = self.field('provider_domain')
username = self.field('userName')
password = self.field('userPassword')
# XXX use pause_for_user from providerinfo
update_signal.emit("head_sentinel", 0)
update_signal.emit("registering with provider", 40)
time.sleep(0.5)
update_signal.emit("registering 2", 60)
time.sleep(1)
update_signal.emit("end_sentinel", 100)
time.sleep(0.5)
return
if wizard and wizard.debug_server:
# We're debugging
dbgsrv = wizard.debug_server
schema = dbgsrv.scheme
netloc = dbgsrv.netloc
port = None
netloc_split = netloc.split(':')
if len(netloc_split) > 1:
provider, port = netloc_split
else:
provider = netloc
signup = auth.LeapSRPRegister(
scheme=schema,
provider=provider,
port=port)
else:
# this is the real thing
signup = auth.LeapSRPRegister(
# XXX FIXME FIXME FIXME FIXME
# XXX FIXME 0 Force HTTPS !!!
# XXX FIXME FIXME FIXME FIXME
#schema="https",
schema="http",
provider=domain)
try:
ok, req = signup.register_user(username, password)
except socket.timeout:
self.set_validation_status(
"Error connecting to provider (timeout)")
return False
except requests.exceptions.ConnectionError as exc:
logger.error(exc)
self.set_validation_status(
"Error connecting to provider "
"(connection error)")
return False
if ok:
return True
# something went wrong.
# not registered, let's catch what.
# get timeout
# ...
if req.status_code == 500:
self.set_validation_status(
"Error during registration (500)")
return False
if req.status_code == 404:
self.set_validation_status(
"Error during registration (404)")
return False
validation_msgs = json.loads(req.content)
logger.debug('validation errors: %s' % validation_msgs)
errors = validation_msgs.get('errors', None)
if errors and errors.get('login', None):
# XXX this sometimes catch the blank username
# but we're not allowing that (soon)
self.set_validation_status(
'Username not available.')
else:
self.set_validation_status(
"Error during sign up")
return False
def _do_validation(self):
"""
called after _do_checks has finished
(connected to checker thread finished signal)
"""
wizard = self.wizard()
if self.errors:
print 'going back with errors'
wizard.set_validation_error(
'signup', 'that name is taken')
self.go_back()
else:
print 'going next'
self.go_next()
def nextId(self):
wizard = self.wizard()
if not wizard:
return
return wizard.get_page_index('connecting')
|