forked from GithubBackups/healthchecks
logout, unified login
This commit is contained in:
parent
a1bfed5d89
commit
7876da2c9e
@ -3,8 +3,8 @@ from django.conf.urls import url
|
|||||||
from hc.accounts import views
|
from hc.accounts import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^create/$', views.create, name="hc-create-account"),
|
|
||||||
url(r'^login/$', views.login, name="hc-login"),
|
url(r'^login/$', views.login, name="hc-login"),
|
||||||
|
url(r'^logout/$', views.logout, name="hc-logout"),
|
||||||
url(r'^login_link_sent/$', views.login_link_sent, name="hc-login-link-sent"),
|
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"),
|
url(r'^check_token/([\w-]+)/([\w-]+)/$', views.check_token, name="hc-check-token"),
|
||||||
]
|
]
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import authenticate, login as auth_login
|
from django.contrib.auth import authenticate
|
||||||
|
from django.contrib.auth import login as auth_login, logout as auth_logout
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
@ -11,42 +12,23 @@ from django.shortcuts import redirect, render
|
|||||||
from hc.accounts.forms import EmailForm
|
from hc.accounts.forms import EmailForm
|
||||||
|
|
||||||
|
|
||||||
def create(request):
|
def _make_user(email):
|
||||||
assert request.method == "POST"
|
username = str(uuid.uuid4())[:30]
|
||||||
|
user = User(username=username, email=email)
|
||||||
|
user.save()
|
||||||
|
|
||||||
form = EmailForm(request.POST)
|
return user
|
||||||
if form.is_valid():
|
|
||||||
email = form.cleaned_data["email"]
|
|
||||||
|
|
||||||
num_existing = User.objects.filter(email=email).count()
|
|
||||||
if num_existing > 0:
|
|
||||||
# FIXME be more polite about this
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
username = str(uuid.uuid4())[:30]
|
|
||||||
temp_password = str(uuid.uuid4())
|
|
||||||
|
|
||||||
user = User(username=username, email=email)
|
|
||||||
user.set_password(temp_password)
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
user = authenticate(username=username, password=temp_password)
|
|
||||||
user.set_unusable_password()
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
auth_login(request, user)
|
|
||||||
return redirect("hc-checks")
|
|
||||||
|
|
||||||
# FIXME do something nicer here
|
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = EmailForm(request.POST)
|
form = EmailForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
email = form.cleaned_data["email"].lower()
|
email = form.cleaned_data["email"]
|
||||||
user = User.objects.get(email=email)
|
try:
|
||||||
|
user = User.objects.get(email=email)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
user = _make_user(email)
|
||||||
|
|
||||||
# We don't want to reset passwords of staff users :-)
|
# We don't want to reset passwords of staff users :-)
|
||||||
if user.is_staff:
|
if user.is_staff:
|
||||||
@ -72,6 +54,11 @@ def login(request):
|
|||||||
return render(request, "accounts/login.html", ctx)
|
return render(request, "accounts/login.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
def logout(request):
|
||||||
|
auth_logout(request)
|
||||||
|
return redirect("hc-index")
|
||||||
|
|
||||||
|
|
||||||
def login_link_sent(request):
|
def login_link_sent(request):
|
||||||
return render(request, "accounts/login_link_sent.html")
|
return render(request, "accounts/login_link_sent.html")
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
@import url("http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css");
|
|
||||||
|
|
||||||
.panel-pricing {
|
.panel-pricing {
|
||||||
-moz-transition: all .3s ease;
|
-moz-transition: all .3s ease;
|
||||||
-o-transition: all .3s ease;
|
-o-transition: all .3s ease;
|
||||||
@ -11,7 +9,7 @@
|
|||||||
.panel-pricing .panel-heading {
|
.panel-pricing .panel-heading {
|
||||||
padding: 20px 10px;
|
padding: 20px 10px;
|
||||||
}
|
}
|
||||||
.panel-pricing .panel-heading .fa {
|
.panel-pricing .panel-heading .glyphicon {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
font-size: 58px;
|
font-size: 58px;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ html, body {
|
|||||||
|
|
||||||
#pitch {
|
#pitch {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 3em;
|
padding: 2em 0 3em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.step-number {
|
.step-number {
|
||||||
@ -16,7 +16,7 @@ html, body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#get-started {
|
#get-started {
|
||||||
margin-top: 3em;
|
margin-top: 4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.glyphicon.up, .glyphicon.new, .glyphicon.down {
|
.glyphicon.up, .glyphicon.new, .glyphicon.down {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6 col-sm-offset-3">
|
<div class="col-sm-6 col-sm-offset-3">
|
||||||
<div id="login_dialog">
|
<div id="login_dialog">
|
||||||
<h1>Hxxx C...</h1>
|
<h1>Health Checks</h1>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Please enter your email address.
|
Please enter your email address.
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>Login link sent, check your inbox!</h1>
|
<div class="row">
|
||||||
|
<div class="col-sm-6 col-sm-offset-3">
|
||||||
|
<div id="login_dialog">
|
||||||
|
<h1>Login Link Sent!</h1>
|
||||||
|
<br />
|
||||||
|
<p>
|
||||||
|
We've sent you an email with login instructions.
|
||||||
|
Please check your inbox!
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<li><a href="#">{{ request.user.email }}</a></li>
|
<li><a href="#">{{ request.user.email }}</a></li>
|
||||||
<li><a href="#">Log Out</a></li>
|
<li><a href="{% url 'hc-logout' %}">Log Out</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{% url 'hc-login' %}">Log In</a></li>
|
<li><a href="{% url 'hc-login' %}">Log In</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<h3>Checks and pinging</h3>
|
<h3>Summary</h3>
|
||||||
<p>
|
<p>
|
||||||
Each check you create in <a href="{% url 'hc-checks' %}">My Checks</a>
|
Each check you create in <a href="{% url 'hc-checks' %}">My Checks</a>
|
||||||
page has an unique "ping" URL. Whenever you access this URL,
|
page has an unique "ping" URL. Whenever you access this URL,
|
||||||
@ -14,12 +14,10 @@
|
|||||||
check is considered "late", and Health Checks sends an email notification.
|
check is considered "late", and Health Checks sends an email notification.
|
||||||
It is all very simple, really.</p>
|
It is all very simple, really.</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Executing a ping</h3>
|
<h3>Executing a ping</h3>
|
||||||
<p>
|
<p>
|
||||||
At the end of your batch job, add a bit of code to ping
|
At the end of your batch job, add a bit of code to request
|
||||||
one of your checks.
|
one of your ping URLs.
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>HTTP and HTTPS protocols both are fine</li>
|
<li>HTTP and HTTPS protocols both are fine</li>
|
||||||
@ -41,6 +39,8 @@ wget https://healthchecks.io/ping/b2012751-c542-4deb-b054-ff51322102b9/
|
|||||||
<h3>When notifications are sent</h3>
|
<h3>When notifications are sent</h3>
|
||||||
<p>
|
<p>
|
||||||
Each check has a configurable "Frequency" parameter, with default value of <strong>one day</strong>.
|
Each check has a configurable "Frequency" parameter, with default value of <strong>one day</strong>.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
When time since last ping exceeds the configured amount, the check is considered late.
|
When time since last ping exceeds the configured amount, the check is considered late.
|
||||||
When a check is <strong>1 hour late</strong>, Health Checks sends you an email notification.
|
When a check is <strong>1 hour late</strong>, Health Checks sends you an email notification.
|
||||||
</p>
|
</p>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<h1>My Checks</h1>
|
<h1>My Checks</h1>
|
||||||
|
{% if checks %}
|
||||||
<table id="checks-table" class="table table-hover">
|
<table id="checks-table" class="table table-hover">
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
@ -12,7 +13,6 @@
|
|||||||
<th>URL</th>
|
<th>URL</th>
|
||||||
<th>Frequency</th>
|
<th>Frequency</th>
|
||||||
<th>Last Ping</th>
|
<th>Last Ping</th>
|
||||||
<th></th>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% for check in checks %}
|
{% for check in checks %}
|
||||||
<tr class="checks-row">
|
<tr class="checks-row">
|
||||||
@ -95,13 +95,13 @@
|
|||||||
Never
|
Never
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<a class="setup-link" href="#">Setup Instructions</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<div class="alert alert-info">You don't have any checks yet.</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
<div id="get-started" class="col-sm-6 col-sm-offset-3">
|
<div id="get-started" class="col-sm-6 col-sm-offset-3">
|
||||||
<h3>E-mail Address to Receive Notifications:</h3>
|
<h3>E-mail Address to Receive Notifications:</h3>
|
||||||
<form action="{% url 'hc-create-account' %}" method="post">
|
<form action="{% url 'hc-login' %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<div class="col-md-4 text-center col-md-offset-4">
|
<div class="col-md-4 text-center col-md-offset-4">
|
||||||
<div class="panel panel-success panel-pricing">
|
<div class="panel panel-success panel-pricing">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<i class="fa fa-desktop"></i>
|
<i class="glyphicon glyphicon-heart-empty"></i>
|
||||||
<h3>Free Plan</h3>
|
<h3>Free Plan</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body text-center">
|
<div class="panel-body text-center">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user