forked from GithubBackups/healthchecks
Account creation
This commit is contained in:
parent
c8b24495b9
commit
7997879bd8
@ -1,5 +1,11 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
|
|
||||||
|
class LowercaseEmailField(forms.EmailField):
|
||||||
|
def clean(self, value):
|
||||||
|
value = super(LowercaseEmailField, self).clean(value)
|
||||||
|
return value.lower()
|
||||||
|
|
||||||
|
|
||||||
class EmailForm(forms.Form):
|
class EmailForm(forms.Form):
|
||||||
email = forms.EmailField()
|
email = LowercaseEmailField()
|
||||||
|
@ -3,6 +3,7 @@ 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'^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"),
|
||||||
|
@ -11,14 +11,41 @@ from django.shortcuts import redirect, render
|
|||||||
from hc.accounts.forms import EmailForm
|
from hc.accounts.forms import EmailForm
|
||||||
|
|
||||||
|
|
||||||
def login(request):
|
def create(request):
|
||||||
|
assert request.method == "POST"
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
def login(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# create a form instance and populate it with data from the request:
|
|
||||||
form = EmailForm(request.POST)
|
form = EmailForm(request.POST)
|
||||||
# check whether it's valid:
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
email = form.cleaned_data["email"]
|
email = form.cleaned_data["email"].lower()
|
||||||
user = User.objects.get(email=email)
|
user = User.objects.get(email=email)
|
||||||
|
|
||||||
# We don't want to reset passwords of staff users :-)
|
# We don't want to reset passwords of staff users :-)
|
||||||
@ -36,16 +63,12 @@ def login(request):
|
|||||||
send_mail('Log In', body, 'cuu508@gmail.com', [email],
|
send_mail('Log In', body, 'cuu508@gmail.com', [email],
|
||||||
fail_silently=False)
|
fail_silently=False)
|
||||||
|
|
||||||
# FIXME send login token here
|
|
||||||
return redirect("hc-login-link-sent")
|
return redirect("hc-login-link-sent")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
form = EmailForm()
|
form = EmailForm()
|
||||||
|
|
||||||
ctx = {
|
ctx = {"form": form}
|
||||||
"form": form
|
|
||||||
}
|
|
||||||
|
|
||||||
return render(request, "accounts/login.html", ctx)
|
return render(request, "accounts/login.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,5 +3,6 @@ from django.conf.urls import url
|
|||||||
from hc.front import views
|
from hc.front import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
url(r'^$', views.index, name="hc-index"),
|
||||||
url(r'^checks/$', views.checks, name="hc-checks"),
|
url(r'^checks/$', views.checks, name="hc-checks"),
|
||||||
]
|
]
|
||||||
|
@ -3,6 +3,11 @@ from django.shortcuts import render
|
|||||||
|
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
|
|
||||||
|
|
||||||
|
def index(request):
|
||||||
|
return render(request, "index.html")
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def checks(request):
|
def checks(request):
|
||||||
|
|
||||||
@ -12,4 +17,4 @@ def checks(request):
|
|||||||
"checks": checks
|
"checks": checks
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, "checks/index.html", ctx)
|
return render(request, "front/index.html", ctx)
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>
|
|
||||||
<div class="input-group input-group-lg">
|
<div class="input-group input-group-lg">
|
||||||
<div class="input-group-addon">@</div>
|
<div class="input-group-addon">@</div>
|
||||||
<input
|
<input
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<h1>Hello World</h1>
|
<h1>Hello {{ request.user.email }}</h1>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Code</th>
|
<th>Code</th>
|
33
templates/index.html
Normal file
33
templates/index.html
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<h1>Hello World</h1>
|
||||||
|
|
||||||
|
<h2>Get started here:</h2>
|
||||||
|
<form action="{% url 'hc-create-account' %}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="input-group input-group-lg">
|
||||||
|
<div class="input-group-addon">@</div>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
class="form-control"
|
||||||
|
id="id_email"
|
||||||
|
name="email"
|
||||||
|
placeholder="Email">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="clearfix">
|
||||||
|
<button type="submit" class="btn btn-lg btn-primary pull-right">
|
||||||
|
Get Started
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user