# Path: accounts/views.py
# def registration(request):
#     if request.user.is_authenticated():
#         return HttpResponseRedirect(reverse('home'))
#     if request.method == 'POST':
#         form = RegistrationForm(request.POST)
#         if form.is_valid():
#             account = form.save()
#             account.is_active = False
#             account.save()
#             account.send_activation_email()
#             return render(request, 'accounts/registration.html', {'form': None})
#     else:
#         form = RegistrationForm()
#     return render(request, 'accounts/registration.html', {'form': form})
# 
# def activate_account(request, username, uid_hash):
#     if request.user.is_authenticated:
#         return HttpResponseRedirect(reverse('home'))
# 
#     try:
#         account = Account.objects.get(username__iexact=username)
#     except Account.DoesNotExist:
#         return render(request, 'accounts/activate.html', {'user_does_not_exist': True})
# 
#     new_hash = create_hash(account.id)
#     if new_hash != uid_hash:
#         return render(request, 'accounts/activate.html', {'decode_error': True})
# 
#     account.is_active = True
#     account.save()
#     return render(request, 'accounts/activate.html', {'all_ok': True})
# 
# def resend_activation_emmil(request):
#     if request.user.is_authenticated:
#         return HttpResponseRedirect(reverse('home'))
# 
#     if request.method == 'POST':
#         form = ReactivationForm(request.POST)
#         if form.is_valid():
#             account = form.cleaned_data['account']
#             account.send_activation_email()
#             return render(request, 'accounts/resend_activation.html', {'form': None})
#     else:
#         form = ReactivationForm()
#     return render(request, 'accounts/resend_activation.html', {'form': form})
# 
# Path: ac_mediator/views.py
# @login_required
# def monitor(request):
#     flower_auth = os.getenv('FLOWER_BASIC_AUTH', ':').split(':')
#     redmon_auth = os.getenv('FLOWER_BASIC_AUTH', ':').split(':')
#     return render(request, 'admin/monitor.html', {
#         'flower_auth': flower_auth,
#         'redmon_auth': redmon_auth,
#     })
# 
# @login_required
# @user_passes_test(lambda u: u.is_staff, login_url='/')
# def crash_me(request):
#     raise Exception('Everything is under control')


from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from accounts.views import registration, activate_account, resend_activation_emmil
from ac_mediator.views import monitor, crash_me
from django.contrib.staticfiles.urls import staticfiles_urlpatterns


# Auth urls
# https://stackoverflow.com/questions/6930982/how-to-use-a-variable-inside-a-regular-expression
# domainPrefix = "authenticate/"
domainPrefix = ""

urlpatterns = [
    url(r'^%scrash/$' % domainPrefix, crash_me, name='crash_me'),
    url(r'^%sregister/$' % domainPrefix, registration, name='registration'),

# Path: accounts/views.py
# def registration(request):
#     if request.user.is_authenticated():
#         return HttpResponseRedirect(reverse('home'))
#     if request.method == 'POST':
#         form = RegistrationForm(request.POST)
#         if form.is_valid():
#             account = form.save()
#             account.is_active = False
#             account.save()
#             account.send_activation_email()
#             return render(request, 'accounts/registration.html', {'form': None})
#     else:
#         form = RegistrationForm()
#     return render(request, 'accounts/registration.html', {'form': form})
# 
# def activate_account(request, username, uid_hash):
#     if request.user.is_authenticated:
#         return HttpResponseRedirect(reverse('home'))
# 
#     try:
#         account = Account.objects.get(username__iexact=username)
#     except Account.DoesNotExist:
#         return render(request, 'accounts/activate.html', {'user_does_not_exist': True})
# 
#     new_hash = create_hash(account.id)
#     if new_hash != uid_hash:
#         return render(request, 'accounts/activate.html', {'decode_error': True})
# 
#     account.is_active = True
#     account.save()
#     return render(request, 'accounts/activate.html', {'all_ok': True})
# 
# def resend_activation_emmil(request):
#     if request.user.is_authenticated:
#         return HttpResponseRedirect(reverse('home'))
# 
#     if request.method == 'POST':
#         form = ReactivationForm(request.POST)
#         if form.is_valid():
#             account = form.cleaned_data['account']
#             account.send_activation_email()
#             return render(request, 'accounts/resend_activation.html', {'form': None})
#     else:
#         form = ReactivationForm()
#     return render(request, 'accounts/resend_activation.html', {'form': form})
# 
# Path: ac_mediator/views.py
# @login_required
# def monitor(request):
#     flower_auth = os.getenv('FLOWER_BASIC_AUTH', ':').split(':')
#     redmon_auth = os.getenv('FLOWER_BASIC_AUTH', ':').split(':')
#     return render(request, 'admin/monitor.html', {
#         'flower_auth': flower_auth,
#         'redmon_auth': redmon_auth,
#     })
# 
# @login_required
# @user_passes_test(lambda u: u.is_staff, login_url='/')
# def crash_me(request):
#     raise Exception('Everything is under control')


# Path: ac_mediator/urls.py
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from accounts.views import registration, activate_account, resend_activation_emmil
from ac_mediator.views import monitor, crash_me
from django.contrib.staticfiles.urls import staticfiles_urlpatterns



# Auth urls
# https://stackoverflow.com/questions/6930982/how-to-use-a-variable-inside-a-regular-expression
# domainPrefix = "authenticate/"
domainPrefix = ""

urlpatterns = [
    url(r'^%scrash/$' % domainPrefix, crash_me, name='crash_me'),
    url(r'^%sregister/$' % domainPrefix, registration, name='registration'),

    url(r'^%sactivate/(?P<username>[^\/]+)/(?P<uid_hash>[^\/]+)/.*$' % domainPrefix, activate_account, name="accounts-activate"),