本文整理汇总了Python中users.forms.RegisterForm类的典型用法代码示例。如果您正苦于以下问题:Python RegisterForm类的具体用法?Python RegisterForm怎么用?Python RegisterForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RegisterForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register
def register(request):
url='/register'
sub='Register'
if request.method == "POST":
form = RegisterForm(request.POST)
if form.is_valid():
nm = form.cleaned_data['name']
gender = form.cleaned_data['gender']
reg_no = form.cleaned_data['reg_no']
email = form.cleaned_data['email']
pwd = form.cleaned_data['password']
x = OjUser.objects.filter(username=email)
if x:
return HttpResponse('Email exists')
l = OjUser.objects.create(
username = reg_no,
first_name = nm,
email = email,
gender = gender,
reg_no = reg_no,
)
l.set_password(pwd)
l.save()
text="Registered Successfully"
return render(request,"index.html",{'text':text})
else:
return render(request,'register.html',{'form':form,'url':url,'sub':sub})
else:
form = RegisterForm()
return render(request,'register.html',{'form':form,'url':'/register','sub':'Register'})
示例2: sbregister
def sbregister(request):
errors_msg = []
if request.method=="POST":
form = RegisterForm(request.POST)
if form.is_valid():
username = request.POST['username']
password = request.POST['password']
rptpwd = request.POST['rptpwd']
sbid = request.POST['idnum']
name = request.POST['name']
teleph = request.POST['teleph']
address = request.POST['address']
user = User.objects.create_user(username=username, password=password)
user.save()
profile = SBProfile(user=user, sbid=sbid, name=name, teleph=teleph, address=address, flag=1)
profile.save()
#login the user in
user = authenticate(username=username, password=password)
login(request, user)
return redirect('users.views.home')
else:
errors_msg.append('Input invalid!')
else:
form = RegisterForm()
return render_to_response('users/register.html',
locals(),
context_instance=RequestContext(request)
)
示例3: register_view
def register_view(request):
"""
Register a new user
"""
# Check if the user is authenticated
if request.user.is_authenticated():
# User is already authenticated
return render(request, 'users/register/already_logged_in.html')
else:
register_form = RegisterForm(request.POST or None)
if request.method == 'POST': # Form data was submitted
if register_form.is_valid(): # Form data is valid
# Create the user
with transaction.atomic():
user = User.objects.create_user(register_form.cleaned_data['username'],
"N/A", # we don't deal with email addresses
register_form.cleaned_data['password'])
PastebinUser.create_user(user)
# TODO: Show a different message if the registration fails
return render(request, 'users/register/register_success.html')
# Show the registration page
return render(request, "users/register/register.html", { "form": register_form })
示例4: register_wholesale
def register_wholesale(request):
"""Регистрация оптового покупателя"""
if request.POST:
form = RegisterForm(request.POST)
company_form = CompanyForm(request.POST)
if form.is_valid() and company_form.is_valid():
instance = form.save(commit=False)
instance.set_password(form.cleaned_data["password"])
instance.status = User.STATUS_WHOLESALE
instance.save()
instance = authenticate(email=instance.email, password=form.cleaned_data["password"])
user_login(request, instance)
company = company_form.save(commit=False)
company.user = request.user
company.save()
return redirect(reverse("users.auth.register.completed"))
else:
form = RegisterForm()
company_form = CompanyForm()
context = {"form": form, "company_form": company_form}
return render(request, "users/auth/register_wholesale.html", context)
示例5: register
def register():
form = RegisterForm(request.form)
if form.validate_on_submit():
# Create new User instance
user = User(
name=form.username.data,
email=form.email.data,
password=form.password.data,
)
try:
user.save()
except UniquenessViolation, err:
if err.column_name == "email":
form.email.errors.append("There is already an account registered with that email address.")
elif err.column_name == "name":
form.username.errors.append("There is already an account registered with that username.")
else:
login_user(user)
# Flash a message that gets displayed only once.
flash("Welcome to the herd.")
return redirect(url_for("users.profile"))
finally:
示例6: create_user
def create_user(request):
#If the user is trying to add info to the server,
if request.method == 'POST':
#Feed as arguments to RegisterForm the inputs from the user.
create_user_form = RegisterForm(request.POST)
#If username and password are of the right length and email is of the valid form,
#And password and confirm password identical,
if create_user_form.is_valid():
#Don't save the user in creation as a new user yet.
new_user = create_user_form.save()
pw = create_user_form.cleaned_data.get('password')
new_user.set_password( pw )
new_user.save()
#Then create UserProfile object from User object.
new_UserProfile = UserProfile(user=new_user)
#new_UserProfile.user = new_user
new_UserProfile.save() #Then save.
#Render a Welcome to GroupFit page if the input info is valid.
#No need to customize welcome page unless we want to just switch the name: Welcome, username!
return render(request, 'welcome.html')
#Send an email as well.
else:
#If the user didn't plug in anything, create_user_form will be an empty shell?
create_user_form = RegisterForm()
return render(request, 'register.html', {'create_user_form': create_user_form})
示例7: register
def register(request, **kwargs):
if request.user.is_authenticated():
messages.error(request, 'Ya estas registrado')
logging.error('Ya estas registrado: %s ' % request.user.username)
return redirect(reverse('error'))
form = RegisterForm()
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
user = form.save()
messages.success(request, _("Bienvenido a %s" % current_site.name))
user = authenticate(username=form.cleaned_data['username'],
password=form.cleaned_data['password1'])
auth_login(request, user)
return redirect(reverse('home'))
context = {
'form': form
}
c = template.RequestContext(request, context)
return render_to_response('page.users.register.html', c)
示例8: handle_register
def handle_register(request, email_template=None, email_subject=None,
email_data=None):
"""Handle to help registration."""
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
form = try_send_email_with_form(
RegistrationProfile.objects.create_inactive_user,
form, 'email',
form.cleaned_data['username'],
form.cleaned_data['password'],
form.cleaned_data['email'],
locale=request.locale,
email_template=email_template,
email_subject=email_subject,
email_data=email_data)
if not form.is_valid():
# Delete user if form is not valid, i.e. email was not sent.
# This is in a POST request and so always pinned to master,
# so there is no race condition.
User.objects.filter(email=form.instance.email).delete()
else:
statsd.incr('user.register')
return form
return RegisterForm()
示例9: register
def register(request):
c = get_common_context(request)
auth_form = AuthenticationForm()
register_form = RegisterForm()
c['auth_form'] = auth_form
c['register_form'] = register_form
if request.method == "POST":
if request.POST['action'] == 'auth':
auth_form = AuthenticationForm(request.POST)
if auth_form.is_valid():
pass
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None:
if user.is_active:
auth.login(request, user)
if 'is_order' in request.session:
del request.session['is_order']
return HttpResponseRedirect('/order/2/')
return HttpResponseRedirect('/')
else:
c['auth_error'] = u'Ваш аккаунт не активирован.'
else:
c['auth_error'] = u'Неверный логин или пароль.'
c['auth_form'] = auth_form
elif request.POST['action'] == 'register':
from django.forms.util import ErrorList
register_form = RegisterForm(request.POST)
if register_form.is_valid():
p1 = register_form.data.get('password_1')
p2 = register_form.data.get('password_2')
error = False
if p1 != p2:
register_form._errors["password_2"] = ErrorList([u'Пароли не совпадают.'])
error = True
if len(User.objects.filter(username=register_form.data.get('email'))):
register_form._errors["email"] = ErrorList([u'Такой емейл уже зарегистрирован.'])
error = True
if not error:
u = User(username=register_form.data.get('email'), email=register_form.data.get('email'))
u.set_password(register_form.data.get('password_1'))
u.save()
p = u.get_profile()
p.fio = register_form.data.get('fio')
p.save()
user = auth.authenticate(username=register_form.data.get('email'), password=register_form.data.get('password_1'))
auth.login(request, user)
if 'is_order' in request.session:
del request.session['is_order']
return HttpResponseRedirect('/order/2/')
else:
return HttpResponseRedirect('/')
c['register_form'] = register_form
return render_to_response('register.html', c, context_instance=RequestContext(request))
示例10: post
def post(self, request):
form = RegisterForm(request.POST)
if form.is_valid():
user = form.save()
return render_to_response('register_success.html', RequestContext(request))
#return HttpResponseRedirect('../../coins/')
else:
return self.registerPage(request, form)
示例11: post
def post(self, request, *args, **kwargs):
form = RegisterForm(request.POST, request.FILES)
if form.is_valid():
user = form.save()
# send_validation_code.apply_async(kwargs={'pk': user.id })
messages.info(request, _('You were successfully registered.'
'Validation link was sent to you'), extra_tags='register')
return HttpResponseRedirect(reverse('users:code_sent'))
return self.render_to_response({'form': form})
示例12: testEmailAlreadyRegistered
def testEmailAlreadyRegistered(self):
form_data = {
'username': self.CREATED_USER_USERNAME,
'email': self.USER_EMAIL,
'password': self.USER_PASSWORD,
'password_confirm': self.USER_PASSWORD,
}
form = RegisterForm(form_data)
self.assertFalse(form.is_valid())
self.assertIn('email', form.errors)
示例13: handle_register
def handle_register(request):
"""Handle to help registration."""
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
RegistrationProfile.objects.create_inactive_user(
form.cleaned_data['username'], form.cleaned_data['password'],
form.cleaned_data['email'])
return form
return RegisterForm()
示例14: register
def register():
form = RegisterForm()
if form.validate_on_submit():
user = User(form.name.data, form.email.data, form.password.data)
db.session.add(user)
db.session.commit()
login_user(user)
flash('Thanks for registering')
return redirect(url_for('users.home'))
return render_template("register.html", form=form)
示例15: test_can_save
def test_can_save(self):
self.assertEqual(User.objects.count(), 0)
test_form = RegisterForm({'username': 'blah',
'email': '[email protected]',
'password1': 'asdf',
'password2': 'asdf'})
test_form.is_valid()
test_form.save()
self.assertEqual(User.objects.count(), 1)