mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-08 06:30:05 +00:00
Login works, stubbed out canary index page
This commit is contained in:
parent
08a3717ad7
commit
a965f4c605
14 changed files with 101 additions and 10 deletions
|
@ -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"),
|
||||
]
|
||||
|
|
|
@ -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, 'cuu508@gmail.com', [email], fail_silently=False)
|
||||
send_mail('Log In', body, 'cuu508@gmail.com', [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
hc/front/__init__.py
Normal file
0
hc/front/__init__.py
Normal file
3
hc/front/admin.py
Normal file
3
hc/front/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
0
hc/front/migrations/__init__.py
Normal file
0
hc/front/migrations/__init__.py
Normal file
3
hc/front/models.py
Normal file
3
hc/front/models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
3
hc/front/tests.py
Normal file
3
hc/front/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
7
hc/front/urls.py
Normal file
7
hc/front/urls.py
Normal 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
hc/front/views.py
Normal file
15
hc/front/views.py
Normal 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)
|
|
@ -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'
|
||||
|
|
|
@ -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')),
|
||||
]
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
Django==1.8.2
|
||||
psycopg2==2.6
|
||||
django-ses
|
||||
psycopg2==2.6
|
||||
django-ses-backend
|
15
templates/bad_link.html
Normal file
15
templates/bad_link.html
Normal 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
templates/checks/index.html
Normal file
23
templates/checks/index.html
Normal 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…
Add table
Reference in a new issue