from ...datastructures import sdict
from ...http import redirect
from .models import AuthUser, AuthGroup, AuthMembership, AuthPermission, \
    AuthEvent


DEFAULT = lambda: None

default_settings = sdict(
    password_min_length=6,
    cas_maps=None,
    registration_requires_verification=False,
    registration_requires_approval=False,
    login_after_registration=False,
    login_after_password_change=True,
    create_user_groups=None,
    everybody_group_id=None,
    #login_captcha=None,
    #register_captcha=None,
    #retrieve_username_captcha=None,
    #retrieve_password_captcha=None,
    #captcha=None,
    expiration=3600,  # one hour
    long_expiration=3600 * 30 * 24,  # one month
    remember_me_form=True,
    allow_basic_login=False,
    on_failed_authentication=lambda x: redirect(x),
    logging_enabled=True,
    allow_delete_accounts=False,
    #password_field='password',
    #table_user_name='auth_user',
    #table_group_name='auth_group',
    #table_membership_name='auth_membership',
    #table_permission_name='auth_permission',
    #table_event_name='auth_event',
    #table_cas_name='auth_cas',
    models=sdict(
        user=AuthUser,
        group=AuthGroup,
        membership=AuthMembership,
        permission=AuthPermission,
        event=AuthEvent
    ),
    use_username=False,
    login_userfield='email',
    logout_onlogout=None,
    register_fields=None,
    profile_fields=None,
    email_case_sensitive=True,
    username_case_sensitive=True,
    update_fields=['email'],
    ondelete="CASCADE",
    extra_fields={},
    actions_disabled=[],
    login_onvalidation=[],
    login_onaccept=[],
    login_onfail=[],
    register_onvalidation=[],
    register_onaccept=[],
    verify_email_onaccept=[],
    profile_onvalidation=[],
    profile_onaccept=[],
    change_password_onvalidation=[],
    change_password_onaccept=[],
    retrieve_password_onvalidation=[],
    reset_password_onvalidation=[],
    reset_password_onaccept=[],
    messages=sdict()
)

default_messages = sdict(
    login_button='Login',
    register_button='Register',
    password_reset_button='Request reset password',
    password_change_button='Change password',
    profile_save_button='Apply changes',
    submit_button='Submit',
    verify_password='Verify Password',
    delete_label='Check to delete',
    function_disabled='Function disabled',
    access_denied='Insufficient privileges',
    registration_verifying='Registration needs verification',
    registration_pending='Registration is pending approval',
    email_taken='This email already has an account',
    invalid_username='Invalid username',
    username_taken='Username already taken',
    login_disabled='Login disabled by administrator',
    logged_in='Logged in',
    email_sent='Email sent',
    unable_to_send_email='Unable to send email',
    email_verified='Email verified',
    logged_out='Logged out',
    registration_successful='Registration successful',
    invalid_email='Invalid email',
    unable_send_email='Unable to send email',
    invalid_login='Invalid login',
    invalid_user='Invalid user',
    invalid_password='Invalid password',
    is_empty="Cannot be empty",
    mismatched_password="Password fields don't match",
    verify_email='Welcome %(username)s! Click on the link %(link)s to verify your email',
    verify_email_subject='Email verification',
    username_sent='Your username was emailed to you',
    new_password_sent='A new password was emailed to you',
    password_changed='Password changed',
    retrieve_username='Your username is: %(username)s',
    retrieve_username_subject='Username retrieve',
    retrieve_password='Your password is: %(password)s',
    retrieve_password_subject='Password retrieve',
    reset_password='Click on the link %(link)s to reset your password',
    reset_password_subject='Password reset',
    invalid_reset_password='Invalid reset password',
    profile_updated='Profile updated',
    new_password='New password',
    old_password='Old password',
    group_description='Group uniquely assigned to user %(id)s',
    register_log='User %(id)s Registered',
    login_log='User %(id)s Logged-in',
    login_failed_log=None,
    logout_log='User %(id)s Logged-out',
    profile_log='User %(id)s Profile updated',
    verify_email_log='User %(id)s Verification email sent',
    retrieve_username_log='User %(id)s Username retrieved',
    retrieve_password_log='User %(id)s Password retrieved',
    reset_password_log='User %(id)s Password reset',
    change_password_log='User %(id)s Password changed',
    add_group_log='Group %(group_id)s created',
    del_group_log='Group %(group_id)s deleted',
    add_membership_log=None,
    del_membership_log=None,
    has_membership_log=None,
    add_permission_log=None,
    del_permission_log=None,
    has_permission_log=None,
    impersonate_log='User %(id)s is impersonating %(other_id)s',
    label_first_name='First name',
    label_last_name='Last name',
    label_username='Username',
    label_email='E-mail',
    label_password='Password',
    label_registration_key='Registration key',
    label_reset_password_key='Reset Password key',
    label_registration_id='Registration identifier',
    label_role='Role',
    label_description='Description',
    label_user_id='User ID',
    label_group_id='Group ID',
    label_name='Name',
    label_table_name='Object or table name',
    label_record_id='Record ID',
    label_time_stamp='Timestamp',
    label_client_ip='Client IP',
    label_origin='Origin',
    label_remember_me="Remember me (for 30 days)",
    verify_password_comment='please input your password again',
)
