Browse Source

logout, unified login

pull/7/head
Pēteris Caune 10 years ago
parent
commit
7876da2c9e
11 changed files with 48 additions and 50 deletions
  1. +1
    -1
      hc/accounts/urls.py
  2. +17
    -30
      hc/accounts/views.py
  3. +1
    -3
      static/css/pricing.css
  4. +2
    -2
      static/css/style.css
  5. +1
    -1
      templates/accounts/login.html
  6. +14
    -1
      templates/accounts/login_link_sent.html
  7. +1
    -1
      templates/base.html
  8. +5
    -5
      templates/docs.html
  9. +4
    -4
      templates/front/index.html
  10. +1
    -1
      templates/index.html
  11. +1
    -1
      templates/pricing.html

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

@ -3,8 +3,8 @@ from django.conf.urls import url
from hc.accounts import views
urlpatterns = [
url(r'^create/$', views.create, name="hc-create-account"),
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'^check_token/([\w-]+)/([\w-]+)/$', views.check_token, name="hc-check-token"),
]

+ 17
- 30
hc/accounts/views.py View File

@ -1,7 +1,8 @@
import uuid
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.core.mail import send_mail
from django.core.urlresolvers import reverse
@ -11,42 +12,23 @@ from django.shortcuts import redirect, render
from hc.accounts.forms import EmailForm
def create(request):
assert request.method == "POST"
def _make_user(email):
username = str(uuid.uuid4())[:30]
user = User(username=username, email=email)
user.save()
form = EmailForm(request.POST)
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()
return user
def login(request):
if request.method == 'POST':
form = EmailForm(request.POST)
if form.is_valid():
email = form.cleaned_data["email"].lower()
user = User.objects.get(email=email)
email = form.cleaned_data["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 :-)
if user.is_staff:
@ -72,6 +54,11 @@ def login(request):
return render(request, "accounts/login.html", ctx)
def logout(request):
auth_logout(request)
return redirect("hc-index")
def login_link_sent(request):
return render(request, "accounts/login_link_sent.html")


+ 1
- 3
static/css/pricing.css View File

@ -1,5 +1,3 @@
@import url("http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css");
.panel-pricing {
-moz-transition: all .3s ease;
-o-transition: all .3s ease;
@ -11,7 +9,7 @@
.panel-pricing .panel-heading {
padding: 20px 10px;
}
.panel-pricing .panel-heading .fa {
.panel-pricing .panel-heading .glyphicon {
margin-top: 10px;
font-size: 58px;
}


+ 2
- 2
static/css/style.css View File

@ -4,7 +4,7 @@ html, body {
#pitch {
text-align: center;
padding: 3em;
padding: 2em 0 3em 0;
}
.step-number {
@ -16,7 +16,7 @@ html, body {
}
#get-started {
margin-top: 3em;
margin-top: 4em;
}
.glyphicon.up, .glyphicon.new, .glyphicon.down {


+ 1
- 1
templates/accounts/login.html View File

@ -4,7 +4,7 @@
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<div id="login_dialog">
<h1>Hxxx C...</h1>
<h1>Health Checks</h1>
<p>
Please enter your email address.


+ 14
- 1
templates/accounts/login_link_sent.html View File

@ -1,5 +1,18 @@
{% extends "base.html" %}
{% 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 %}

+ 1
- 1
templates/base.html View File

@ -43,7 +43,7 @@
<ul class="nav navbar-nav navbar-right">
{% if request.user.is_authenticated %}
<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 %}
<li><a href="{% url 'hc-login' %}">Log In</a></li>
{% endif %}


+ 5
- 5
templates/docs.html View File

@ -4,7 +4,7 @@
{% block content %}
<div class="row">
<div class="col-sm-12">
<h3>Checks and pinging</h3>
<h3>Summary</h3>
<p>
Each check you create in <a href="{% url 'hc-checks' %}">My Checks</a>
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.
It is all very simple, really.</p>
<h3>Executing a ping</h3>
<p>
At the end of your batch job, add a bit of code to ping
one of your checks.
At the end of your batch job, add a bit of code to request
one of your ping URLs.
</p>
<ul>
<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>
<p>
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 a check is <strong>1 hour late</strong>, Health Checks sends you an email notification.
</p>


+ 4
- 4
templates/front/index.html View File

@ -5,6 +5,7 @@
<div class="row">
<div class="col-sm-12">
<h1>My Checks</h1>
{% if checks %}
<table id="checks-table" class="table table-hover">
<tr>
<th></th>
@ -12,7 +13,6 @@
<th>URL</th>
<th>Frequency</th>
<th>Last Ping</th>
<th></th>
</tr>
{% for check in checks %}
<tr class="checks-row">
@ -95,13 +95,13 @@
Never
{% endif %}
</td>
<td>
<a class="setup-link" href="#">Setup Instructions</a>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<div class="alert alert-info">You don't have any checks yet.</div>
{% endif %}
</div>
</div>
<div class="row">


+ 1
- 1
templates/index.html View File

@ -50,7 +50,7 @@
<div id="get-started" class="col-sm-6 col-sm-offset-3">
<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 %}
<div class="form-group">


+ 1
- 1
templates/pricing.html View File

@ -12,7 +12,7 @@
<div class="col-md-4 text-center col-md-offset-4">
<div class="panel panel-success panel-pricing">
<div class="panel-heading">
<i class="fa fa-desktop"></i>
<i class="glyphicon glyphicon-heart-empty"></i>
<h3>Free Plan</h3>
</div>
<div class="panel-body text-center">


Loading…
Cancel
Save