# Path: app/views.py
# def startup_list(request):
# def startup_detail(request, id):
# def message_detail(request, id):
#     def _decode_header(txt):
# def message_attachment(request, id, attachment_id):
# def incoming_callback(request, pwd):
#     def __init__(self, request=None, *args, **kwargs):
#     def clean(self):
#     def confirm_login_allowed(self, user):
#     def get_user_id(self):
#     def get_user(self):
# def opensearch(request):
# class KimaLoginForm(forms.Form):
# 
# Path: app/views_admin.py
# def index(request):
#     def clean_email(self):
# def user_list(request):
# def user_edit(request, user_id):
# def user_add(request):
# def startup_list(request):
#     def validate_user_id(self, value):
# def startup_permission(request, startup_id):
#     def validate_key(self, key):
# def startup_edit(request, startup_id):
# class UserCreateForm(forms.Form): # TODO : Look if it's not better to subclass a ModelForm to user, and add a custom field around it
# class UserEditForm(forms.Form):
# class StartupPermissionSerializer(serializers.Serializer):
# class StartupEditSerializer(serializers.Serializer):
# 
# Path: app/views_settings.py
# def index(request):
#     def __init__(self, user, *args, **kwargs):
#     def clean_current_password(self):
#     def clean(self):
# def password(request):
# class PasswordChangeForm(forms.Form):
# 
# Path: app/views.py
# class KimaLoginForm(forms.Form):
#     """
#     Base class for authenticating users. Extend this to get a form that accepts
#     username/password logins.
#     """
#     email = forms.EmailField(max_length=254, widget=forms.EmailInput(attrs={"class": "form-control"}))
#     password = forms.CharField(label="Password", widget=forms.PasswordInput(attrs={"class": "form-control"}))
# 
#     error_messages = {
#         'invalid_login': ("Please enter a correct email and password. "
#                            "Note that both fields may be case-sensitive."),
#         'inactive': "This account is inactive.",
#     }
# 
#     def __init__(self, request=None, *args, **kwargs):
#         """
#         The 'request' parameter is set for custom auth use by subclasses.
#         The form data comes in via the standard 'data' kwarg.
#         """
#         self.request = request
#         self.user_cache = None
#         super(KimaLoginForm, self).__init__(*args, **kwargs)
# 
#     def clean(self):
#         email = self.cleaned_data.get('email')
#         password = self.cleaned_data.get('password')
# 
#         if email and password:
#             try:
#                 tmp_user = get_user_model().objects.get(email__iexact=email,is_active=True)
#                 self.user_cache = authenticate(username=tmp_user.username,password=password)
#             except get_user_model().DoesNotExist:
#                 self.user_cache = None
# 
#             if self.user_cache is None:
#                 raise forms.ValidationError(
#                     self.error_messages['invalid_login'],
#                     code='invalid_login'
#                 )
#             else:
#                 self.confirm_login_allowed(self.user_cache)
# 
#         return self.cleaned_data
# 
#     def confirm_login_allowed(self, user):
#         """
#         Controls whether the given User may log in. This is a policy setting,
#         independent of end-user authentication. This default behavior is to
#         allow login by active users, and reject login by inactive users.
# 
#         If the given user cannot log in, this method should raise a
#         ``forms.ValidationError``.
# 
#         If the given user may log in, this method should return None.
#         """
#         if not user.is_active:
#             raise forms.ValidationError(
#                 self.error_messages['inactive'],
#                 code='inactive',
#             )
# 
#     def get_user_id(self):
#         if self.user_cache:
#             return self.user_cache.id
#         return None
# 
#     def get_user(self):
#         return self.user_cache


from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.contrib.auth.decorators import login_required
from django.views.generic import RedirectView
from app import views as app_views
from app import views_admin as app_views_admin
from app import views_settings as app_views_settings
from app.views import KimaLoginForm
This is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""



urlpatterns = [
    url(r'^$', login_required(RedirectView.as_view(url="/startup/")), name="index"),

    url(r'^startup/$', app_views.startup_list, name="startup_list"),
    url(r'^startup/(?P<id>[0-9]+)/$', app_views.startup_detail, name="startup_detail"),
    url(r'^message/(?P<id>[0-9]+)/$', app_views.message_detail, name="message_detail"),
    url(r'^message/(?P<id>[0-9]+)/attachment/(?P<attachment_id>[0-9]+)/$', app_views.message_attachment, name="message_attachment"),

    url(r'^accounts/login/$', auth_views.login, {'template_name': 'registration/login.html', 'authentication_form': KimaLoginForm}, name="auth_login"),
    url(r'^accounts/logout/$', auth_views.logout,  name='auth_logout'),

    url(r'^!callback/mail/(?P<pwd>[0-9A-Za-z]+)/$', app_views.incoming_callback, name="mail_callback"),

    url(r'^settings/$', app_views_settings.index, name="settings"),

# Path: app/views.py
# def startup_list(request):
# def startup_detail(request, id):
# def message_detail(request, id):
#     def _decode_header(txt):
# def message_attachment(request, id, attachment_id):
# def incoming_callback(request, pwd):
#     def __init__(self, request=None, *args, **kwargs):
#     def clean(self):
#     def confirm_login_allowed(self, user):
#     def get_user_id(self):
#     def get_user(self):
# def opensearch(request):
# class KimaLoginForm(forms.Form):
# 
# Path: app/views_admin.py
# def index(request):
#     def clean_email(self):
# def user_list(request):
# def user_edit(request, user_id):
# def user_add(request):
# def startup_list(request):
#     def validate_user_id(self, value):
# def startup_permission(request, startup_id):
#     def validate_key(self, key):
# def startup_edit(request, startup_id):
# class UserCreateForm(forms.Form): # TODO : Look if it's not better to subclass a ModelForm to user, and add a custom field around it
# class UserEditForm(forms.Form):
# class StartupPermissionSerializer(serializers.Serializer):
# class StartupEditSerializer(serializers.Serializer):
# 
# Path: app/views_settings.py
# def index(request):
#     def __init__(self, user, *args, **kwargs):
#     def clean_current_password(self):
#     def clean(self):
# def password(request):
# class PasswordChangeForm(forms.Form):
# 
# Path: app/views.py
# class KimaLoginForm(forms.Form):
#     """
#     Base class for authenticating users. Extend this to get a form that accepts
#     username/password logins.
#     """
#     email = forms.EmailField(max_length=254, widget=forms.EmailInput(attrs={"class": "form-control"}))
#     password = forms.CharField(label="Password", widget=forms.PasswordInput(attrs={"class": "form-control"}))
# 
#     error_messages = {
#         'invalid_login': ("Please enter a correct email and password. "
#                            "Note that both fields may be case-sensitive."),
#         'inactive': "This account is inactive.",
#     }
# 
#     def __init__(self, request=None, *args, **kwargs):
#         """
#         The 'request' parameter is set for custom auth use by subclasses.
#         The form data comes in via the standard 'data' kwarg.
#         """
#         self.request = request
#         self.user_cache = None
#         super(KimaLoginForm, self).__init__(*args, **kwargs)
# 
#     def clean(self):
#         email = self.cleaned_data.get('email')
#         password = self.cleaned_data.get('password')
# 
#         if email and password:
#             try:
#                 tmp_user = get_user_model().objects.get(email__iexact=email,is_active=True)
#                 self.user_cache = authenticate(username=tmp_user.username,password=password)
#             except get_user_model().DoesNotExist:
#                 self.user_cache = None
# 
#             if self.user_cache is None:
#                 raise forms.ValidationError(
#                     self.error_messages['invalid_login'],
#                     code='invalid_login'
#                 )
#             else:
#                 self.confirm_login_allowed(self.user_cache)
# 
#         return self.cleaned_data
# 
#     def confirm_login_allowed(self, user):
#         """
#         Controls whether the given User may log in. This is a policy setting,
#         independent of end-user authentication. This default behavior is to
#         allow login by active users, and reject login by inactive users.
# 
#         If the given user cannot log in, this method should raise a
#         ``forms.ValidationError``.
# 
#         If the given user may log in, this method should return None.
#         """
#         if not user.is_active:
#             raise forms.ValidationError(
#                 self.error_messages['inactive'],
#                 code='inactive',
#             )
# 
#     def get_user_id(self):
#         if self.user_cache:
#             return self.user_cache.id
#         return None
# 
#     def get_user(self):
#         return self.user_cache


# Path: reporting/urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.contrib.auth.decorators import login_required
from django.views.generic import RedirectView
from app import views as app_views
from app import views_admin as app_views_admin
from app import views_settings as app_views_settings
from app.views import KimaLoginForm

This is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""



urlpatterns = [
    url(r'^$', login_required(RedirectView.as_view(url="/startup/")), name="index"),

    url(r'^startup/$', app_views.startup_list, name="startup_list"),
    url(r'^startup/(?P<id>[0-9]+)/$', app_views.startup_detail, name="startup_detail"),
    url(r'^message/(?P<id>[0-9]+)/$', app_views.message_detail, name="message_detail"),
    url(r'^message/(?P<id>[0-9]+)/attachment/(?P<attachment_id>[0-9]+)/$', app_views.message_attachment, name="message_attachment"),

    url(r'^accounts/login/$', auth_views.login, {'template_name': 'registration/login.html', 'authentication_form': KimaLoginForm}, name="auth_login"),
    url(r'^accounts/logout/$', auth_views.logout,  name='auth_logout'),

    url(r'^!callback/mail/(?P<pwd>[0-9A-Za-z]+)/$', app_views.incoming_callback, name="mail_callback"),

    url(r'^settings/$', app_views_settings.index, name="settings"),

    url(r'^settings/password/$', app_views_settings.password, name="settings_password"),