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, '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(): user = user_form.save() # Using set_password we apply HASH method to encrypt the password - Leandro 13/12/2017 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, '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(): user = user_form.save() # Save user_form directory to database. Why? user.set_password(user.password) # Hash password user.save() # Save to database profile = profile_form.save(commit=False) # Save to database, don't commit yet profile.user = user # Set up one-to-one relationship with user (in the views) if 'profile_pic' in request.FILES: # Put uploaded picture against profile model 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() mappings = { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered } return render(request, 'app/registration.html', mappings)
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: # profile.profile_pic=request.Files['profile_pic'] profile.save() registered = True else: print("profile pic error") else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, '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(): user = user_form.save(commit=False) user.email = user.username user.set_password(user.password) print(user) 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() attrs = {'class': 'form-control'} return render( request, '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) if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() # creating a user user.set_password(user.password) # hashes the password user.save() # save changes profile = profile_form.save(commit=False) # creates profile but doesn't save to database profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() # save changes registered = True else: print(user_form.errors, profile_form.errors) else: # not filled out user_form = UserForm() profile_form = UserProfileInfoForm() context_dict = {'title':'Registration', 'registered': registered, 'user_form': user_form, 'profile_form': profile_form} return render(request,'app/registration.html',context=context_dict)
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(data=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() # This is the render and context dictionary to feed # back to the registration.html file page. return render(request,'app/registration.html', {'user_form':user_form, 'profile_form':profile_form, 'registered':registered})
def student_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') # If yes, then grab it from the POST form reply profile.profile_pic = request.FILES['profile_pic'] # Now save model profile.save() print(user.username,user.email,profile.phone_no) main.add_user(user.first_name,profile.pointer,user.email,profile.phone_no) # Registration Successful registered = True u = reverse('app:student_user_login') return HttpResponseRedirect(u) hashcode = 0 name = user.username size = len(name) temp = size for i in name: hashcode += ord(i)*(10**temp) temp-=1 #print(hashcode) #subscribe.addUser(str(hashcode),name) else: # One of the forms was invalid if this else gets called. print(user_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,'app/studentregistration.html', {'user_form':user_form, 'profile_form':profile_form, 'registered':registered})
def register(request): registered = False if request.method == 'POST': # It appears as one form to the user on the .html page user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) # Check to see if form 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) profile.user = user # Registration Successful! profile.save() 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() # This is the render and context dictionary to feed # back to the registration.html file page. return render(request,'app/registration.html', {'user_form':user_form, 'profile_form':profile_form, 'registered':registered})
def post(self, request): # user_form = UserProfileForm(data=request.POST) profile_form = UserProfileInfoForm(request.POST) print(profile_form.is_valid(), profile_form) if profile_form.is_valid(): # user = user_form.save(commit=False) # user['id'] = request.session.get('_auth_user_id') # user.set_password(user.password) # print(user, "------------------------------") # user.update() # profile.user = request.user#.get('_auth_user_id') # user = get_object_or_404(User, pk=request.session.get('_auth_user_id')) # print(profile_form) profile = profile_form.save(commit=False) # profile.user_id = request.user profileObj = get_object_or_404( UserProfileInfo, user_id=request.session.get('_auth_user_id')) profile.user_id = request.session.get('_auth_user_id') profile.id = profileObj.id print(profile, "+++++++++++++++++++++++++++++++") if 'profile_pic' in request.FILES: print('found it') profile.profile_pic = request.FILES['profile_pic'] profile.save() return render(request, self.template_name, { 'messages': "Update Successfully", "isUpdate": True }) else: return render( request, self.template_name, { 'user_form': self.user_form, 'profile_image_form': self.profile_image_form, 'messages': "Please fill all fields", "isUpdate": False })