def register(request): if request.session.test_cookie_worked(): print ">>>> TEST COOKIE WORKED!" request.session.delete_test_cookie() registerd = 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) user.save() profile = profile_form.save(commit = False) profile.user = user if 'picture' in request.FILES: profile.picture = request.FILES['picture'] profile.save() registerd = True else: print user_form.errors, profile_form.errors else: user_form = UserForm() profile_form = UserProfileForm() return render(request, 'register.html', {'user_form' : user_form, 'profile_form' : profile_form, 'registerd' : registerd})
def new_user(request): rgform = UserForm(request.POST) if rgform.is_valid(): user = rgform.save(commit = False) request.session user.ip_registration = get_ip(request) user.save() return render(request, './index.html') return render(request, './registration.html',{'regform': UserForm()})
def create_account(request): global USERKEYS, CONSULTANT form = UserForm(request.POST or None) if form.is_valid(): new_user = form.save() # Contact the server to get the global param and compute the pair of keys public_key, secret_key, user_id = keygen(form.cleaned_data['username']) # Save the user information in a JSON file USERKEYS = UserKeys(user_id, form.cleaned_data['username'], public_key, secret_key) USERKEYS.save_to_file() # Create consultant consultant_key, consultant_id = get_consultant() CONSULTANT = UserKeys(consultant_id, "consultant", consultant_key, "noonecares") # Redirect to the login page return redirect('frontend:home') return render(request, 'frontend/sign.html', locals())
def profile(request): if request.method == 'POST': form1 = UserForm(request.POST, instance=request.user) #form2 = UserProfileForm(request.user.is_superuser, request.POST, instance=request.user.userprofile) # For now we allow everyone to choose their organisation and claim ownership form2 = UserProfileForm(True, request.POST, instance=request.user.userprofile) if (form1.is_valid() and form2.is_valid()): form1.save() form2.save() else: form1 = UserForm(instance=request.user) #form2 = UserProfileForm(request.user.is_superuser, instance=request.user.userprofile) form2 = UserProfileForm(True, instance=request.user.userprofile) org = request.user.userprofile.organisation extendToPrettyForm(form1) extendToPrettyForm(form2) return render(request, 'frontend/profile.html', { 'user': request.user, 'org': org, 'form1': form1, 'form2': form2 })