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, 'register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def signup(request): registered = False #defining a post method to a form and saving it to db 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: 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, 'first_app/signup.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() #to prevent from collision commit=false profile = profile_form.save(commit=False) profile.user = user if 'profile_pic' in request.FILES: 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, 'first_app/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def registration(request): registered = False if request.method == 'POST': userform = UserForm(data=request.POST) userinfoform = UserInfoForm(data=request.POST) if userform.is_valid() and userinfoform.is_valid(): user = userform.save() user.set_password(user.password) user.save() userinfo = userinfoform.save(commit=False) userinfo.user = user if 'profile_pic' in request.FILES: userinfo.profile_pic = request.FILES['profile_pic'] userinfo.save() registered = True else: print(userform.errors, userinfoform.errors) else: userform = UserForm() userinfoform = UserInfoForm() return render( request, 'first_app/registration.html', { 'userform': userform, 'userinfoform': userinfoform, 'registered': registered })
def register(request): form = UserForm(request.POST) registered = False if form.is_valid(): user = form.save(commit=False) if UserSignUp.objects.filter(email=user.email).exists(): return render(request, 'already.html') else: user.save() registered = True email_id = request.POST.get('email') print(email_id) l = [] l.append(email_id) subject = "Newsletter" message = """ Thank you, for subscribing to our newsletter, We hope that it will be beneficial for you. Regards: Rishabh Maheshwari """ recepient = l send_mail(subject, message, EMAIL_HOST_USER, recepient, fail_silently=False) return render(request, 'home.html', { 'form': form, 'registered': registered })
def signup_page(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) #hasing password user.save() profile = profile_form.save(commit=False) profile.user = user #sets up ne to one relationship # can also be used to upload a CSV if 'profile_pic' in request.FILES: 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, 'first_app/signup.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) info_form = UserInfoForm(request.POST, request.FILES) if user_form.is_valid() and info_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() info = info_form.save(commit=False) info.user = user if 'pro_pics' in request.FILES: info.pro_pics = request.FILES['pro_pics'] info.save() registered = True else: print(user_form.errors, info_form.errors) else: user_form = UserForm() info_form = UserInfoForm() return render(request, 'first_app/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) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save(commit=True) user.set_password(user.password) user.save() profile = profile_form.save(commit=False) profile.user = user if "profile_pic" in request.FILES: 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() context_dict = {"user_form": user_form, "profile_form": profile_form} return render(request, "first_app/registration.html", context_dict)
def register(request): registered = False if request.method == "POST": user_form = UserForm(data = request.POST) profile_form = UserProfileForm(data = request.POST) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() user.set_password(user.password) #settings.py-> PASSWORD_HASHER & validators used user.save() profile = profile_form.save(commit = False) #False because we want to perform task like relating one to one with user, True lets it directly save to database profile.user = user #relating profile and user in one to one fashion if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: print(user_form.error,profile_form.error) else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'first_app/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(): # SAVE USER user = user_form.save() # HASH PASSWORD user.set_password(user.password) # SAVE CHANGES FOR HASHED PASSWORD user.save(0) profile = profile_form.save(commit=False) profile.user = user if 'profile_picture' in request.FILES: profile.profile_picture = request.FILES['profile_picture'] profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render(request, 'first_app/registration.html', {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def register(request): registered = False if request.method == 'POST': # Get info from "both" forms # It appears as one form to the user on the .html page user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(request.POST) # Check to see both forms are valid if user_form.is_valid() and profile_form.is_valid(): # Save User Form to Database user = user_form.save() # Hash the password user.set_password(user.password) # Update with Hashed password user.save() # Now we deal with the extra info! # Can't commit yet because we still need to manipulate profile = profile_form.save(commit=False) # Set One to One relationship between # UserForm and UserProfileInfoForm profile.user = user # Check if they provided a profile picture if 'profile_pic' in request.FILES: print('found it') # If yes, then grab it from the POST form reply profile.profile_pic = request.FILES['profile_pic'] # Now save model profile.save() # Registration Successful! registered = True else: # One of the forms was invalid if this else gets called. print(user_form.errors, profile_form.errors) else: # Was not an HTTP post so we just render the forms as blank. user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'first_app/_register.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) # Get info from "both" forms # It appears as one form to the user on the .html page # Check to see both forms are valid if user_form.is_valid() and profile_form.is_valid(): # Save User Form to Database user = user_form.save() # Hash the password user.set_password(user.password) # Update with Hashed password user.save() profile = profile_form.save(commit=False) # Set One to One relationship between # UserForm and UserProfileInfoForm profile.user = user # Check if they provided a profile picture if 'profile_pic' in request.FILES: print('found it') # If yes, then grab it from the POST form reply profile.profile_pic = request.FILES['profile_pic'] # Now save model profile.save() # Check if they provided a profile picture # Registration Successful! registered = True else: # One of the forms was invalid if this else gets called. print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() # This is the render and context dictionary to feed # back to the registration.html file page. return render( request, 'login.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def signup(request): if request.method == 'GET': form = UserForm() elif request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): form.save() return render(request, 'first_app/signup.html', {'form': form})
def user_form(request): form = UserForm(request.POST) if request.method == 'POST': # created a person object obj = Person() if form.is_valid(): # clean data from 'form' and assign them into objects attributes obj.first_name = form.cleaned_data['first_name'] obj.last_name = form.cleaned_data['last_name'] #finally save the object in db obj.save() print('Object Saved') return HttpResponse("Object Saved") return render(request, "user-form.html", {'form': form})
def Registration(request): topics = Topic.objects.all() registered = False if request.method == "POST": print("Registration Request type is - Get") """ Invoke both the forms 1.user_form 2.UserProfileInfoForm in the views from forms.py 1. UserForm is linked with django's default model User 2. UserProfileInfoForm is linked with model UserProfileInfo which describes the two additional fields """ user_form = UserForm(request.POST) profile_form = UserProfileInfoForm(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 """ The above line is actually relates to object reference 'user' defined in model.py by user = models.OneToOneField(User, on_delete='Cascade') """ if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True #return HttpResponseRedirect(reverse(Registration)) else: print("Form is invalid. Errors - " + user_form.errors + profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() print("Registration Request type is - Get") return render( request, 'first_app/Registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered, 'all_topics': topics, })
def user_form_view(request): users_list = User.objects.all() user_form = UserForm() if request.method == 'POST': user_form = UserForm(request.POST) if user_form.is_valid(): print("Validation success") print("First Name: " + user_form.cleaned_data['first_name']) print("Last Name: " + user_form.cleaned_data['last_name']) print("Email: " + user_form.cleaned_data['email']) user_form.save() user_form = UserForm() else: print("ERROR: Form invalid") return render(request, 'first_app/index.html', { 'form': user_form, 'users_list': users_list })
def add_User(request, pk): entity = get_object_or_404(Entity, pk=pk) if request.method == "POST": form = UserForm(request.POST) if form.is_valid(): UserProfileInfo = form.save(commit=False) UserProfileInfo.entity = entity UserProfileInfo.save() subject = 'Your Fafnir account is set!' message = "Hi, Testing" message = Mail(from_email='*****@*****.**', to_emails=["*****@*****.**"], subject=subject, html_content=message) sg = SendGridAPIClient(SENDGRID_API_KEY) response = sg.send(message) """ name = form.cleaned_data["name"] email = form.cleaned_data["email"] subject = f'Message from {form.cleaned_data["name"]}' message = "Welcome to My Portal" sender = "*****@*****.**" recipients = ['*****@*****.**', "*****@*****.**"] try: jj = send_mail(subject, message, sender, recipients, fail_silently=False) except BadHeaderError: return HttpResponse('Invalid header found') """ return redirect('users', pk=entity.pk) else: form = UserForm() entity_list = Entity.objects.order_by('entity_name') return render(request, 'first_app/add_user.html', {'form': form})
def register(request): registered = False if request.method == 'POST': print('form filled') 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) #password hashing user.save() #save user data profile = profile_form.save(commit=False) profile.user = user #one to one relation if 'profile_pic' in request.FILES: #iterating over media files uploaded in the registration process profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True print('form saved') else: print(user_form.errors, profile_form.errors) #error printing on the forms else: print('form created') user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, "first_app/registration.html", { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): registered = False if request.method == 'POST': # Grab the data from the POST user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) # Check if the form is valid and save the user data if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() # Hash the user password user.set_password(user.password) # Save the latest data user.save() # commit the profile information without saving them: This is because we havent # checked if the user provided an image(profile pics) profile = profile_form.save(commit=False) # Set the user id. this is used to fulfile the OneToOneField # Registered on our Form.py file profile.user = user if 'profile_pics' in request.FILES: profile.profile_pics = request.FILES['profile_pics'] profile.save() registered = True else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render(request, 'first_app/registration.html', {"profile_form": profile_form, 'user_form': user_form, 'registered': registered})
def authoreg(request): print("authoreg called") registered = False if request == "POST": print("Inside 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() print("Saved data of user") profile = profile_form.save(commit=False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() print("Saved data of profile") registered = True print("Updated registered tag!!") else: print(user_form.errors, profile_form.errors) else: print("Get portion executed!!") user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'first_app/authoreg.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) 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, 'first_app/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 = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): # Save form to a database user = user_form.save() # Hash the password user.set_password(user.password) # Save the password to the user information user.save() profile = profile_form.save(commit=False) # OneToOne Relationship profile.user = user if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: print(user.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'first_app/registration.html', { 'registered': registered, 'user_form': user_form, 'profile_form': profile_form })
def Register(request): if request.user.is_authenticated: return HttpResponseRedirect(reverse('index')) 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: 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, 'first_app/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })