Example #1
0
def register(request):
    unidades = Empresa.objects.all().order_by('nome_fantasia')

    if request.method == 'POST':
        user_form = RegistroForm(request.POST)

        if user_form.is_valid():
            User.objects.create_user(
                username=user_form.cleaned_data['username'],
                password=user_form.cleaned_data['password'],
                email=user_form.cleaned_data['email'],
                first_name=user_form.cleaned_data['first_name'],
                # last_name=user_form.cleaned_data['last_name'],
                is_active=False,
            )

            id = request.POST['SelectUnidade']
            empresa = get_object_or_404(Empresa, id=id)

            usuario = get_object_or_404(
                User, username=user_form.cleaned_data['username'])

            profile = UserProfile()
            profile.user = usuario
            profile.empresa = empresa
            profile.siape = int(request.POST['username'])

            profile.save()

            email = []
            email_user = []

            email.append(empresa.email_responsavel_sistema)
            email_user.append(usuario.email)

            ResponsavelUsuarioMail(usuario).send(email)
            RegistraUsuarioMail(usuario).send(email_user)

            return redirect('login_register_success')

    user_form = RegistroForm()

    context = {'user_form': user_form, 'unidades': unidades}
    return render(request, 'registration/login.html', context)
Example #2
0
def my_data(request):
    user = User.objects.get(pk=request.user.pk)
    user_form = UserForm(instance=user)

    try:
        user_profile = UserProfile.objects.get(user=user)
    except:
        user_profile = UserProfile()
        user_profile.user = user
        user_profile.save()

    profile_form = UserProfileForm(instance=user_profile)

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user.first_name = user_form.cleaned_data['first_name']
            user.last_name = user_form.cleaned_data['last_name']
            user.save()

            user_profile.cpf = profile_form.cleaned_data['cpf']
            user_profile.address = profile_form.cleaned_data['address']
            user_profile.number = profile_form.cleaned_data['number']
            user_profile.address2 = profile_form.cleaned_data['address2']
            user_profile.city = profile_form.cleaned_data['city']
            user_profile.district = profile_form.cleaned_data['district']
            user_profile.state = profile_form.cleaned_data['state']
            user_profile.country = profile_form.cleaned_data['country']
            user_profile.zipcode = profile_form.cleaned_data['zipcode']
            user_profile.phone = profile_form.cleaned_data['phone']
            user_profile.remote_receiver_id = profile_form.cleaned_data[
                'remote_receiver_id']
            user_profile.save()

    context = {
        'user_form': user_form,
        'profile_form': profile_form,
        'user': user
    }

    return render(request, 'portal/my_data.html', context)
Example #3
0
    def create_remote_customer(self, user):

        try:
            profile = user.userprofile
        except:
            profile = UserProfile()
            profile.user = user
            profile.save()

        if not profile.remote_customer_id:
            data = {'email': user.email}

            customer = Customer()
            res = customer.create(data)

            if res['id']:
                user.userprofile.remote_customer_id = res['id']
                user.userprofile.save()

        if user.userprofile.remote_customer_id:
            return user

        return False
Example #4
0
    def create_remote_costumer(self, user):
        try:
            profile = user.userprofile
        except:
            profile = UserProfile()
            profile.user = user
            profile.save()

        if not profile.remote_costumer_id:
            data = {
                'email': user.email,
                'name': user.first_name + user.last_name,
            }
            customer = Customer()
            res = customer.create(data)
            if res['id']:
                user.userprofile.remote_costumer_id = res['id']
                user.userprofile.save()

        if user.userprofile.remote_costumer_id:
            print('yeahh')
            return user
        return False