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 })
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 })
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 })
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 })
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 })
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() return HttpResponseRedirect(reverse('index')) else: print(user_form.errors) return HttpResponse("Форма была не полностью заполнена или такой пользователь уже существует") else: user_form = UserForm() return render(request,'dappx/registration.html', {'user_form':user_form, 'registered':registered})
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() registered = True else: print(user_form.errors) else: user_form = UserForm() return render(request, 'dappx/registration.html', { 'user_form': user_form, 'registered': registered })
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = VoterProfileInfoForm(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 fullName = str(user.first_name) + str(user.last_name) voter_profile = { "$class": "org.ecp.voting.voter", "voterID": user.username, "fullName": str(fullName), "gender": str(profile.gender) } ifVoted_data = { "$class": "org.ecp.voting.ifVoted", "voterID": user.username, "votedOrNot": "false" } requests.post(server + '/api/voter', json=voter_profile) requests.post(server + '/api/ifVoted', json=ifVoted_data) else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = VoterProfileInfoForm() return render( request, 'dappx/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
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 })
def candidate_register(request): registered = False constituency_list = [] i = 0 contituency = requests.get(server + '/api/district').json() while (i < len(contituency)): constituency_list.append((contituency[i]["districtName"])) i = i + 1 political_parties = requests.get(server + '/api/politicalParty').json() if request.method == 'POST': user_form = UserForm(data=request.POST) profile_form = CandidateProfileInfoForm(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.constituency = request.POST['const'] profile.party = request.POST['party'] profile.save() fullName = str(user.first_name) + str(user.last_name) district_url = server + '/api/queries/filterDistrictByName?nameParam={}'.format( request.POST['const']) url = server + '/api/queries/PartyByNames?partyParam={}'.format( request.POST['party']) district_info = requests.get(district_url).json() political_party_data = requests.get(url).json() candidate_vote_id_data = CandidateVote.objects.create( candidate_id=str(user.username)) candidateVoteId = str(candidate_vote_id_data.candidate_vote_id) candidate_data = { "$class": "org.ecp.voting.candidate", "candidateID": str(user.username), "fullName": fullName, "party": political_party_data[0], "IndependentStatus": "false" } candidate_vote_data = { "$class": "org.ecp.voting.candidateVote", "candidateVoteId": candidateVoteId, "totalVote": "0", "candidateProfile": candidate_data, "candidateDistrict": district_info[0] } candidate_payload = json.dumps(candidate_data) candidate_data_request = requests.post(server + '/api/candidate', json=candidate_data) requests.post(server + '/api/candidateVote', json=candidate_vote_data) registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = CandidateProfileInfoForm() return render( request, 'dappx/candidate_registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered, 'constituencies': constituency_list, 'parties': political_parties })