Commit e835d7e8 authored by Jens Langhammer's avatar Jens Langhammer

Revert "pyazo: cleanup redundant tasks"

This reverts commit 45641495.
parent 45641495
......@@ -19,6 +19,23 @@ from pyazo.utils.config import CONFIG
LOGGER = logging.getLogger(__name__)
# This is the base url used for image URLs
EXTERNAL_URL = CONFIG.get('external_url')
# This dictates how the Path is generated
# can be either of:
# - view_sha512_short
# - view_md5
# - view_sha256
# - view_sha512
DEFAULT_RETURN_VIEW = CONFIG.get('default_return_view')
# Set this to true if you only want to use external authentication
EXTERNAL_AUTH_ONLY = CONFIG.get('external_auth_only')
# If this is true, images are automatically claimed if the windows user exists
# in django
AUTO_CLAIM_ENABLED = CONFIG.get('auto_claim_enabled')
SECURE_PROXY_SSL_HEADER = tuple(CONFIG.get('secure_proxy_header', {}).items())[0]
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
......@@ -197,7 +214,7 @@ RAVEN_CONFIG = {
'release': VERSION,
'environment': 'production' if DEBUG is False else 'development',
'tags': {'site': CONFIG.get('external_url')}
'tags': {'site': EXTERNAL_URL}
ERROR_REPORT_ENABLED = CONFIG.get('error_report_enabled', False)
"""pyazo Core Account Views"""
from logging import getLogger
import logging
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate
from django.contrib.auth import login as django_login
......@@ -11,48 +13,47 @@ from django.utils.translation import ugettext as _
from pyazo.decorators import anonymous_required
from pyazo.forms.account import LoginForm
from pyazo.utils.config import CONFIG
LOGGER = getLogger(__name__)
LOGGER = logging.getLogger(__name__)
def login(request):
def login(req):
"""View to handle Browser Logins Requests"""
if request.method == 'POST':
form = LoginForm(request.POST)
if req.method == 'POST':
form = LoginForm(req.POST)
if form.is_valid():
user = authenticate(
if user is not None:
django_login(request, user)
django_login(req, user)
# Set updated password in user profile for PAM
if not form.cleaned_data.get('remember'):
request.session.set_expiry(0) # Expires when browser is closed
messages.success(request, _("Successfully logged in!"))
req.session.set_expiry(0) # Expires when browser is closed
messages.success(req, _("Successfully logged in!"))"Successfully logged in %s", form.cleaned_data.get('username'))
# Check if there is a next GET parameter and redirect to that
if 'next' in request.GET:
return redirect(request.GET.get('next'))
if 'next' in req.GET:
return redirect(req.GET.get('next'))
# Otherwise just index
return redirect(reverse('index'))
# Check if the user's account is pending
# and inform that, they need to check their usernames
# users = User.objects.filter(username=form.cleaned_data.get('username'))
messages.error(request, _("Invalid Login"))
messages.error(req, _("Invalid Login"))"Failed to log in %s", form.cleaned_data.get('username'))
return redirect(reverse('accounts-login'))"Form invalid")
form = LoginForm()
return render(request, 'account/login.html', {
return render(req, 'account/login.html', {
'form': form,
'title': _("SSO - Login"),
'primary_action': _("Login"),
'external_only': CONFIG.get('external_auth_only'),
'external_only': settings.EXTERNAL_AUTH_ONLY,
def logout(request):
"""pyazo core views"""
from logging import getLogger
import logging
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
......@@ -9,7 +9,7 @@ from django.views.generic import TemplateView
from pyazo.models import Collection, Upload
LOGGER = getLogger(__name__)
LOGGER = logging.getLogger(__name__)
class IndexView(LoginRequiredMixin, TemplateView):
"""Show overview of uploads"""
......@@ -3,6 +3,7 @@ import os
from logging import getLogger
from urllib.parse import urljoin
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
......@@ -16,7 +17,6 @@ from django.views.generic import TemplateView, View
from pyazo.forms.view import CollectionSelectForm
from pyazo.models import Collection, Upload
from pyazo.utils.config import CONFIG
from pyazo.utils.files import generate_hashes, save_from_post
from pyazo.views.view import UploadViewFile
......@@ -131,7 +131,7 @@ class LegacyUploadView(View):
new_upload = Upload(
file=save_from_post(request.FILES['imagedata'].read(), extension=ext))
# Run auto-claim
if CONFIG.get('auto_claim_enabled') and 'username' in request.POST:
if settings.AUTO_CLAIM_ENABLED and 'username' in request.POST:
matching = User.objects.filter(username=request.POST.get('username'))
if matching.exists():
new_upload.user = matching.first()
......@@ -142,10 +142,10 @@ class LegacyUploadView(View):
UploadViewFile.count_view(new_upload, request)"Uploaded %s", new_upload.filename)
# Generate url for client to open
upload_prop = CONFIG.get('default_return_view').replace('view_', '')
upload_prop = settings.DEFAULT_RETURN_VIEW.replace('view_', '')
upload_hash = getattr(new_upload, upload_prop, 'sha256')
url = reverse(CONFIG.get('default_return_view'), kwargs={'file_hash': upload_hash})
full_url = urljoin(CONFIG.get('external_url'), url)
url = reverse(settings.DEFAULT_RETURN_VIEW, kwargs={'file_hash': upload_hash})
full_url = urljoin(settings.EXTERNAL_URL, url)
return HttpResponse(full_url)
return HttpResponse(status=400)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment