Ejemplo n.º 1
0
def add_assistant_save(request):
    if request.method != 'POST':
        return HttpResponse("Method Not Allowed")
    else:
        form = CreateUserForm(request.POST)
        if form.is_valid():
            first_name = request.POST.get('first_name')
            last_name = request.POST.get('last_name')
            email = request.POST.get('email')

            company = Companies.objects.get(
                id=request.user.managers.company_id_id)
            user = CustomUser.objects.create_user(username=email,
                                                  email=email,
                                                  last_name=last_name,
                                                  first_name=first_name,
                                                  user_type=3)
            user.set_password(CustomUser.objects.make_random_password())
            user.assistants.company_id_id = company.id
            user.save()

            send_activation_email(request, user)

            messages.success(request,
                             "Dodanie użytkownika zakończone powodzeniem")
            return HttpResponseRedirect(reverse("manage_assistant"))
        else:
            form = CreateUserForm(request.POST)
            messages.error(request,
                           "Dodanie użytkownika zakończone niepowodzeniem")
            return render(request,
                          'manager_template/add_assistant_template.html',
                          {"form": form})
Ejemplo n.º 2
0
def do_admin_signup(request):
    if request.method != 'POST':
        return HttpResponse("Method Not Allowed")
    else:

        form = CreateUserForm(request.POST)
        if form.is_valid():
            first_name = request.POST.get('first_name')
            last_name = request.POST.get('last_name')
            email = request.POST.get('email')
            password = request.POST.get('password')
            confirm_password = request.POST.get('confirm_password')

            user = CustomUser.objects.create_user(username=email,
                                                  password=password,
                                                  first_name=first_name,
                                                  last_name=last_name,
                                                  email=email,
                                                  user_type=1)
            user.save()

            messages.success(
                request,
                "Rejestracja zakończona sukcesem. Możesz się zalogować")
            return HttpResponseRedirect(reverse("signup_admin"))

        else:
            form = CreateUserForm(request.POST)
            return render(request, 'signup_admin_page.html', {"form": form})