Ejemplo n.º 1
0
def delete_password_resets(request: Request, age_in_days: int):
    """Delete password resets that are older than `age_in_days`."""
    resets = find_service(request.root, 'principals', 'resets')
    expired = [u for u in resets.values() if is_older_than(u, age_in_days)]
    for reset in expired:
        logger.info('deleting reset {0}'.format(reset))
        del resets[reset.__name__]
Ejemplo n.º 2
0
def delete_password_resets(request: Request, age_in_days: int):
    """Delete password resets that are older than `age_in_days`."""
    resets = find_service(request.root, 'principals', 'resets')
    expired = [u for u in resets.values() if is_older_than(u, age_in_days)]
    for reset in expired:
        logger.info('deleting reset {0}'.format(reset))
        del resets[reset.__name__]
Ejemplo n.º 3
0
def delete_not_activated_users(request: Request, age_in_days: int):
    """Delete not activate users that are older than `age_in_days`."""
    userlocator = request.registry.getMultiAdapter((request.context, request),
                                                   IRolesUserLocator)
    users = userlocator.get_users()
    not_activated = (u for u in users if not u.active)
    expired = [u for u in not_activated if is_older_than(u, age_in_days)]
    for user in expired:
        msg = 'deleting user {0}: name {1} email {2}'.format(
            user, user.email, user.name)
        logger.info(msg)
        del user.__parent__[user.__name__]
Ejemplo n.º 4
0
def delete_not_activated_users(request: Request, age_in_days: int):
    """Delete not activate users that are older than `age_in_days`."""
    userlocator = request.registry.getMultiAdapter((request.context, request),
                                                   IRolesUserLocator)
    users = userlocator.get_users()
    not_activated = (u for u in users if not u.active)
    expired = [u for u in not_activated if is_older_than(u, age_in_days)]
    for user in expired:
        msg = 'deleting user {0}: name {1} email {2}'.format(user,
                                                             user.email,
                                                             user.name)
        logger.info(msg)
        del user.__parent__[user.__name__]
Ejemplo n.º 5
0
 def validate_activation_path(node, value):
     locator = request.registry.getMultiAdapter((context, request),
                                                IUserLocator)
     user = locator.get_user_by_activation_path(value)
     error_msg = 'Unknown or expired activation path'
     if user is None:
         raise Invalid(node, error_msg)
     elif is_older_than(user, days=8):
         user.activation_path = None
         raise Invalid(node, error_msg)
     else:
         request.validated['user'] = user
         # TODO we should use a sheet to activate the user.
         user.activate()
         user.activation_path = None
         event = ResourceSheetModified(user, IUserBasic, request.registry, {},
                                       {}, request)
         registry.notify(event)  # trigger reindex activation_path index
Ejemplo n.º 6
0
def validate_activation_path(context, request: Request):
    """Validate the user name of a login request.

    If valid and activated, the user object is added as 'user' to
    `request.validated`.
    """
    path = request.validated["path"]
    locator = request.registry.getMultiAdapter((context, request), IUserLocator)
    user = locator.get_user_by_activation_path(path)
    error = error_entry("body", "path", "Unknown or expired activation path")
    if user is None:
        request.errors.append(error)
    elif is_older_than(user, days=8):
        request.errors.append(error)
        user.activation_path = None
    else:
        user.activate()
        user.activation_path = None
        request.validated["user"] = user
        event = ResourceSheetModified(user, IUserBasic, request.registry, {}, {}, request)
        request.registry.notify(event)  # trigger reindex activation_path index
Ejemplo n.º 7
0
def validate_activation_path(context, request: Request):
    """Validate the user name of a login request.

    If valid and activated, the user object is added as 'user' to
    `request.validated`.
    """
    path = request.validated['path']
    locator = request.registry.getMultiAdapter((context, request),
                                               IUserLocator)
    user = locator.get_user_by_activation_path(path)
    error = error_entry('body', 'path', 'Unknown or expired activation path')
    if user is None:
        request.errors.append(error)
    elif is_older_than(user, days=8):
        request.errors.append(error)
        user.activation_path = None
    else:
        user.activate()
        user.activation_path = None
        request.validated['user'] = user
        event = ResourceSheetModified(user, IUserBasic, request.registry, {},
                                      {}, request)
        request.registry.notify(event)  # trigger reindex activation_path index
Ejemplo n.º 8
0
 def validate_activation_path(node, value):
     registry = request.registry
     locator = registry.getMultiAdapter((context, request), IUserLocator)
     user = locator.get_user_by_activation_path(value)
     error_msg = 'Unknown or expired activation path'
     if user is None:
         raise Invalid(node, error_msg)
     elif is_older_than(user, days=8):
         user.activation_path = None
         raise Invalid(node, error_msg)
     else:
         request.validated['user'] = user
         if not user.active:
             user.activate()
         elif user.has_new_email_pending:
             user.activate_new_email()
         else:
             raise Invalid(node, 'No new email waiting for activation.')
         user.activation_path = None
         autoupdated = False
         event = ResourceSheetModified(user, IUserBasic, registry, {},
                                       {}, request, autoupdated)
         registry.notify(event)  # trigger reindex activation_path index
Ejemplo n.º 9
0
 def validate_activation_path(node, value):
     registry = request.registry
     locator = registry.getMultiAdapter((context, request), IUserLocator)
     user = locator.get_user_by_activation_path(value)
     error_msg = 'Unknown or expired activation path'
     if user is None:
         raise Invalid(node, error_msg)
     elif is_older_than(user, days=8):
         user.activation_path = None
         raise Invalid(node, error_msg)
     else:
         request.validated['user'] = user
         if not user.active:
             user.activate()
         elif user.has_new_email_pending:
             user.activate_new_email()
         else:
             raise Invalid(node, 'No new email waiting for activation.')
         user.activation_path = None
         autoupdated = False
         event = ResourceSheetModified(user, IUserBasic, registry, {}, {},
                                       request, autoupdated)
         registry.notify(event)  # trigger reindex activation_path index