def register(request): if request.method == 'POST': user_form = UserRegistrationForm(request.POST) if user_form.is_valid(): new_user = user_form.save(commit=False) new_user.set_password(user_form.cleaned_data['password']) new_user.save() prof = Profile() prof.organization_user = new_user prof.name = user_form.cleaned_data["organization_name"] prof.organization_slug = slugify( user_form.cleaned_data["organization_name"]) prof.ein_number = user_form.cleaned_data["ein_number"] prof.about = user_form.cleaned_data["about"] prof.organization_city = user_form.cleaned_data[ "organization_city"] prof.organization_country = user_form.cleaned_data[ "organization_country"] prof.organization_contact_email = user_form.cleaned_data[ "organization_contact_email"] prof.organization_mission = user_form.cleaned_data[ "organization_mission"] prof.organization_primary_objective1 = user_form.cleaned_data[ "organization_primary_objective1"] prof.organization_primary_objective2 = user_form.cleaned_data[ "organization_primary_objective2"] prof.organization_primary_objective3 = user_form.cleaned_data[ "organization_primary_objective3"] prof.save() return HttpResponse("Registration Done") else: user_form = UserRegistrationForm() context = {'user_form': user_form} return render(request, 'main/register.html', context=context)
def create_invited_user(self, inviter_id, username, name, sex, email, password, site, send_email=False): """ add by cyb: Create a new, active ``User``, generate a ``Profile`` and email the register success information to ``User`` . Unlike function create_inactive_user, no activation email, only the success email will be sent. """ new_user = User.objects.create_user(username, email, password) new_user.is_active = True new_user.save() user_profile = Profile() user_profile.name = name user_profile.user_id = new_user.pk user_profile.sex = sex user_profile.is_active = True user_profile.invite_num = 10 user_profile.save() #Due to syncronization issue between database master and slave, return both to prevent inconsistency # in querying new_profile.user return_value ={} return_value['user_profile'] = user_profile return_value['new_user'] = new_user return return_value