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(user_form.errors,profile_form.errors) else: user_form = UserForm profile_form = UserProfileInfoForm return render(request, 'myapp/register.html', {'user_form':user_form, 'profile_form':profile_form,'registered':registered})
def register(request): registered = False verifCodeAlert = False try: code = models.verifyCodes.objects.all().filter(inUse=False)[0] except: return HttpResponse("Ilość kont wyczerpana") if request.method == "POST": user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) margonemAccountCheck = codegen.checkCode(code.code, request.POST.get("mprofile")) if user_form.is_valid() and profile_form.is_valid() and margonemAccountCheck == True: user = user_form.save() user.set_password(user.password) profile = profile_form.save(commit=False) profile.verifCode = code code.inUse = True code.save() registered = True user.save() profile.user = user profile.save() user = authenticate(username = user.username, password = user.password) return HttpResponseRedirect(reverse('user_login')) else: registerAlert = dict() try: if profile_form.errors['mprofile']: registerAlert.update({'Podano błędny, lub zajęty link do profilu margonem': "Validmprofile"}) except: if margonemAccountCheck == False: registerAlert.update({'Nie znaleziono kodu weryfikacyjnego na profilu margonem': "validCode"}) try: if user_form.errors['username']: registerAlert.update({'Login najprawdopodobniej jest zajęty': "validLogin"}) except: pass try: if user_form.errors['password']: registerAlert.update({'Hasło jest zbyt słabe': "validpassword"}) except: pass print(user_form.errors.keys()) user_form = UserForm() profile_form = UserProfileInfoForm() return render(request, 'registration.html', context={'user_form': user_form, 'profile_form': profile_form, 'registered': registered, 'verCode': code.code, 'alerts': registerAlert}) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render(request, 'registration.html',context={'user_form':user_form, 'profile_form':profile_form, 'registered':registered, 'verCode':code.code, 'verifCodeAlert':verifCodeAlert})
def register(request): registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) # print(user_form) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): # our_user = UserProfileInfo(user = user_form.save(),indicesList = "'NDVI':'(nir-r)/(nir+r)'") # print(our_user) user = user_form.save() user.set_password(user.password) user.save() # our_user.save() profile = profile_form.save(commit=False) profile.user = user # userInfo = UserProfileInfo.objects.all() # print(userInfo) 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, '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 else: print(user_form.errors, profile_form.errors) else: user_form = UserForm() profile_form = UserProfileInfoForm() return render( request, 'registration/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(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 is used in the context of registration.html 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, 'myapp/registration.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })
def register(request): registered = False if request.method == 'POST': user_form = UserForm(request.POST) profile_form = UserProfileInfoForm(request.POST) # check for validity of both the forms if user_form.is_valid() and profile_form.is_valid(): user = user_form.save() # set_password will take in the raw_password and applies hashing user.set_password(user.password) # save the above change user.save() # contains website link and profile_pic profile = profile_form.save( commit=False) # creates object but don't persist into db 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, 'myapp/registration.html', { 'registered': registered, 'user_form': user_form, 'profile_form': profile_form })
def register(request): registered = False if request.method == "POST": # this garp data from user form when user register user_form = UserForm(data=request.POST) profile_form = UserProfileInfoForm(data=request.POST) if user_form.is_valid() and profile_form.is_valid(): """ grap user from user_form then save it then hash th password then save it """ user = user_form.save() user.set_password(user.password) user.save() # the additional fields """ this won't save directr;y to the database and this use the OneToOneField we created """ profile = profile_form.save(commit=False) profile.user = user """ request.FILES for pdf/img/cv """ 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, 'myapp/register.html', { 'user_form': user_form, 'profile_form': profile_form, 'registered': registered })