Ejemplo n.º 1
0
def register(request):
    """
    Register a new User profile using built in Django Users Model
    """
    privacy = TolaSites.objects.get(id=1)
    if request.method == 'POST':
        uf = NewUserRegistrationForm(request.POST)
        tf = NewTolaUserRegistrationForm(request.POST)

        if uf.is_valid() * tf.is_valid():
            user = uf.save()
            user.groups.add(Group.objects.get(name='ViewOnly'))

            tolauser = tf.save(commit=False)
            tolauser.user = user
            tolauser.save()
            messages.error(request, 'Thank you, You have been registered as a new user.', fail_silently=False)
            return HttpResponseRedirect("/")
    else:
        uf = NewUserRegistrationForm()
        tf = NewTolaUserRegistrationForm()

    return render(request, "registration/register.html", {
        'userform': uf,'tolaform': tf, 'helper': NewTolaUserRegistrationForm.helper,'privacy':privacy
    })
Ejemplo n.º 2
0
def register(request):
    """
    Register a new User profile using built in Django Users Model
    """
    privacy = TolaSites.objects.get(id=1)
    if request.method == 'POST':
        uf = NewUserRegistrationForm(request.POST)
        tf = NewTolaUserRegistrationForm(request.POST)

        if uf.is_valid() * tf.is_valid():
            user = uf.save()
            user.groups.add(Group.objects.get(name='ViewOnly'))

            tolauser = tf.save(commit=False)
            tolauser.user = user
            tolauser.save()
            messages.error(
                request,
                'Thank you, You have been registered as a new user.',
                fail_silently=False)
            return HttpResponseRedirect("/")
    else:
        uf = NewUserRegistrationForm()
        tf = NewTolaUserRegistrationForm()

    return render(
        request, "registration/register.html", {
            'userform': uf,
            'tolaform': tf,
            'helper': NewTolaUserRegistrationForm.helper,
            'privacy': privacy
        })
Ejemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        form_user = NewUserRegistrationForm(request.POST)
        form_tolauser = NewTolaUserRegistrationForm(request.POST)

        if form_user.is_valid() and form_tolauser.is_valid():
            user = form_user.save()
            user.groups.add(Group.objects.get(name=ROLE_VIEW_ONLY))

            tolauser = form_tolauser.save(commit=False)
            tolauser.user = user
            tolauser.organization = form_tolauser.cleaned_data.get('org')
            tolauser.name = ' '.join([user.first_name, user.last_name]).strip()
            tolauser.save()
            self.register_in_track(request, tolauser)
            messages.error(
                request,
                'Thank you, You have been registered as a new user.',
                fail_silently=False)
            return HttpResponseRedirect(reverse('login'))

        context = self._get_context_data(**{
            'form_user': form_user,
            'form_tolauser': form_tolauser,
        })
        return render(request, self.template_name, context)
Ejemplo n.º 4
0
def register(request):
    """
    Register a new User profile using built in Django Users Model
    """
    if request.user.is_superuser:
        form_user = NewUserRegistrationForm(request.POST)
        form_tolauser = NewTolaUserRegistrationForm(request.POST)

        if form_user.is_valid() and form_tolauser.is_valid() and \
                request.POST.get('tola_user_uuid'):
            user = form_user.save()

            tolauser = form_tolauser.save(commit=False)
            tolauser.user = user
            tolauser.organization = form_tolauser.cleaned_data.get('org')
            tolauser.name = ' '.join([user.first_name, user.last_name]).strip()
            tolauser.tola_user_uuid = request.POST.get('tola_user_uuid')
            tolauser.save()
            serializer = TolaUserSerializer(tolauser,
                                            context={'request': request})
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(status=status.HTTP_400_BAD_REQUEST)

    return Response(status=status.HTTP_403_FORBIDDEN)