aboutsummaryrefslogtreecommitdiff
path: root/accounts/views.py
blob: aafcfb60701d163f1f3f3250e621317fe7ed7ec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required

from accounts.forms import UserCreationForm


@login_required
def profile(request):
    return render(request, "accounts/profile.html")


def create_account(request):
    form = UserCreationForm()

    if request.method == "POST":
        form = UserCreationForm(request.POST)

        if form.is_valid():
            form.save()

            user = authenticate(username=form.cleaned_data["username"],
                    password=form.cleaned_data["password1"])
            login(request, user)

            return redirect("account:profile")

    return render(request, "accounts/create.html", {
        "form": form,
    })