Browse Source

Account creation

pull/7/head
Pēteris Caune 10 years ago
parent
commit
7997879bd8
8 changed files with 81 additions and 13 deletions
  1. +7
    -1
      hc/accounts/forms.py
  2. +1
    -0
      hc/accounts/urls.py
  3. +32
    -9
      hc/accounts/views.py
  4. +1
    -0
      hc/front/urls.py
  5. +6
    -1
      hc/front/views.py
  6. +0
    -1
      templates/accounts/login.html
  7. +1
    -1
      templates/front/index.html
  8. +33
    -0
      templates/index.html

+ 7
- 1
hc/accounts/forms.py View File

@ -1,5 +1,11 @@
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):
email = forms.EmailField()
email = LowercaseEmailField()

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

@ -3,6 +3,7 @@ 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'^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"),


+ 32
- 9
hc/accounts/views.py View File

@ -11,14 +11,41 @@ from django.shortcuts import redirect, render
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':
# create a form instance and populate it with data from the request:
form = EmailForm(request.POST)
# check whether it's valid:
if form.is_valid():
email = form.cleaned_data["email"]
email = form.cleaned_data["email"].lower()
user = User.objects.get(email=email)
# We don't want to reset passwords of staff users :-)
@ -36,16 +63,12 @@ def login(request):
send_mail('Log In', body, '[email protected]', [email],
fail_silently=False)
# FIXME send login token here
return redirect("hc-login-link-sent")
else:
form = EmailForm()
ctx = {
"form": form
}
ctx = {"form": form}
return render(request, "accounts/login.html", ctx)


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

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

+ 6
- 1
hc/front/views.py View File

@ -3,6 +3,11 @@ from django.shortcuts import render
from hc.api.models import Check
def index(request):
return render(request, "index.html")
@login_required
def checks(request):
@ -12,4 +17,4 @@ def checks(request):
"checks": checks
}
return render(request, "checks/index.html", ctx)
return render(request, "front/index.html", ctx)

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

@ -15,7 +15,6 @@
{% csrf_token %}
<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-addon">@</div>
<input


templates/checks/index.html → templates/front/index.html View File


+ 33
- 0
templates/index.html View 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…
Cancel
Save