def _validate(self): """Perform input validation.""" correct_mail = is_correct_email( compat.text_type(self.ui.email_edit.text())) correct_password = len( compat.text_type(self.ui.password_edit.text())) > 0 enabled = correct_mail and correct_password self.ui.sign_in_button.setEnabled(enabled)
def _validate(self): """Perform input validation.""" correct_mail = is_correct_email( compat.text_type(self.ui.email_edit.text())) correct_password = len(compat.text_type( self.ui.password_edit.text())) > 0 enabled = correct_mail and correct_password self.ui.sign_in_button.setEnabled(enabled)
def password_check_match(line_edit, line_edit_confirm, assistance): """Check if passwords match, otherwise show a message.""" password_assistance(line_edit, assistance) label_text = compat.text_type(assistance.text()) text1 = compat.text_type(line_edit.text()) text2 = compat.text_type(line_edit_confirm.text()) if text1 != text2: label_text += "<br>" + BAD % PASSWORD_MATCH assistance.setText(label_text)
def confirm_email_assistance(self): """Show help for the confirm email field.""" text1 = compat.text_type(self.ui.email_edit.text()) text2 = compat.text_type(self.ui.confirm_email_edit.text()) if text1 != text2: self.set_error_message(self.ui.confirm_email_assistance, EMAIL_MATCH) common.check_as_invalid(self.ui.confirm_email_edit) else: self.ui.confirm_email_assistance.setVisible(False) common.check_as_valid(self.ui.confirm_email_edit)
def _validate(self): """Enable the submit button if data is valid.""" enabled = True code = compat.text_type(self.ui.reset_code_line_edit.text()) password = compat.text_type(self.ui.password_line_edit.text()) confirm_password = compat.text_type( self.ui.confirm_password_line_edit.text()) if not is_min_required_password(password): enabled = False elif not self.is_correct_password_confirmation(confirm_password): enabled = False elif not code: enabled = False self.ui.reset_password_button.setEnabled(enabled)
def set_new_password(self): """Request a new password to be set.""" self.hide_error() email = compat.text_type( self.wizard().forgotten.ui.email_line_edit.text()) code = compat.text_type(self.ui.reset_code_line_edit.text()) password = compat.text_type(self.ui.password_line_edit.text()) logger.info('Setting new password for %r and email %r with code %r', self.app_name, email, code) args = (self.app_name, email, code, password) f = self.backend.set_new_password error_handler = partial(self._handle_error, f, self.on_password_change_error) self.show_overlay() f(*args, reply_handler=NO_OP, error_handler=error_handler)
def _on_save_clicked(self, *args): """Save the new credentials.""" username = compat.text_type( self.ui.username_entry.text()).encode('utf8') password = compat.text_type( self.ui.password_entry.text()).encode('utf8') creds = dict(username=username, password=password) try: logger.debug('Save credentials as for domain %s.', self.domain) yield self.keyring.set_credentials(self.domain, creds) except Exception as e: logger.exception('Could not set credentials: %s', e) self.done(EXCEPTION_RAISED) logger.debug('Stored creds') self.done(USER_SUCCESS)
def on_logged_in(self, app_name, result): """We managed to log in.""" logger.info('Logged in for %s', app_name) self.hide_overlay() email = compat.text_type(self.ui.email_edit.text()) logger.debug('About to emit userLoggedIn signal with: (%s).', email) self.userLoggedIn.emit(email)
def password_assistance(line_edit, assistance, icon_type=BAD): """Show help for the password field.""" text1 = compat.text_type(line_edit.text()) label_text = [ "<b>%s</b>" % PASSWORD_MUST_CONTAIN, ] if len(text1) < 8: sign = icon_type else: sign = GOOD label_text.append(sign % PASSWORD_LENGTH) if re.search('[A-Z]', text1) is None: sign = icon_type else: sign = GOOD label_text.append(sign % PASSWORD_UPPER) if re.search('[\d+]', text1) is None: sign = icon_type else: sign = GOOD label_text.append(sign % PASSWORD_DIGIT) assistance.setText("<br>".join(label_text))
def main(**kwargs): """Start the QT mainloop and open the main window.""" if os.environ.get("TESTABILITY", False) and "-testability" not in sys.argv: sys.argv.append("-testability") app = QtGui.QApplication(sys.argv) source.main(app) data = [] for qss_name in (PLATFORM_QSS, ":/stylesheet.qss"): qss = QtCore.QResource(qss_name) data.append(compat.text_type(qss.data())) app.setStyleSheet("\n".join(data)) # Fix the string that contains unicode chars. for key in kwargs: value = kwargs[key] if isinstance(value, compat.binary_type): kwargs[key] = value.decode("utf-8") close_callback = lambda: source.main_quit(app) ui = UbuntuSSOClientGUI(close_callback=close_callback, **kwargs) style = QtGui.QStyle.alignedRect( QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter, ui.size(), app.desktop().availableGeometry() ) ui.setGeometry(style) app = QtGui.QApplication.instance() app.setWindowIcon(QtGui.QIcon.fromTheme("ubuntuone")) ui.show() if sys.platform == "darwin": ui.raise_() source.main_start(app)
def on_password_changed(self, app_name, email): """Let user know that the password was changed.""" logger.info('ResetPasswordPage.on_password_changed for %s, email: %s', app_name, email) self.hide_overlay() email = compat.text_type( self.wizard().forgotten.ui.email_line_edit.text()) self.passwordChanged.emit(email)
def login(self): """Perform the login using the self.backend.""" # grab the data from the view and call the backend email = compat.text_type(self.ui.email_edit.text()) logger.info('CurrentUserSignInPage.login for: %s', email) password = compat.text_type(self.ui.password_edit.text()) args = (self.app_name, email, password) if self.ping_url: f = self.backend.login_and_ping args = args + (self.ping_url, ) else: f = self.backend.login self.hide_error() self.show_overlay() error_handler = partial(self._handle_error, f, self.on_login_error) f(*args, reply_handler=NO_OP, error_handler=error_handler)
def login(self): """Perform the login using the self.backend.""" # grab the data from the view and call the backend email = compat.text_type(self.ui.email_edit.text()) logger.info('CurrentUserSignInPage.login for: %s', email) password = compat.text_type(self.ui.password_edit.text()) args = (self.app_name, email, password) if self.ping_url: f = self.backend.login_and_ping args = args + (self.ping_url,) else: f = self.backend.login self.hide_error() self.show_overlay() error_handler = partial(self._handle_error, f, self.on_login_error) f(*args, reply_handler=NO_OP, error_handler=error_handler)
def set_next_validation(self): """Set the validation as the next page.""" logger.debug("SetUpAccountPage.set_next_validation") email = compat.text_type(self.ui.email_edit.text()) password = compat.text_type(self.ui.password_edit.text()) name = compat.text_type(self.ui.name_edit.text()) captcha_id = self.captcha_id captcha_solution = compat.text_type(self.ui.captcha_solution_edit.text()) # validate the current info of the form, try to perform the action # to register the user, and then move foward if self.validate_form(): self.show_overlay() self.hide_error() args = (self.app_name, email, password, name, captcha_id, captcha_solution) f = self.backend.register_user error_handler = partial(self._handle_error, f, self.on_user_registration_error) f(*args, reply_handler=NO_OP, error_handler=error_handler)
def email_assistance(self): """Show help for the email field.""" text = compat.text_type(self.ui.email_edit.text()) if not is_correct_email(text): self.set_error_message(self.ui.email_assistance, INVALID_EMAIL) common.check_as_invalid(self.ui.email_edit) else: self.ui.email_assistance.setVisible(False) common.check_as_valid(self.ui.email_edit)
def name_assistance(self): """Show help for the name field.""" text = compat.text_type(self.ui.name_edit.text()) if not text.strip(): self.set_error_message(self.ui.name_assistance, EMPTY_NAME) common.check_as_invalid(self.ui.name_edit) else: self.ui.name_assistance.setVisible(False) common.check_as_valid(self.ui.name_edit)
def _move_to_email_verification_page(self, email): """Move to the email verification page wizard.""" logger.debug('Moving to EmailVerificationPage from: %s', self.currentPage()) self._next_id = self.email_verification_page_id self.email_verification.email = compat.text_type(email) self.email_verification.password = self.currentPage().password self.next() self._next_id = -1
def set_next_validation(self): """Set the validation as the next page.""" logger.debug('SetUpAccountPage.set_next_validation') email = compat.text_type(self.ui.email_edit.text()) password = compat.text_type(self.ui.password_edit.text()) name = compat.text_type(self.ui.name_edit.text()) captcha_id = self.captcha_id captcha_solution = compat.text_type( self.ui.captcha_solution_edit.text()) # validate the current info of the form, try to perform the action # to register the user, and then move foward if self.validate_form(): self.show_overlay() self.hide_error() args = (self.app_name, email, password, name, captcha_id, captcha_solution) f = self.backend.register_user error_handler = partial(self._handle_error, f, self.on_user_registration_error) f(*args, reply_handler=NO_OP, error_handler=error_handler)
def validate_form(self): """Validate the info of the form and return an error.""" logger.debug("SetUpAccountPage.validate_form") name = compat.text_type(self.ui.name_edit.text()).strip() email = compat.text_type(self.ui.email_edit.text()) confirm_email = compat.text_type(self.ui.confirm_email_edit.text()) password = compat.text_type(self.ui.password_edit.text()) confirm_password = compat.text_type(self.ui.confirm_password_edit.text()) captcha_solution = compat.text_type(self.ui.captcha_solution_edit.text()) condition = True messages = [] if not name: condition = False self.set_error_message(self.ui.name_assistance, NAME_INVALID) if not is_correct_email(email): condition = False self.set_error_message(self.ui.email_assistance, EMAIL_INVALID) if email != confirm_email: condition = False self.set_error_message(self.ui.confirm_email_assistance, EMAIL_MISMATCH) if not is_min_required_password(password): messages.append(PASSWORD_TOO_WEAK) if password != confirm_password: messages.append(PASSWORD_MISMATCH) if not captcha_solution: messages.append(CAPTCHA_REQUIRED_ERROR) if len(messages) > 0: condition = False self.show_error("\n".join(messages)) return condition
def validate_form(self): """Validate the info of the form and return an error.""" logger.debug('SetUpAccountPage.validate_form') name = compat.text_type(self.ui.name_edit.text()).strip() email = compat.text_type(self.ui.email_edit.text()) confirm_email = compat.text_type(self.ui.confirm_email_edit.text()) password = compat.text_type(self.ui.password_edit.text()) confirm_password = compat.text_type( self.ui.confirm_password_edit.text()) captcha_solution = compat.text_type( self.ui.captcha_solution_edit.text()) condition = True messages = [] if not name: condition = False self.set_error_message(self.ui.name_assistance, NAME_INVALID) if not is_correct_email(email): condition = False self.set_error_message(self.ui.email_assistance, EMAIL_INVALID) if email != confirm_email: condition = False self.set_error_message(self.ui.confirm_email_assistance, EMAIL_MISMATCH) if not is_min_required_password(password): messages.append(PASSWORD_TOO_WEAK) if password != confirm_password: messages.append(PASSWORD_MISMATCH) if not captcha_solution: messages.append(CAPTCHA_REQUIRED_ERROR) if len(messages) > 0: condition = False self.show_error('\n'.join(messages)) return condition
def _enable_setup_button(self): """Only enable the setup button if the form is valid.""" name = compat.text_type(self.ui.name_edit.text()).strip() email = compat.text_type(self.ui.email_edit.text()) confirm_email = compat.text_type(self.ui.confirm_email_edit.text()) password = compat.text_type(self.ui.password_edit.text()) confirm_password = compat.text_type(self.ui.confirm_password_edit.text()) captcha_solution = compat.text_type(self.ui.captcha_solution_edit.text()) # Check for len(name) > 0 to ensure that a bool is assigned to enabled if not self.terms_checkbox.isVisible(): checkbox_terms = True else: checkbox_terms = self.terms_checkbox.isChecked() enabled = ( checkbox_terms and len(captcha_solution) > 0 and is_min_required_password(password) and password == confirm_password and is_correct_email(email) and email == confirm_email and len(name) > 0 ) self.set_up_button.setEnabled(enabled)
def _show_ui(self, login_only): """Show the UI and wait for it to finish. Upon analyzing returning code from the UI process, emit proper signals to the caller. The caller can specify a preference for the UI, but if the preferred one is not available, the service will try to open any available UI. If no GUI is available, GUINotAvailableError will be raised. """ guis = (self.ui_executable, UI_EXECUTABLE_QT) for gui_exe_name in guis: try: args = get_bin_cmd(gui_exe_name) except OSError: logger.error('The given UI %r does not exist.', gui_exe_name) else: break else: raise GUINotAvailableError('Can not find a GUI to present to the ' 'user (tried with %r). Aborting.' % repr(guis)) for arg in ('app_name', 'help_text', 'ping_url', 'policy_url', 'tc_url', 'window_id'): value = getattr(self, arg) if value: args.append('--%s' % arg) if not isinstance(value, compat.basestring): value = compat.text_type(value) args.append(value) if login_only: args.append('--login_only') return_code = yield runner.spawn_program(args) logger.info('_show_ui: received from the ui return code %r.', return_code) credentials = None if return_code == USER_SUCCESS: credentials = yield self.find_credentials() elif return_code == USER_CANCELLATION: raise UserCancellationError() else: raise CredentialsError(return_code) defer.returnValue(credentials)
def validate_email(self): """Call the next action.""" logger.debug('EmailVerificationController.validate_email for: %s', self.email) code = compat.text_type(self.ui.verification_code_edit.text()) args = (self.app_name, self.email, self.password, code) self.hide_error() self.show_overlay() if self.ping_url: f = self.backend.validate_email_and_ping args = args + (self.ping_url,) else: f = self.backend.validate_email logger.info('Calling validate_email with email %r, password <hidden>, ' 'app_name %r and email_token %r.', self.email, self.app_name, code) error_handler = partial(self._handle_error, f, self.on_email_validation_error) f(*args, reply_handler=NO_OP, error_handler=error_handler)
def validate_email(self): """Call the next action.""" logger.debug('EmailVerificationController.validate_email for: %s', self.email) code = compat.text_type(self.ui.verification_code_edit.text()) args = (self.app_name, self.email, self.password, code) self.hide_error() self.show_overlay() if self.ping_url: f = self.backend.validate_email_and_ping args = args + (self.ping_url, ) else: f = self.backend.validate_email logger.info( 'Calling validate_email with email %r, password <hidden>, ' 'app_name %r and email_token %r.', self.email, self.app_name, code) error_handler = partial(self._handle_error, f, self.on_email_validation_error) f(*args, reply_handler=NO_OP, error_handler=error_handler)
def main(**kwargs): """Start the QT mainloop and open the main window.""" if os.environ.get('TESTABILITY', False) and \ '-testability' not in sys.argv: sys.argv.append('-testability') app = QtGui.QApplication(sys.argv) source.main(app) data = [] for qss_name in (PLATFORM_QSS, ":/stylesheet.qss"): qss = QtCore.QResource(qss_name) data.append(compat.text_type(qss.data())) app.setStyleSheet('\n'.join(data)) # Fix the string that contains unicode chars. for key in kwargs: value = kwargs[key] if isinstance(value, compat.binary_type): kwargs[key] = value.decode('utf-8') close_callback = lambda: source.main_quit(app) ui = UbuntuSSOClientGUI(close_callback=close_callback, **kwargs) style = QtGui.QStyle.alignedRect(QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter, ui.size(), app.desktop().availableGeometry()) ui.setGeometry(style) app = QtGui.QApplication.instance() app.setWindowIcon(QtGui.QIcon.fromTheme("ubuntuone")) ui.show() if sys.platform == 'darwin': ui.raise_() source.main_start(app)
def password_assistance(line_edit, assistance, icon_type=BAD): """Show help for the password field.""" text1 = compat.text_type(line_edit.text()) label_text = ["<b>%s</b>" % PASSWORD_MUST_CONTAIN, ] if len(text1) < 8: sign = icon_type else: sign = GOOD label_text.append(sign % PASSWORD_LENGTH) if re.search('[A-Z]', text1) is None: sign = icon_type else: sign = GOOD label_text.append(sign % PASSWORD_UPPER) if re.search('[\d+]', text1) is None: sign = icon_type else: sign = GOOD label_text.append(sign % PASSWORD_DIGIT) assistance.setText("<br>".join(label_text))
def _enable_setup_button(self): """Only enable the setup button if the form is valid.""" name = compat.text_type(self.ui.name_edit.text()).strip() email = compat.text_type(self.ui.email_edit.text()) confirm_email = compat.text_type(self.ui.confirm_email_edit.text()) password = compat.text_type(self.ui.password_edit.text()) confirm_password = compat.text_type( self.ui.confirm_password_edit.text()) captcha_solution = compat.text_type( self.ui.captcha_solution_edit.text()) # Check for len(name) > 0 to ensure that a bool is assigned to enabled if not self.terms_checkbox.isVisible(): checkbox_terms = True else: checkbox_terms = self.terms_checkbox.isChecked() enabled = checkbox_terms and \ len(captcha_solution) > 0 and \ is_min_required_password(password) and \ password == confirm_password and is_correct_email(email) and \ email == confirm_email and len(name) > 0 self.set_up_button.setEnabled(enabled)
def _validate(self): """Validate that we have an email.""" email = compat.text_type(self.ui.email_line_edit.text()) self.ui.send_button.setEnabled(is_correct_email(email))
def on_user_not_validated(self, app_name, email): """Show the validate email page.""" self.hide_overlay() email = compat.text_type(self.ui.email_edit.text()) self.userNotValidated.emit(email)
def password(self): """Return the content of the password edit.""" return compat.text_type(self.ui.password_edit.text())
def on_user_registered(self, app_name, email): """Execute when the user did register.""" self.hide_overlay() email = compat.text_type(self.ui.email_edit.text()) self.userRegistered.emit(email)
def is_correct_password_confirmation(self, password): """Return if the password is correct.""" return compat.text_type(self.ui.password_line_edit.text()) == password
def is_correct_email_confirmation(self, email_address): """Return that the email is the same.""" return compat.text_type(self.ui.email_edit.text()) == email_address
def email_address(self): """Return the email address provided by the user.""" return compat.text_type(self.ui.email_line_edit.text())
def is_correct_password_confirmation(self, password): """Return that the passwords are correct.""" return compat.text_type(self.ui.password_edit.text()) == password