def create_company(request, template_name='register/outside/create_company.html'): form = NewCompanyForm(request.POST or None) contact_form = CreateCompanyContactNoCompanyForm(request.POST or None, prefix='contact') user_form = UserForm(request.POST or None, prefix='user') if contact_form.is_valid() and user_form.is_valid() and form.is_valid(): company = form.save() user = user_form.save(commit=False) contact = contact_form.save(commit=False) user.username = contact.email_address user.email = contact.email_address user.save() contact.user = user contact.confirmed = True #Auto confirm contacts who register a new company contact.company = company contact.save() user = authenticate( username=contact_form.cleaned_data['email_address'], password=user_form.cleaned_data['password1'], ) login(request, user) return redirect('anmalan:choose_company') return render( request, template_name, dict(form=form, contact_form=contact_form, user_form=user_form))
def create_user(request, template_name='register/outside/create_user.html'): contact_form = CreateCompanyContactForm(request.POST or None, prefix='contact') user_form = UserForm(request.POST or None, prefix='user') if request.POST and contact_form.is_valid() and user_form.is_valid(): user = user_form.save(commit=False) contact = contact_form.save(commit=False) user.username = contact.email_address user.email = contact.email_address user.save() contact.user = user contact.save() user = authenticate( username=contact_form.cleaned_data['email_address'], password=user_form.cleaned_data['password1'], ) login(request, user) return redirect('anmalan:choose_company') return render(request, template_name, dict(contact_form=contact_form, user_form=user_form))