本文整理汇总了Python中forms.UserCreateForm类的典型用法代码示例。如果您正苦于以下问题:Python UserCreateForm类的具体用法?Python UserCreateForm怎么用?Python UserCreateForm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserCreateForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
def create_user(request):
context = {}
context_instance = RequestContext(request)
form = UserCreateForm(request.POST or None)
context['form'] = form
if request.user.is_authenticated():
return redirect('/user/dashboard')
if request.method == 'POST' and form.is_valid():
first_name = form.cleaned_data['first_name']
last_name = form.cleaned_data['last_name']
username = form.cleaned_data['username']
password = form.cleaned_data['password']
email = form.cleaned_data['email']
phone = form.cleaned_data['phone']
try:
users_manager.create_user(first_name, last_name, username, password, email, phone)
# authenticate and login
user = authenticate(username=username, password=password)
login_auth(request, user)
return redirect('/user/dashboard')
except Exception as exc:
# 400
form.errors['__all__'] = form.error_class(["Error: %s" % exc.message])
# GET / POST with invalid input
return render_to_response('user/create.html', context, context_instance=context_instance)
示例2: signup
def signup(request):
"""
User registration view.
"""
auth_form = AuthenticateForm()
if request.method == 'POST':
form = UserCreateForm(data=request.POST)
if form.is_valid():
form.save()
user = authenticate(email=request.POST['email'], password=request.POST['password2'])
if user is not None:
if user.is_active:
login(request, user)
return redirect('/')
else:
return render_to_response('home.html', {
'auth_form': auth_form, 'user_form': form,
}, context_instance=RequestContext(request))
elif request.method == 'GET':
form = UserCreateForm()
return render_to_response('home.html', {
'auth_form': auth_form, 'user_form': form,
}, context_instance=RequestContext(request))
示例3: register
def register(request):
context = {}
context["news"] = get_news_by_request(request)
user = User()
if request.method == 'POST':
form = UserCreateForm(request.POST, instance = user)
if form.is_valid():
pw = user.password
user.set_password(user.password)
user.theme_id=4
user.input_type_id=1
if not open_registration:
user.is_active = False
form.save()
ro = ReminderOffsets.objects.get(value=0)
user.reminder_offset.add(ro)
ro = ReminderOffsets.objects.get(value=2)
user.reminder_offset.add(ro)
if open_registration:
group = Group.objects.filter(name="BuLiTipp")[0]
user.groups.add(group)
user = authenticate(username=user.username, password=pw)
djlogin(request, user)
messages.success(request, "Benutzer erfolgreich angelegt! Tritt als nächstes einer Tippgemeinschaft bei!")
return HttpResponseRedirect(reverse("user", args=["tgchange"]))
else:
mail.send("BuLiTipp: User registriert", "[email protected]", "Bitte administriere den neuen User " + user.username+ " !")
messages.success(request, "Benutzer erfolgreich angelegt! Du kannst dich einloggen sobald der Administrator dich freigeschaltet hat.")
return HttpResponseRedirect(reverse("home"))
else:
form = UserCreateForm(instance=user)
context["form"] = form
return render(request, 'registration/register.html', context)
示例4: customregister
def customregister(request):
returnJson = ifReturnJson(request)
data_dict = {}
data_dict['type'] = 'register'
if request.method == 'POST':
form = UserCreateForm(request.POST)
if form.is_valid():
new_user = form.save()
data_dict['success'] = 1
data_dict['uid'] = new_user.id
data_dict['username'] = new_user.username
data_dict['name'] = new_user.first_name + new_user.last_name
data_dict['email'] = new_user.email
#Redirect to the registration complete page
#return HttpResponseRedirect("/homepage/")
else:
data_dict['success'] = 0
#invalid form
data_dict['error_message'] = 'invalid registration form'
if returnJson == 1:
return HttpResponse(json.dumps(data_dict),content_type='application/json')
elif returnJson == 0:
return redirect('/accounts/register')
else:
form = UserCreateForm()
return render(request, "registration/registration_form.html", {
'form': form,
})
示例5: create_user
def create_user(self, version = 0):
"""
Creates a UserProfile. Version is an integer that determines which userprofile to generate (one of two)
"""
registration_values = self.create_valid_user_vals(version)
user_form = UserCreateForm(registration_values)
if user_form.is_valid():
return user_form.save()
示例6: register
def register(request):
if request.method == "POST":
form = UserCreateForm(request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/videos/")
else:
form = UserCreateForm()
return render(request, "registration/register.html", {"form": form})
示例7: new_user
def new_user(request):
if request.method=='POST':
formulario = UserCreateForm(request.POST)
if formulario.is_valid:
formulario.save()
return HttpResponseRedirect('/')
else:
formulario = UserCreateForm()
return render_to_response('new_user.html',{'formulario':formulario},context_instance=RequestContext(request))
示例8: post
def post(self):
form = UserCreateForm()
if not form.validate_on_submit():
return form.errors, 422
user = User(form.email.data, form.password.data)
db.session.add(user)
db.session.commit()
return UserSerializer(user).data
示例9: create_account
def create_account(request):
if request.method == "POST":
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/success/')
else:
form = UserCreateForm()
return render(request,'create.html',{'form':form})
示例10: register
def register(request):
register_success = reverse('user_register_success')
if request.method == 'POST':
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(register_success)
else:
form = UserCreateForm()
return render_to_response('newaccounts/registration.html', {'form':form}, context_instance=RequestContext(request))
示例11: signup
def signup(request, template_name="authentication/signup.html"):
form = UserCreateForm(request.POST or None)
if request.POST:
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse("home"))
return render(request, template_name, {"form": form})
示例12: create_user
def create_user(request):
"""Creates a new user"""
if request.method == "POST":
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/')
else:
form = UserCreateForm()
return render(request, 'quiz/create_user.html', context={'form': form})
示例13: register
def register(request):
if request.user.is_authenticated():
return redirect('/')
if request.method == 'POST':
user_information = {
'username': request.POST['username'],
'password1': request.POST['password1'],
'password2': request.POST['password2'],
'last_name': request.POST['last_name'],
'city': request.POST['city'],
'first_name': request.POST['first_name'],
'state': request.POST['state'],
'middle_initial': request.POST['middle_initial'],
'birth_date': request.POST['birth_date'],
'email': request.POST['email'],
'street_address': request.POST['street_address'],
'zip_code': request.POST['zip_code']
}
form = UserCreateForm(user_information)
if form.is_valid():
form.save()
return redirect('/')
else:
form_errors = form.errors
return render_to_response('register.html', {'errors': form_errors, 'form': form}, context_instance=RequestContext(request))
else: #AJAX form validation
request_copy = request.GET.copy()
if 'username' in request_copy: #Username in use?
name = request_copy['username']
response_data = {}
if UserProfile.objects.filter(username__iexact=name):
response_data['result'] = 'false'
else:
response_data['result'] = 'true'
return HttpResponse(response_data['result'], content_type='text/plain')
# return HttpResponse(json.dumps(response_data), content_type = "application/json")
if 'email' in request_copy: #Email in use?
entered_email = request_copy['email']
response_data = {}
if UserProfile.objects.filter(email__iexact=entered_email):
response_data['result'] = 'false'
else:
response_data['result'] = 'true'
return HttpResponse(response_data['result'], content_type = 'text/plain')
else:
form = UserCreateForm()
return render_to_response("register.html", {'form': form, 'errors':form.errors}, context_instance=RequestContext(request))
示例14: register
def register(request):
if request.method == 'POST':
form = UserCreateForm(request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/importinfo/")
else:
form = UserCreateForm()
return render_to_response("registration/register.html", {
'form': form,
}, context_instance=RequestContext(request))
示例15: post
def post(self, request):
form = UserCreateForm(request.POST)
if form.is_valid():
form.save()
request.session["temp_user"] = {
'username': request.POST["username"],
'new': True,
}
return redirect('/accounts/register/done/')
else:
return render(request, self.template_name, {'user_create_form': form})