# Path: amivapi/settings.py
# EMAIL_REGEX = '^.+@.+$'
# 
# Path: amivapi/users/security.py
# class UserAuth(AmivTokenAuth):
#     """Provides auth for /users resource.
# 
#     This is an example of how to implement the AmivTokenAuth.
# 
#     Main Goals:
# 
#     - Registered users can see nethz/name of everyone, full data of themselves
#     - Registered users can change their own data (nobody else)
# 
# 
#     We dont have to care about:
# 
#     - Admins, since for them no filters etc are applied
#     - Unregistered users, since no methods are public.
# 
#     Since only admins can POST, we do not need to implement a custom
#     `has_resource_write_permission` - the default is fine.
#     """
# 
#     def has_item_write_permission(self, user_id, item):
#         """Check if *user* is allowed to write *item*.
# 
#         This includes PATCH and DELETE.
# 
#         User can only write his own data.
# 
#         Args:
#             user (str): The id of the user that wants to access the item
#             item (dict): The item the user wants to change or delete.
# 
#         Returns:
#             bool: True if user has permission to change the item, False if not.
#         """
#         return str(item['_id']) == user_id
# 
#     def create_user_lookup_filter(self, user_id):
#         """Create a filter for item lookup.
# 
#         Not a member: Can see only himself
#         A Member: Can see everyone
# 
#         Note: Users will only see complete info for themselves.
#         But excluding other fields will be done in a hook later.
# 
#         Args:
#             user_id (str): Id of the user. No public methods -> wont be None
# 
#         Returns:
#             dict: The filter, will be combined with other filters in the hook.
#                 Return None if no filters should be applied.
#         """
#         # Find out if not member
#         collection = current_app.data.driver.db['users']
#         # set projection to only return membership
#         result = collection.find_one({'_id': ObjectId(user_id)},
#                                      {'membership': 1})
# 
#         if result['membership'] == "none":
#             # Can't see others
#             return {'_id': user_id}
#         else:
#             # Can see everyone (fields will be filtered later)
#             return {}


from datetime import timedelta
from textwrap import dedent
from amivapi.settings import EMAIL_REGEX
from .security import UserAuth
                'not_patchable_unless_admin': True,
                'nullable': True,
                'default': None,
                'example': 'itet'
            },
            'gender': {
                'type': 'string',
                'allowed': ['male', 'female'],
                'not_patchable_unless_admin': True,
                'required': True,
                'example': 'male',
            },

            # Fields the user can modify himself
            'password': {
                'type': 'string',
                'minlength': 7,
                'maxlength': 100,
                'empty': False,
                'nullable': True,
                'default': None,
                'description': 'Leave empty to use just LDAP authentification. '
                'People without LDAP should use this field.',
                'session_younger_than': timedelta(minutes=1),
                'example': "Hunter2",
                'writeonly': True,  # 'writeonly' only affects the docs
            },
            'email': {
                'type': 'string',
                'maxlength': 100,

# Path: amivapi/settings.py
# EMAIL_REGEX = '^.+@.+$'
# 
# Path: amivapi/users/security.py
# class UserAuth(AmivTokenAuth):
#     """Provides auth for /users resource.
# 
#     This is an example of how to implement the AmivTokenAuth.
# 
#     Main Goals:
# 
#     - Registered users can see nethz/name of everyone, full data of themselves
#     - Registered users can change their own data (nobody else)
# 
# 
#     We dont have to care about:
# 
#     - Admins, since for them no filters etc are applied
#     - Unregistered users, since no methods are public.
# 
#     Since only admins can POST, we do not need to implement a custom
#     `has_resource_write_permission` - the default is fine.
#     """
# 
#     def has_item_write_permission(self, user_id, item):
#         """Check if *user* is allowed to write *item*.
# 
#         This includes PATCH and DELETE.
# 
#         User can only write his own data.
# 
#         Args:
#             user (str): The id of the user that wants to access the item
#             item (dict): The item the user wants to change or delete.
# 
#         Returns:
#             bool: True if user has permission to change the item, False if not.
#         """
#         return str(item['_id']) == user_id
# 
#     def create_user_lookup_filter(self, user_id):
#         """Create a filter for item lookup.
# 
#         Not a member: Can see only himself
#         A Member: Can see everyone
# 
#         Note: Users will only see complete info for themselves.
#         But excluding other fields will be done in a hook later.
# 
#         Args:
#             user_id (str): Id of the user. No public methods -> wont be None
# 
#         Returns:
#             dict: The filter, will be combined with other filters in the hook.
#                 Return None if no filters should be applied.
#         """
#         # Find out if not member
#         collection = current_app.data.driver.db['users']
#         # set projection to only return membership
#         result = collection.find_one({'_id': ObjectId(user_id)},
#                                      {'membership': 1})
# 
#         if result['membership'] == "none":
#             # Can't see others
#             return {'_id': user_id}
#         else:
#             # Can see everyone (fields will be filtered later)
#             return {}


# Path: amivapi/users/model.py
from datetime import timedelta
from textwrap import dedent
from amivapi.settings import EMAIL_REGEX
from .security import UserAuth

                'not_patchable_unless_admin': True,
                'nullable': True,
                'default': None,
                'example': 'itet'
            },
            'gender': {
                'type': 'string',
                'allowed': ['male', 'female'],
                'not_patchable_unless_admin': True,
                'required': True,
                'example': 'male',
            },

            # Fields the user can modify himself
            'password': {
                'type': 'string',
                'minlength': 7,
                'maxlength': 100,
                'empty': False,
                'nullable': True,
                'default': None,
                'description': 'Leave empty to use just LDAP authentification. '
                'People without LDAP should use this field.',
                'session_younger_than': timedelta(minutes=1),
                'example': "Hunter2",
                'writeonly': True,  # 'writeonly' only affects the docs
            },
            'email': {
                'type': 'string',
                'maxlength': 100,

                'regex': EMAIL_REGEX,