2023-10-03 03:47:00 +00:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
2023-09-26 07:15:28 +00:00
|
|
|
from django.shortcuts import render
|
2023-10-03 03:47:00 +00:00
|
|
|
from django.urls import reverse
|
2023-09-28 09:01:14 +00:00
|
|
|
|
2023-10-03 03:47:00 +00:00
|
|
|
from .models import AppUser
|
|
|
|
from .forms import UserForm
|
2023-09-28 09:01:14 +00:00
|
|
|
from django.shortcuts import redirect, render
|
2023-10-03 03:47:00 +00:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
|
2023-09-28 09:01:14 +00:00
|
|
|
|
|
|
|
def index(request):
|
|
|
|
return redirect("/user")
|
|
|
|
|
|
|
|
|
2023-10-03 03:47:00 +00:00
|
|
|
@login_required
|
2023-09-28 09:01:14 +00:00
|
|
|
def user(request):
|
2023-10-03 03:47:00 +00:00
|
|
|
current_user: AppUser = request.user.appuser
|
|
|
|
if request.method == "POST":
|
|
|
|
form = UserForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
cdata = form.cleaned_data
|
|
|
|
current_user.django_user.first_name = cdata['first_name']
|
|
|
|
current_user.save()
|
|
|
|
current_user.django_user.save()
|
|
|
|
return HttpResponseRedirect(reverse("user"))
|
|
|
|
else:
|
|
|
|
return render(request, "idhub/user-details.html", {"form": form})
|
|
|
|
elif request.method == "GET":
|
|
|
|
form = UserForm.from_user(current_user)
|
|
|
|
return render(request, "idhub/user-details.html", {"form": form})
|