def show_disable_two_factor_authentication_link(self): """ Indicates whether the disable two factor authentication link should be shown. The following conditions shall be met for True to be returned: - User hasn enabled the two factor authentication for his account. - In app settings, the globally enable two factor authentication is set to False. :return bool: """ user = api.user.get_current() return not is_two_factor_authentication_globally_enabled() and has_enabled_two_factor_authentication(user)
def show_disable_two_factor_authentication_link(self): """ Indicates whether the disable two factor authentication link should be shown. The following conditions shall be met for True to be returned: - User hasn enabled the two factor authentication for his account. - In app settings, the globally enable two factor authentication is set to False. :return bool: """ if api.user.is_anonymous(): return False # don't show action to anonymous users user = api.user.get_current() return ( is_two_factor_authentication_globally_enabled() and has_enabled_two_factor_authentication(user) )
def show_enable_two_factor_authentication_link(self): """ Indicates whether the enable two factor authentication link should be shown. The following conditions shall be met for True to be returned: - User hasn't enabled the two factor authentication for his account. - In app settings, the globally enable two factor authentication is set to False. :return bool: """ if api.user.is_anonymous(): return False # don't show action to anonymous users user = api.user.get_current() return ( is_two_factor_authentication_globally_enabled() and not has_enabled_two_factor_authentication(user) )
def userCreatedHandler(principal, event): """ Fired upon creation of each user. If app setting ``globally_enabled`` is set to True, two-step verification would be automatically enabled for the registered users (in that case they would have to go through the bar-code recovery procedure. The ``principal`` value is seems to be a user object, although it does not have the ``setMemberProperties`` method defined (that's why we obtain the user using `plone.api`, 'cause that one has it). """ from collective.googleauthenticator.helpers import ( is_two_factor_authentication_globally_enabled, get_or_create_secret) user = api.user.get(username=principal.getId()) if is_two_factor_authentication_globally_enabled(): get_or_create_secret(user) user.setMemberProperties(mapping={ 'enable_two_factor_authentication': True, }) logger.debug(user.getProperty('enable_two_factor_authentication')) logger.debug(user.getProperty('two_factor_authentication_secret'))
def userCreatedHandler(principal, event): """ Fired upon creation of each user. If app setting ``globally_enabled`` is set to True, two-step verification would be automatically enabled for the registered users (in that case they would have to go through the bar-code recovery procedure. The ``principal`` value is seems to be a user object, although it does not have the ``setMemberProperties`` method defined (that's why we obtain the user using `plone.api`, 'cause that one has it). """ from collective.googleauthenticator.helpers import ( is_two_factor_authentication_globally_enabled, get_or_create_secret, ) user = api.user.get(username=principal.getId()) if is_two_factor_authentication_globally_enabled(): get_or_create_secret(user) user.setMemberProperties(mapping={"enable_two_factor_authentication": True}) logger.debug(user.getProperty("enable_two_factor_authentication")) logger.debug(user.getProperty("two_factor_authentication_secret"))
def is_two_factor_authentication_globally_enabled(self): """ Disable the two-step verification for the user and redirect back to the `@@personal-information`. """ return is_two_factor_authentication_globally_enabled()