summaryrefslogtreecommitdiff
path: root/src/leap/gui/firstrun/login.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-11-13 00:14:53 +0900
committerkali <kali@leap.se>2012-11-13 00:14:53 +0900
commit971c5e2217d17f4dab68336c9d8f562ca63fc84b (patch)
tree5c7f3c653f7b41df77171ebbf09a617011cdaaac /src/leap/gui/firstrun/login.py
parent72f3ef94f0d7deffa9adfba6bde57ae3d9c8d165 (diff)
check credentials on login branch
plus fix repaint on populateErrors on login page, should refactor to ToBeValidated class or something similar, with the other paintEvent functions that implement the painting of errors coming from the "next" validating page.
Diffstat (limited to 'src/leap/gui/firstrun/login.py')
-rw-r--r--src/leap/gui/firstrun/login.py118
1 files changed, 89 insertions, 29 deletions
diff --git a/src/leap/gui/firstrun/login.py b/src/leap/gui/firstrun/login.py
index ae4b23c6..4271c774 100644
--- a/src/leap/gui/firstrun/login.py
+++ b/src/leap/gui/firstrun/login.py
@@ -4,7 +4,7 @@ LogIn Page, used inf First Run Wizard
from PyQt4 import QtCore
from PyQt4 import QtGui
-import requests
+#import requests
from leap.gui.firstrun.mixins import UserFormMixIn
@@ -18,6 +18,7 @@ class LogInPage(QtGui.QWizardPage, UserFormMixIn):
self.setTitle("Log In")
self.setSubTitle("Log in with your credentials.")
+ self.current_page = "login"
self.setPixmap(
QtGui.QWizard.LogoPixmap,
@@ -68,30 +69,89 @@ class LogInPage(QtGui.QWizardPage, UserFormMixIn):
# pagewizard methods
+ #### begin possible refactor
+
+ def populateErrors(self):
+ # XXX could move this to ValidationMixin
+ # used in providerselect and register too
+
+ errors = self.wizard().get_validation_error(
+ self.current_page)
+ prev_er = getattr(self, 'prevalidation_error', None)
+ showerr = self.validationMsg.setText
+
+ if not errors and prev_er:
+ showerr(prev_er)
+ return
+
+ if errors:
+ bad_str = getattr(self, 'bad_string', None)
+ cur_str = self.userNameLineEdit.text()
+
+ if bad_str is None:
+ # first time we fall here.
+ # save the current bad_string value
+ self.bad_string = cur_str
+ showerr(errors)
+ else:
+ if prev_er:
+ showerr(prev_er)
+ return
+ # not the first time
+ if cur_str == bad_str:
+ showerr(errors)
+ else:
+ showerr('')
+
+ def cleanup_errormsg(self):
+ """
+ we reset bad_string to None
+ should be called before leaving the page
+ """
+ self.bad_string = None
+
+ def paintEvent(self, event):
+ """
+ we hook our populate errors
+ on paintEvent because we need it to catch
+ when user enters the page coming from next,
+ and initializePage does not cover that case.
+ Maybe there's a better event to hook upon.
+ """
+ super(LogInPage, self).paintEvent(event)
+ self.populateErrors()
+
+ def set_prevalidation_error(self, error):
+ self.prevalidation_error = error
+
+ #### end possible refactor
+
def nextId(self):
wizard = self.wizard()
if not wizard:
return
- if wizard.is_provider_setup is True:
- next_ = 'connecting'
if wizard.is_provider_setup is False:
- next_ = 'providersetup'
+ next_ = 'providersetupvalidation'
+ if wizard.is_provider_setup is True:
+ # XXX bad name, ok, gonna change that
+ next_ = 'signupvalidation'
return wizard.get_page_index(next_)
def initializePage(self):
+ super(LogInPage, self).initializePage()
self.userNameLineEdit.setText('username@provider.example.org')
self.userNameLineEdit.cursorPositionChanged.connect(
self.onUserNameEdit)
self.initial_username_sample = True
def validatePage(self):
- wizard = self.wizard()
- eipconfigchecker = wizard.eipconfigchecker()
+ #wizard = self.wizard()
+ #eipconfigchecker = wizard.eipconfigchecker()
full_username = self.userNameLineEdit.text()
password = self.userPasswordLineEdit.text()
if full_username.count('@') != 1:
- self.set_validation_status(
+ self.set_prevalidation_error(
"Username must be in the username@provider form.")
return False
@@ -100,33 +160,33 @@ class LogInPage(QtGui.QWizardPage, UserFormMixIn):
self.setField('login_userName', username)
self.setField('login_userPassword', password)
+ ####################################################
+ # Validation logic:
+ # move to provider setup page
+ ####################################################
# Able to contact domain?
# can get definition?
# two-by-one
- try:
- eipconfigchecker.fetch_definition(domain=domain)
-
+ #try:
+ #eipconfigchecker.fetch_definition(domain=domain)
+#
# we're using requests here for all
# the possible error cases that it catches.
- except requests.exceptions.ConnectionError as exc:
- self.set_validation_status(exc.message[1])
- return False
- except requests.exceptions.HTTPError as exc:
- self.set_validation_status(exc.message)
- return False
- wizard.set_providerconfig(
- eipconfigchecker.defaultprovider.config)
-
- # XXX validate user? or we leave that for later?
- # I think the best thing to do for that is
- # continue to provider setup page, and if
- # we catch authentication error there, redirect
- # again to this page (by clicking "next" to
- # come here).
- # Rationale is that we need to verify server certs
- # and so on.
-
- # mark that we came from login page.
+ #except requests.exceptions.ConnectionError as exc:
+ #self.set_validation_status(exc.message[1])
+ #return False
+ #except requests.exceptions.HTTPError as exc:
+ #self.set_validation_status(exc.message)
+ #return False
+ #wizard.set_providerconfig(
+ #eipconfigchecker.defaultprovider.config)
+ ####################################################
+
+ # XXX I think this is not needed
+ # since we're also checking for the is_signup field.
self.wizard().from_login = True
+ # some cleanup before we leave the page
+ self.cleanup_errormsg()
+
return True