コード例 #1
0
def my_user_login(request):
    registered = False
    if request.method == 'POST':
        registered = False
        token = dict(request.POST.lists())["token[id]"][0]
        name = dict(request.POST.lists())["name"][0]
        email = dict(request.POST.lists())["email"][0]
        phone = dict(request.POST.lists())["phone"][0]
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.token = token
            profile.name = name
            profile.email = email
            profile.phone = phone
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            #Create customers
            try:
                customer = conekta.Customer.create({
                    'name':
                    name,
                    'email':
                    email,
                    'phone':
                    phone,
                    'payment_sources': [{
                        'type': 'card',
                        'token_id': token
                    }]
                })
            except conekta.ConektaError as e:
                print(e)

            subscription = customer.createSubscription({"plan": "LaPapa"})
            profile.pay = True
            user.save()
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        return render(request, 'dappx/login.html', {})
    return render(
        request, 'dappx/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #2
0
def register(request):
    registered = False
    user_type = None
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        info_form = UserProfileInfoForm()
        if user_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            info = info_form.save(commit=False)
            info.user = user
            info.save()
            registered = True
            user_type = request.POST.get("user_type")
            if user_type == "CL":
                group, created = Group.objects.get_or_create(name='Client')
                user.groups.add(group)
                return render(
                    request, 'dappx/info.html', {
                        'user_type': user_type,
                        'info_form': ClientInfoForm(),
                        'user': user
                    })
            else:
                group, created = Group.objects.get_or_create(name='Contractor')
                user.groups.add(group)
                return render(
                    request, 'dappx/info.html', {
                        'user_type': user_type,
                        'info_form': ContractorInfoForm(),
                        'user': user
                    })
        else:
            print(user_form.errors)
            print(info_form.errors)
            return render(
                request, 'dappx/registration.html', {
                    'user_form': user_form,
                    'info_form': info_form,
                    'registered': registered
                })
    else:
        user_form = UserForm()
        info_form = UserProfileInfoForm()
        return render(
            request, 'dappx/registration.html', {
                'user_form': user_form,
                'info_form': info_form,
                'registered': registered
            })
コード例 #3
0
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'dappx/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #4
0
ファイル: views.py プロジェクト: tawhidularefindcc/essay
def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()
            registered = True
            return HttpResponseRedirect(reverse('dappx:submission'))
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()

    return render(
        request, 'dappx/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })
コード例 #5
0
def info(request):
    # client
    name = request.POST.get("name")
    business_id = request.POST.get("business_id")
    address = request.POST.get("address")
    state = request.POST.get("state")
    city = request.POST.get("state")
    postal_code = request.POST.get("postal_code")

    username = request.POST.get("username")
    user = User.objects.get(username=username)

    if business_id is None:
        client = Client.objects.create(user=user,
                                       name=name,
                                       state=state,
                                       city=city,
                                       postal_code=postal_code)
        client.save()
    else:
        contractor = Contractor.objects.create(user=user,
                                               name=name,
                                               state=state,
                                               city=city,
                                               postal_code=postal_code,
                                               business_id=business_id,
                                               address=address,
                                               covid_safety=0,
                                               review_count=0,
                                               categories=[])
        contractor.save()

    print("Created")
    registered = True
    user_form = UserForm()
    info_form = UserProfileInfoForm()
    return render(request, 'dappx/registration.html', {
        'user_form': user_form,
        'info_form': info_form,
        'registered': registered
    })
コード例 #6
0
def edit_profile(request):
    category = productcategories.objects.all()
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        profile_form = UserProfileInfoForm(
            request.POST, instance=request.user.userprofileinfo)

        if form.is_valid() and profile_form.is_valid():
            form.save()
            profile_form.save()
            return redirect('/profile')
    else:
        form = EditProfileForm(instance=request.user)
        profile_form = UserProfileInfoForm(
            instance=request.user.userprofileinfo)
        #args = {'form': form, 'profile_form': profile_form, 'category': category }
    return render(request, 'dappx/edit_profile.html', {
        'form': form,
        'profile_form': profile_form,
        'category': category
    })
コード例 #7
0
def register(request):
    category = productcategories.objects.all()
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        #email = user_form.fields.email()
        profile_form = UserProfileInfoForm(data=request.POST)
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'profile_pic' in request.FILES:
                print('found it')
                profile.profile_pic = request.FILES['profile_pic']
            profile.save()
            registered = True
            email = request.POST.get('email')
            send_mail(
                'BringSUya Hoşgeldiniz',
                'Sitemize üye olduğunuz için teşekkürler. ',
                'EMAIL_HOST_USER ',
                [email],
            )
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileInfoForm()
    return render(
        request, 'dappx/registration.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered,
            'category': category
        })