Browse Source

Login works, stubbed out canary index page

pull/7/head
Pēteris Caune 10 years ago
parent
commit
a965f4c605
14 changed files with 101 additions and 10 deletions
  1. +3
    -3
      hc/accounts/urls.py
  2. +14
    -4
      hc/accounts/views.py
  3. +0
    -0
      hc/front/__init__.py
  4. +3
    -0
      hc/front/admin.py
  5. +0
    -0
      hc/front/migrations/__init__.py
  6. +3
    -0
      hc/front/models.py
  7. +3
    -0
      hc/front/tests.py
  8. +7
    -0
      hc/front/urls.py
  9. +15
    -0
      hc/front/views.py
  10. +11
    -2
      hc/settings.py
  11. +1
    -0
      hc/urls.py
  12. +3
    -1
      requirements.txt
  13. +15
    -0
      templates/bad_link.html
  14. +23
    -0
      templates/checks/index.html

+ 3
- 3
hc/accounts/urls.py View File

@ -3,7 +3,7 @@ from django.conf.urls import url
from hc.accounts import views
urlpatterns = [
url(r'^login/$', views.login, name="hc-login"),
url(r'^login_link_sent/$', views.login_link_sent, name="hc-login-link-sent"),
url(r'^check_token/([\w-]+)/$', views.check_token, name="hc-check-token"),
url(r'^login/$', views.login, name="hc-login"),
url(r'^login_link_sent/$', views.login_link_sent, name="hc-login-link-sent"),
url(r'^check_token/([\w-]+)/([\w-]+)/$', views.check_token, name="hc-check-token"),
]

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

@ -1,6 +1,7 @@
import uuid
from django.conf import settings
from django.contrib.auth import authenticate, login as auth_login
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
@ -22,11 +23,12 @@ def login(request):
user.set_password(token)
user.save()
login_link = reverse("hc-check-token", args=[token])
login_link = reverse("hc-check-token", args=[user.username, token])
login_link = settings.SITE_ROOT + login_link
body = "login link: %s" % login_link
send_mail('Log In', body, '[email protected]', [email], fail_silently=False)
send_mail('Log In', body, '[email protected]', [email],
fail_silently=False)
# FIXME send login token here
return redirect("hc-login-link-sent")
@ -45,5 +47,13 @@ def login_link_sent(request):
return render(request, "accounts/login_link_sent.html")
def check_token(request):
return render(request, "accounts/login_link_sent.html")
def check_token(request, username, token):
user = authenticate(username=username, password=token)
if user is not None:
if user.is_active:
user.set_unusable_password()
user.save()
auth_login(request, user)
return redirect("hc-checks")
return render(request, "bad_link.html")

+ 0
- 0
hc/front/__init__.py View File


+ 3
- 0
hc/front/admin.py View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

+ 0
- 0
hc/front/migrations/__init__.py View File


+ 3
- 0
hc/front/models.py View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

+ 3
- 0
hc/front/tests.py View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

+ 7
- 0
hc/front/urls.py View File

@ -0,0 +1,7 @@
from django.conf.urls import url
from hc.front import views
urlpatterns = [
url(r'^checks/$', views.checks, name="hc-checks"),
]

+ 15
- 0
hc/front/views.py View File

@ -0,0 +1,15 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from hc.checks.models import Canary
@login_required
def checks(request):
canaries = Canary.objects.filter(user=request.user)
ctx = {
"canaries": canaries
}
return render(request, "checks/index.html", ctx)

+ 11
- 2
hc/settings.py View File

@ -10,11 +10,12 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import json
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
hc_config = json.loads(open(os.path.expanduser("~/hc_config.json")).read())
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
@ -39,7 +40,8 @@ INSTALLED_APPS = (
'django.contrib.staticfiles',
'hc.accounts',
'hc.checks'
'hc.checks',
'hc.front'
)
MIDDLEWARE_CLASSES = (
@ -107,3 +109,10 @@ USE_TZ = True
SITE_ROOT = "http://localhost:8000"
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
# AWS
EMAIL_BACKEND = 'django_ses_backend.SESBackend'
AWS_SES_ACCESS_KEY_ID = hc_config["aws_ses_access_key"]
AWS_SES_SECRET_ACCESS_KEY = hc_config["aws_ses_secret_key"]
AWS_SES_REGION_NAME = 'eu-west-1'
AWS_SES_REGION_ENDPOINT = 'email.eu-west-1.amazonaws.com'

+ 1
- 0
hc/urls.py View File

@ -5,4 +5,5 @@ urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^accounts/', include('hc.accounts.urls')),
url(r'^', include('hc.checks.urls')),
url(r'^', include('hc.front.urls')),
]

+ 3
- 1
requirements.txt View File

@ -1,2 +1,4 @@
Django==1.8.2
psycopg2==2.6
django-ses
psycopg2==2.6
django-ses-backend

+ 15
- 0
templates/bad_link.html View File

@ -0,0 +1,15 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<div id="login_dialog">
<h1>Server Error</h1>
<p>
Something bad happened and you should feel bad.
</p>
</div>
</div>
</div>
{% endblock %}

+ 23
- 0
templates/checks/index.html View File

@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<h1>Hello World</h1>
<table class="table">
<tr>
<th>Code</th>
<th>Last Ping</th>
</tr>
{% for canary in canaries %}
<tr>
<td>{{ canary.code }}</td>
<td>{{ canary.last_ping }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}

Loading…
Cancel
Save