Exemplo n.º 1
0
 def __init__(self, proxy):
     """Initiate the Login object."""
     self.processor = Account()
     self.proxy = proxy
Exemplo n.º 2
0
 def __init__(self, proxy):
     """Initiate the Login object."""
     self.processor = Account()
     self.proxy = proxy
Exemplo n.º 3
0
class SSOLogin(object):
    """Login thru the Single Sign On service."""

    def __init__(self, proxy):
        """Initiate the Login object."""
        self.processor = Account()
        self.proxy = proxy

    @defer.inlineCallbacks
    def _process_new_token(self, app_name, email, credentials, ping_url):
        """Process a new set of credentials for 'email'."""
        if ping_url:
            yield utils.ping_url(ping_url, email, credentials)
            logger.info('Url %r successfully opened!', ping_url)

        yield Keyring().set_credentials(app_name, credentials)

    @log_call(logger.debug)
    def CaptchaGenerated(self, app_name, result):
        """Signal thrown after the captcha is generated."""
        self.proxy.CaptchaGenerated(app_name, result)

    @log_call(logger.debug)
    def CaptchaGenerationError(self, app_name, error):
        """Signal thrown when there's a problem generating the captcha."""
        error_dict = except_to_errdict(error)
        self.proxy.CaptchaGenerationError(app_name, error_dict)

    @defer.inlineCallbacks
    def generate_captcha(self, app_name, filename):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.generate_captcha(filename)
            self.CaptchaGenerated(app_name, result)
        except Exception as e:
            self.CaptchaGenerationError(app_name, e)

    @log_call(logger.debug)
    def UserRegistered(self, app_name, result):
        """Signal thrown when the user is registered."""
        self.proxy.UserRegistered(app_name, result)

    @log_call(logger.debug)
    def UserRegistrationError(self, app_name, error):
        """Signal thrown when there's a problem registering the user."""
        error_dict = except_to_errdict(error)
        self.proxy.UserRegistrationError(app_name, error_dict)

    @defer.inlineCallbacks
    def register_user(self, app_name, email, password, name, captcha_id,
                      captcha_solution):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.register_user(email, password, name,
                                                captcha_id, captcha_solution)
            self.UserRegistered(app_name, result)
        except Exception as e:
            self.UserRegistrationError(app_name, e)

    @log_call(logger.debug)
    def LoggedIn(self, app_name, result):
        """Signal thrown when the user is logged in."""
        self.proxy.LoggedIn(app_name, result)

    @log_call(logger.debug)
    def LoginError(self, app_name, error):
        """Signal thrown when there is a problem in the login."""
        error_dict = except_to_errdict(error)
        self.proxy.LoginError(app_name, error_dict)

    @log_call(logger.debug)
    def UserNotValidated(self, app_name, email):
        """Signal thrown when the user is not validated."""
        self.proxy.UserNotValidated(app_name, email)

    @defer.inlineCallbacks
    def login(self, app_name, email, password, ping_url=None):
        """Call the matching method in the processor."""
        try:
            token_name = get_token_name(app_name)
            logger.debug('login: token_name %r, email %r, password <hidden>.',
                         token_name, email)
            credentials = yield self.processor.login(email, password,
                                                     token_name)
            logger.debug('login returned not None credentials? %r.',
                         credentials is not None)
            is_validated = yield self.processor.is_validated(credentials)
            logger.debug('user is validated? %r.', is_validated)
            if is_validated:
                yield self._process_new_token(app_name, email,
                                              credentials, ping_url)
                self.LoggedIn(app_name, email)
            else:
                self.UserNotValidated(app_name, email)
        except Exception as e:
            self.LoginError(app_name, e)

    @log_call(logger.debug)
    def EmailValidated(self, app_name, result):
        """Signal thrown after the email is validated."""
        self.proxy.EmailValidated(app_name, result)

    @log_call(logger.debug)
    def EmailValidationError(self, app_name, error):
        """Signal thrown when there's a problem validating the email."""
        error_dict = except_to_errdict(error)
        self.proxy.EmailValidationError(app_name, error_dict)

    @defer.inlineCallbacks
    def validate_email(self, app_name, email, password, email_token,
                       ping_url=None):
        """Call the matching method in the processor."""
        try:
            token_name = get_token_name(app_name)
            credentials = yield self.processor.validate_email(email, password,
                                                      email_token, token_name)
            yield self._process_new_token(app_name, email,
                                          credentials, ping_url)
            self.EmailValidated(app_name, email)
        except Exception as e:
            self.EmailValidationError(app_name, e)

    @log_call(logger.debug)
    def PasswordResetTokenSent(self, app_name, result):
        """Signal thrown when the token is succesfully sent."""
        self.proxy.PasswordResetTokenSent(app_name, result)

    @log_call(logger.debug)
    def PasswordResetError(self, app_name, error):
        """Signal thrown when there's a problem sending the token."""
        error_dict = except_to_errdict(error)
        self.proxy.PasswordResetError(app_name, error_dict)

    @defer.inlineCallbacks
    def request_password_reset_token(self, app_name, email):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.request_password_reset_token(email)
            self.PasswordResetTokenSent(app_name, result)
        except Exception as e:
            self.PasswordResetError(app_name, e)

    @log_call(logger.debug)
    def PasswordChanged(self, app_name, result):
        """Signal thrown when the token is succesfully sent."""
        self.proxy.PasswordChanged(app_name, result)

    @log_call(logger.debug)
    def PasswordChangeError(self, app_name, error):
        """Signal thrown when there's a problem sending the token."""
        error_dict = except_to_errdict(error)
        self.proxy.PasswordChangeError(app_name, error_dict)

    @defer.inlineCallbacks
    def set_new_password(self, app_name, email, token, new_password):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.set_new_password(email, token,
                                                           new_password)
            self.PasswordChanged(app_name, result)
        except Exception as e:
            self.PasswordChangeError(app_name, e)
Exemplo n.º 4
0
class SSOLogin(object):
    """Login thru the Single Sign On service."""
    def __init__(self, proxy):
        """Initiate the Login object."""
        self.processor = Account()
        self.proxy = proxy

    @defer.inlineCallbacks
    def _process_new_token(self, app_name, email, credentials, ping_url):
        """Process a new set of credentials for 'email'."""
        if ping_url:
            yield utils.ping_url(ping_url, email, credentials)
            logger.info('Url %r successfully opened!', ping_url)

        yield Keyring().set_credentials(app_name, credentials)

    @log_call(logger.debug)
    def CaptchaGenerated(self, app_name, result):
        """Signal thrown after the captcha is generated."""
        self.proxy.CaptchaGenerated(app_name, result)

    @log_call(logger.debug)
    def CaptchaGenerationError(self, app_name, error):
        """Signal thrown when there's a problem generating the captcha."""
        error_dict = except_to_errdict(error)
        self.proxy.CaptchaGenerationError(app_name, error_dict)

    @defer.inlineCallbacks
    def generate_captcha(self, app_name, filename):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.generate_captcha(filename)
            self.CaptchaGenerated(app_name, result)
        except Exception as e:
            self.CaptchaGenerationError(app_name, e)

    @log_call(logger.debug)
    def UserRegistered(self, app_name, result):
        """Signal thrown when the user is registered."""
        self.proxy.UserRegistered(app_name, result)

    @log_call(logger.debug)
    def UserRegistrationError(self, app_name, error):
        """Signal thrown when there's a problem registering the user."""
        error_dict = except_to_errdict(error)
        self.proxy.UserRegistrationError(app_name, error_dict)

    @defer.inlineCallbacks
    def register_user(self, app_name, email, password, name, captcha_id,
                      captcha_solution):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.register_user(
                email, password, name, captcha_id, captcha_solution)
            self.UserRegistered(app_name, result)
        except Exception as e:
            self.UserRegistrationError(app_name, e)

    @log_call(logger.debug)
    def LoggedIn(self, app_name, result):
        """Signal thrown when the user is logged in."""
        self.proxy.LoggedIn(app_name, result)

    @log_call(logger.debug)
    def LoginError(self, app_name, error):
        """Signal thrown when there is a problem in the login."""
        error_dict = except_to_errdict(error)
        self.proxy.LoginError(app_name, error_dict)

    @log_call(logger.debug)
    def UserNotValidated(self, app_name, email):
        """Signal thrown when the user is not validated."""
        self.proxy.UserNotValidated(app_name, email)

    @defer.inlineCallbacks
    def login(self, app_name, email, password, ping_url=None):
        """Call the matching method in the processor."""
        try:
            token_name = get_token_name(app_name)
            logger.debug('login: token_name %r, email %r, password <hidden>.',
                         token_name, email)
            credentials = yield self.processor.login(email, password,
                                                     token_name)
            logger.debug('login returned not None credentials? %r.',
                         credentials is not None)
            is_validated = yield self.processor.is_validated(credentials)
            logger.debug('user is validated? %r.', is_validated)
            if is_validated:
                yield self._process_new_token(app_name, email, credentials,
                                              ping_url)
                self.LoggedIn(app_name, email)
            else:
                self.UserNotValidated(app_name, email)
        except Exception as e:
            self.LoginError(app_name, e)

    @log_call(logger.debug)
    def EmailValidated(self, app_name, result):
        """Signal thrown after the email is validated."""
        self.proxy.EmailValidated(app_name, result)

    @log_call(logger.debug)
    def EmailValidationError(self, app_name, error):
        """Signal thrown when there's a problem validating the email."""
        error_dict = except_to_errdict(error)
        self.proxy.EmailValidationError(app_name, error_dict)

    @defer.inlineCallbacks
    def validate_email(self,
                       app_name,
                       email,
                       password,
                       email_token,
                       ping_url=None):
        """Call the matching method in the processor."""
        try:
            token_name = get_token_name(app_name)
            credentials = yield self.processor.validate_email(
                email, password, email_token, token_name)
            yield self._process_new_token(app_name, email, credentials,
                                          ping_url)
            self.EmailValidated(app_name, email)
        except Exception as e:
            self.EmailValidationError(app_name, e)

    @log_call(logger.debug)
    def PasswordResetTokenSent(self, app_name, result):
        """Signal thrown when the token is succesfully sent."""
        self.proxy.PasswordResetTokenSent(app_name, result)

    @log_call(logger.debug)
    def PasswordResetError(self, app_name, error):
        """Signal thrown when there's a problem sending the token."""
        error_dict = except_to_errdict(error)
        self.proxy.PasswordResetError(app_name, error_dict)

    @defer.inlineCallbacks
    def request_password_reset_token(self, app_name, email):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.request_password_reset_token(email)
            self.PasswordResetTokenSent(app_name, result)
        except Exception as e:
            self.PasswordResetError(app_name, e)

    @log_call(logger.debug)
    def PasswordChanged(self, app_name, result):
        """Signal thrown when the token is succesfully sent."""
        self.proxy.PasswordChanged(app_name, result)

    @log_call(logger.debug)
    def PasswordChangeError(self, app_name, error):
        """Signal thrown when there's a problem sending the token."""
        error_dict = except_to_errdict(error)
        self.proxy.PasswordChangeError(app_name, error_dict)

    @defer.inlineCallbacks
    def set_new_password(self, app_name, email, token, new_password):
        """Call the matching method in the processor."""
        try:
            result = yield self.processor.set_new_password(
                email, token, new_password)
            self.PasswordChanged(app_name, result)
        except Exception as e:
            self.PasswordChangeError(app_name, e)