You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.0 KiB
32 lines
1.0 KiB
from django.views.generic import FormView, View
|
|
from django.http import JsonResponse
|
|
from django.contrib.auth import get_user_model, logout
|
|
|
|
from .forms import LearnerRegistrationForm
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class LearnerRegistrationView(FormView):
|
|
form_class = LearnerRegistrationForm
|
|
template_name = "auth/registration-learner.html"
|
|
|
|
def form_valid(self, form):
|
|
first_name = form.cleaned_data['first_name']
|
|
last_name = form.cleaned_data['last_name']
|
|
email = form.cleaned_data['email']
|
|
password = form.cleaned_data['password']
|
|
|
|
User.objects.create_user(username=email, email=email, first_name=first_name, last_name=last_name, password=password)
|
|
|
|
return JsonResponse({"success": True}, status=201)
|
|
|
|
def form_invalid(self, form):
|
|
return JsonResponse(form.errors.get_json_data(escape_html=True), status=400)
|
|
|
|
|
|
class LogoutView(View):
|
|
def post(self, request, *args, **kwargs):
|
|
logout(request)
|
|
return JsonResponse({"success": True})
|
|
|