Beispiel #1
0
def signup_view(request):
    form = SignUpForm()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        user = form.save()
        user.set_password(user.password)
        user.save()
        return HttpResponseRedirect('/accounts/login')
    return render(request, 'authapp/signup.html', {'form': form})
Beispiel #2
0
def editar(request, id):
    empleado = get_object_or_404(Empleado, id=id)
    usuario = get_object_or_404(User, id=empleado.user_id)
    if request.POST:  # If the form has been submitted...
        form = SignUpForm(request.POST, instance=usuario)  # A form bound to the POST data
        empleado_form = EmpleadoForm(request.POST, instance=empleado)
        if form.is_valid() and empleado_form.is_valid():  # All validation rules pass

            # Process the data in form.cleaned_data
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            email = form.cleaned_data["email"]
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]
            is_staff = form.cleaned_data["is_staff"]

            usuario.username = username
            usuario.set_password(password)
            usuario.email = email
            usuario.first_name = first_name
            usuario.last_name = last_name
            usuario.is_staff = is_staff
            # At this point, user is a User object that has already been saved
            # to the database. You can continue to change its attributes
            # if you want to change other fields

            # Save new user attributes
            usuario.save()

            empleado = empleado_form.save(commit=False)
            empleado.user = usuario
            empleado.save()

            return HttpResponseRedirect('/empleados')  # Redirect after POST
    else:
        form = SignUpForm(instance=usuario)
        empleado_form = EmpleadoForm(instance=empleado)
        #form.fields['password'].widget.attrs['disabled'] = True
    data = {
        'form': form, 'empleado_form': empleado_form
    }
    return render_to_response('authapp/signup.html', data, context_instance=RequestContext(request))
Beispiel #3
0
def signup(request):
    if request.POST:  # If the form has been submitted...
        form = SignUpForm(request.POST)  # A form bound to the POST data
        empleado_form = EmpleadoForm(request.POST)
        if form.is_valid() and empleado_form.is_valid():  # All validation rules pass

            # Process the data in form.cleaned_data
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            email = form.cleaned_data["email"]
            first_name = form.cleaned_data["first_name"]
            last_name = form.cleaned_data["last_name"]
            is_staff = form.cleaned_data["is_staff"]

            # At this point, user is a User object that has already been saved
            # to the database. You can continue to change its attributes
            # if you want to change other fields.
            user = User.objects.create_user(username, email, password)
            user.first_name = first_name
            user.last_name = last_name
            user.is_staff = is_staff

            # Save new user attributes
            user.save()

            empleado = empleado_form.save(commit=False)
            empleado.user = user
            empleado.save()

            return HttpResponseRedirect('/empleados')  # Redirect after POST
    else:
        form = SignUpForm()
        empleado_form = EmpleadoForm(request.POST)

    data = {
        'form': form, 'empleado_form': empleado_form
    }
    return render_to_response('authapp/signup.html', data, context_instance=RequestContext(request))
Beispiel #4
0
def register(request):
    title = 'Регистрация'
    if request.user.is_authenticated:
        if request.user.is_staff:
            return HttpResponseRedirect(
                reverse("staff_profile", kwargs={'page': 1}))
        else:
            return HttpResponseRedirect(
                reverse('bids_list_work',
                        kwargs={
                            'pk': request.user.pk,
                            'page': 1
                        }))

    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            account = form.save()
            account.save()
            username = request.POST['username']
            password = request.POST['password1']
            user = auth.authenticate(username=username, password=password)
            if user.is_superuser:
                reverse_lazy('admin')
            auth.login(request, user)
            send_mail(
                '{}'.format(title),
                'Пользователь с почтой {} и номером {} зарегистрировался'.
                format(username, request.POST['telephone_num']),
                settings.EMAIL_HOST_USER,
                [settings.EMAIL_HOST_USER],
                fail_silently=False,
            )
            return HttpResponseRedirect(
                reverse('create', kwargs={'pk': request.user.pk}))
        else:
            content = {'title': title, 'form': form}
            return render(request, 'authapp/index.html', content)
    else:
        form = SignUpForm()
        content = {'title': title, 'form': form}
        return render(request, 'authapp/index.html', content)
Beispiel #5
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save(commit=False)
            user.is_active = False
            user.save()

            current_site = get_current_site(request)
            subject = 'Activate Your MySite Account'
            message = render_to_string(
                'authapp/account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)

            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'authapp/signup.html', {'form': form})