def registration(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, 'main_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) if user_form.is_valid(): user = user_form.save() user.set_password(user.password) user.save() registered = True return HttpResponseRedirect('/' + request.POST['path']) else: print (user_form.errors) else: user_form = UserForm() page = main_pages.get(name='Register') form = WebsiteForm.objects.get(page=page, name='register_form') context_dict = { 'page': page, 'html_form': form, 'user_form': user_form, 'registered': registered, 'force_form': False, } return render(request, 'account/register.html', context_dict)
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: # One of the forms was invalid if this else gets called. print(user_form.errors.errors) else: # Was not an HTTP post so we just render the forms as blank. user_form = UserForm() return render(request,'main_app/registration.html', {'user_form':user_form, 'registered':registered})
def sign_up(request): context = RequestContext(request) 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) user.save() user_profile = profile_form.save(commit=False) user_profile.user = user p = Project(name='inbox') p.owner = user p.save() if 'avatar' in request.FILES: profile.avatar = request.FILES['avatar'] user_profile.save() return redirect(reverse_lazy('index')) else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render_to_response('main_app/signup.html', { 'user_form': user_form, 'profile_form': profile_form }, context)
def editProfile(request): if request.method == 'POST': uform = UserForm(request.POST) pform = ProfileForm(request.POST) pform.user = request.user if uform.is_valid() and pform.is_valid(): uform.save() pform.save() return HttpResponseRedirect('/profile/') else: context = { 'uform': uform, 'pform': pform, } return render(request, 'profile.html', context) if request.method == 'GET': user = request.user try: profile = Profile.objects.get(user=user) except: profile = Profile.objects.create(user=user) context = { 'uform': UserForm( initial={ 'username': user.username, 'first_name': user.first_name, 'last_name': user.last_name, 'email': user.email, }), 'pform': ProfileForm( initial={ 'middle_name': profile.middle_name, 'sex': profile.sex, 'birthday': profile.birthday, }), } return render(request, 'profile.html', context)
def register(request): registered = False if request.method == "POST": # Mapping Form Data into Form Objects 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() # Hashing Password by calling 'set_password' user.set_password(user.password) # Save changers user.save() # Set Default User Object into the Profile # commit=False to avoid issues like insert duplicate records profile = profile_form.save(commit=False) profile.user = user # Set Profile Image File (Any kind of file) if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] # Save Profile profile.save() # Change Status of Registration if all went good registered = True else: print(user_form.errors, profile_form.errors) else: # Create Form Objects user_form = UserForm() profile_form = UserProfileInfoForm() # Set Context Object context = { "registered": registered, "user_form": user_form, "profile_form": profile_form, } return render(request, 'main_app/registration.html', context=context)
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, 'registration/registration.html', { 'user_form': user_form, 'registered': registered, })
def register(request): registered = False errors_string = None 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) # hash password user.save() profile = profile_form.save(commit=False) profile.user = user # One to One relation if 'profile_pic' in request.FILES: profile.profile_pic = request.FILES['profile_pic'] profile.save() registered = True else: all_errors = [] for err_list in user_form.errors.values(): all_errors.append(' '.join(err_list)) for err_list in profile_form.errors.values(): all_errors += ' '.join(err_list) errors_string = ' '.join(all_errors) else: registered = True if request.user.username else False user_form = UserForm() profile_form = UserProfileInfoForm() context = { 'active': 'register', 'errors': errors_string, 'user_form': user_form, 'profile_form': profile_form, 'registered': registered } return render(request, 'registration.html', context=context)