Commit c3996a51f16a749cdd201e7e94982f93649cb2fa
1 parent
d74a55cd
Exists in
master
and in
3 other branches
Applying maintenance config
Showing
2 changed files
with
11 additions
and
4 deletions
Show diff stats
security/models.py
... | ... | @@ -3,7 +3,7 @@ from django.utils.translation import ugettext_lazy as _ |
3 | 3 | |
4 | 4 | class Security(models.Model): |
5 | 5 | allow_register = models.BooleanField(_("Don't allow users to self-register"), default = False) |
6 | - maintence = models.BooleanField(_("Put system in maintence mode"), default = False) | |
6 | + maintence = models.BooleanField(_("Put system in maintenance mode"), default = False) | |
7 | 7 | |
8 | 8 | class Meta: |
9 | 9 | verbose_name = _('Security configuration') | ... | ... |
users/views.py
... | ... | @@ -9,6 +9,8 @@ from django.db.models import Q |
9 | 9 | |
10 | 10 | from braces import views as braces_mixins |
11 | 11 | |
12 | +from security.models import Security | |
13 | + | |
12 | 14 | from .models import User |
13 | 15 | from .utils import has_dependencies |
14 | 16 | from .forms import RegisterUserForm, ProfileForm, UserForm, ChangePassForm, PassResetRequest, SetPasswordForm |
... | ... | @@ -404,16 +406,21 @@ def login(request): |
404 | 406 | username = request.POST['email'] |
405 | 407 | password = request.POST['password'] |
406 | 408 | user = authenticate(username=username, password=password) |
409 | + security = Security.objects.get(id = 1) | |
410 | + | |
407 | 411 | if user is not None: |
408 | - login_user(request, user) | |
409 | - return redirect(reverse("home")) | |
412 | + if not security.maintence or user.is_staff: | |
413 | + login_user(request, user) | |
414 | + return redirect(reverse("home")) | |
415 | + else: | |
416 | + messages.error(request, _('System under maintenance. Try again later')) | |
410 | 417 | else: |
411 | 418 | messages.error(request, _('E-mail or password are incorrect.')) |
412 | 419 | context["username"] = username |
413 | 420 | elif request.user.is_authenticated: |
414 | 421 | return redirect(reverse('home')) |
415 | 422 | |
416 | - return render(request,"users/login.html",context) | |
423 | + return render(request, "users/login.html", context) | |
417 | 424 | |
418 | 425 | |
419 | 426 | # API VIEWS | ... | ... |