Browse Source

/admin/login/ uses the same login view as the main site.

pull/114/head
Pēteris Caune 8 years ago
parent
commit
a4bcbb28aa
4 changed files with 15 additions and 9 deletions
  1. +2
    -5
      hc/accounts/backends.py
  2. +4
    -2
      hc/accounts/views.py
  3. +3
    -0
      hc/urls.py
  4. +6
    -2
      templates/accounts/login.html

+ 2
- 5
hc/accounts/backends.py View File

@ -17,8 +17,8 @@ class ProfileBackend(BasicBackend):
def authenticate(self, username=None, token=None):
try:
profile = (Profile.objects
.select_related("user").get(user__username=username))
profiles = Profile.objects.select_related("user")
profile = profiles.get(user__username=username)
except Profile.DoesNotExist:
return None
@ -27,9 +27,6 @@ class ProfileBackend(BasicBackend):
return profile.user
def get_user(self, user_id):
return User.objects.filter(pk=user_id).first()
class EmailBackend(BasicBackend):


+ 4
- 2
hc/accounts/views.py View File

@ -59,7 +59,7 @@ def _associate_demo_check(request, user):
del request.session["welcome_code"]
def login(request):
def login(request, show_password=False):
bad_credentials = False
if request.method == 'POST':
form = EmailPasswordForm(request.POST)
@ -72,6 +72,7 @@ def login(request):
auth_login(request, user)
return redirect("hc-checks")
bad_credentials = True
show_password = True
else:
try:
user = User.objects.get(email=email)
@ -89,7 +90,8 @@ def login(request):
ctx = {
"form": form,
"bad_credentials": bad_credentials,
"bad_link": bad_link
"bad_link": bad_link,
"show_password": show_password
}
return render(request, "accounts/login.html", ctx)


+ 3
- 0
hc/urls.py View File

@ -1,7 +1,10 @@
from django.conf.urls import include, url
from django.contrib import admin
from hc.accounts.views import login as hc_login
urlpatterns = [
url(r'^admin/login/', hc_login, {"show_password": True}),
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('hc.accounts.urls')),
url(r'^', include('hc.api.urls')),


+ 6
- 2
templates/accounts/login.html View File

@ -15,8 +15,12 @@
<h1>Health Checks</h1>
<div class="dialog-body">
<p>
{% if show_password %}
Please entery your email address and password.
{% else %}
Please enter your email address.
Next, we'll send you an email with log-in instructions!
{% endif %}
</p>
</div>
{% endif %}
@ -43,7 +47,7 @@
</div>
</div>
{% if not bad_credentials %}
{% if not show_password %}
<div class="checkbox" id="password-toggle">
<label>
<input type="checkbox"> I want to use a password
@ -52,7 +56,7 @@
{% endif %}
<div id="password-block" class="form-group {% if not bad_credentials %} hide {% endif %}">
<div id="password-block" class="form-group {% if not show_password %} hide {% endif %}">
<div class="input-group input-group-lg">
<div class="input-group-addon">
<span class="icon-dots"></span>


Loading…
Cancel
Save