本文整理匯總了Python中registration.forms.RegistrationForm類的典型用法代碼示例。如果您正苦於以下問題:Python RegistrationForm類的具體用法?Python RegistrationForm怎麽用?Python RegistrationForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RegistrationForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register
def register(request, template_name='registration/register.html'):
profile_url = settings.USER_PROFILE_URL % 'username'
if request.method == 'GET':
form = RegistrationForm()
else: # POST
form = RegistrationForm(data=request.POST)
if form.is_valid():
hn_username = form.cleaned_data['hn_username']
# user_data is a dict containing the users HN account creation
# date, karma at query time, and HN profile
user_data = retrieve_hn_user_data(hn_username)
# form validation checks that hn_username matches what's provided
# and that the "key" (a url) is in the profile
temp_password = ''.join(random.sample(string.letters, 16))
new_user = User.objects.create_user(username=hn_username,
email='',
password=temp_password)
user = authenticate(username=new_user.username,
password=temp_password)
if user is not None:
login(request, user)
messages.success(request, 'That worked. Please provide a password.')
return HttpResponseRedirect(reverse('set_password'))
return render_to_response(template_name, locals(),
context_instance=RequestContext(request))
示例2: handle_post
def handle_post(self, request):
"""
Registers a user if it was a request to register a user
and the registration form was correctly completed.
"""
# Confirm that the requst is a post, and that this form is
# the intended recipient of the posted data.
if not request.POST or self.submit_btn_name() not in request.POST:
return None
form = RegistrationForm(request.POST, auto_id=False)
if form.is_valid():
# Create a user, log them in, and redirect based on the
# success_url rules.
user, created = User.objects.create_user(request=request,
send_email=True,
**form.cleaned_data)
user_cache = authenticate(
username=form.cleaned_data['email'],
password=form.cleaned_data['password1'])
expire_login(request, user_cache)
response = HttpResponseRedirect(success_url(request))
response.set_cookie('myguid', user.user_guid, expires=365*24*60*60,
domain='.my.jobs')
return response
return None
示例3: register
def register(request):
if request.user.is_authenticated():
return redirect('current_profile')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
#new_user = RegistrationProfile.objects.create_inactive_user(username, email, password)
#return redirect('registration_complete')
user = User.objects.create_user(username, form.cleaned_data['email'], password)
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()
user = auth.authenticate(username=username, password=password)
assert user and user.is_authenticated()
auth.login(request, user)
# TODO: redirect to a message with confirmation
return redirect(user.get_absolute_url())
else:
form = RegistrationForm()
return render_to_response('users/register.html',
context_instance=RequestContext(request, {'form': form}))
示例4: register
def register(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(username=form.cleaned_data['username'], email = form.cleaned_data['email'], password=form.cleaned_data['password'])
user.save()
registration = UserProfile(user=user, name = form.cleaned_data['name'], address = form.cleaned_data['address'],
contact = form.cleaned_data['contact'], stream = form.cleaned_data['stream'], age = form.cleaned_data['age'],
gender = form.cleaned_data['gender'], register_as = form.cleaned_data['register_as']
)
if form.cleaned_data['register_as']=='FY':
facstat = FacultyStatus(username = form.cleaned_data['username'], name = form.cleaned_data['name'])
facstat.save()
if 'picture' in request.FILES:
registration.picture = request.FILES['picture']
registration.save()
return HttpResponseRedirect('/profile')
else:
return render_to_response('registration/register.html',{'form':form, 're':"active"}, context_instance=RequestContext(request))
else:
form = RegistrationForm()
context = {'form': form, 're':"active"}
return render_to_response('registration/register.html', context, context_instance=RequestContext(request))
示例5: edit
def edit(request):
curr_user = request.user
if request.method == 'POST':
form = RegistrationForm(request.POST, user=curr_user)
if form.is_valid():
try:
curr_user.account.first_name = form.cleaned_data['first_name']
curr_user.account.middle_name = form.cleaned_data['middle_name']
curr_user.account.last_name = form.cleaned_data['last_name']
curr_user.account.mobile_no = form.cleaned_data['phone_number']
#curr_user.account.email = form.cleaned_data['email']
curr_user.account.save()
except Account.DoesNotExist:
return HttpResponse('The Account object does not exist for this user')
return redirect('/register/success/')
else:
form = RegistrationForm(user=curr_user)
return render(
request,
'registration/register.html',
{'form': form, 'title': 'Update Profile'}
)
示例6: user_profile_post
def user_profile_post(request, **kwargs):
user=request.user
form=RegistrationForm(request.POST)
added_context={'registration_form': form}
if not form.is_valid(user=user):
form.reformat_errors()
# log.debug('user %r not valid, aborting' % user.contributor)
return render(request, 'registration/user_profile.html', added_context)
user.first_name=form.cleaned_data['first_name']
user.last_name=form.cleaned_data['last_name']
user.email=form.cleaned_data['email']
user.password=make_password(form.cleaned_data['password1'])
user.contributor.lab.name=form.cleaned_data['lab']
user.contributor.lab.url=form.cleaned_data['lab_url']
try:
# log.debug('about to save user: %r' % user.contributor)
user.save()
added_context['msgs']='Profile successfully updated'
except Exception as e:
msgs='Unable to save user information: %s' % e
added_context['msgs']=msgs
# log.debug(msgs)
return render(request, 'registration/user_profile.html', added_context)
示例7: create_account
def create_account(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
form.cleaned_data['email'],
form.cleaned_data['email'],
form.cleaned_data['password'],
)
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()
# Log in the new user. Note that Django requires that we call
# authenticate() despite its apparent redundancy in this case
user = authenticate(username=user.username, password=form.cleaned_data['password'])
login(request, user)
return redirect(reverse('registration.views.create_account_done'))
else:
form = RegistrationForm()
return render_to_response('registration/create_account.html', RequestContext(request, {
'form': form,
}))
示例8: register
def register(request, extra_context=None):
if not getattr(settings, 'REGISTRATION_OPEN', True):
return redirect('registration_disallowed')
if request.method == 'POST':
form = RegistrationForm(data=request.POST, files=request.FILES)
if form.is_valid():
username, email, password = form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password1']
site = Site.objects.get_current() if Site._meta.installed else RequestSite(request)
new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site)
signals.user_registered.send(sender=None, user=new_user, request=request)
profile = UserProfile.objects.get(user=new_user)
seller_type = form.cleaned_data['seller_type']
phone = form.cleaned_data['phone']
profile.seller_type = seller_type
profile.phone = phone
profile.save()
gravatar_task.delay(new_user, new_user.pk)
success_url = request.GET.get('next','')
if success_url:
return redirect(success_url)
else:
return redirect('registration_complete')
else:
form = RegistrationForm()
if extra_context is None:
extra_context = {}
context = RequestContext(request)
for key, value in extra_context.items():
context[key] = callable(value) and value() or value
return render_to_response('static_pages/index.html', {'register_form': form}, context_instance=context)
示例9: register
def register(request,
disallowed_url='registration_disallowed',
template_name='registration/registration.html'):
"""用戶注冊
"""
# 是否允許用戶進行注冊
allow_register = getattr(settings, 'REGISTRATION_OPEN', False)
if not allow_register:
return redirect(disallowed_url)
if request.method == 'POST':
form = RegistrationForm(request.POST)
# 數據驗證
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password1']
# 創建一個未激活的用戶和默認的擴展屬性
act_key = TeamProfile.objects.create_inactive_user(username, email, password)
# 直接將激活碼作為鏈接發給用戶
to, args, kwargs = ('registration_activate',(), {'activation_key':act_key})
return redirect(to, *args, **kwargs)
else:
form = RegistrationForm()
context = RequestContext(request)
return render_to_response(template_name,
{'form': form},
context_instance=context)
示例10: register
def register(request):
if not request.user.is_anonymous():
return redirect('/home/')
if request.method == 'POST':
title = "Update Profile"
form = RegistrationForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
password = form.cleaned_data['password1']
user = User.objects.create(username=email_to_username(email),
email=email)
user.set_password(password)
user.save()
account = Account.objects.create(
user=user,
first_name=form.cleaned_data['first_name'],
middle_name=form.cleaned_data['middle_name'],
last_name=form.cleaned_data['last_name'],
mobile_no=form.cleaned_data['phone_number'],
email=form.cleaned_data['email']
)
return redirect('/register/success/')
else:
title = "Create New Profile"
form = RegistrationForm()
return render(
request,
'registration/register.html',
{'form': form, 'title': title}
)
示例11: login
def login(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('')
else:
return render(request, 'registration/login.html')
示例12: __init__
def __init__(self, *args, **kwargs):
user_profile_instance = kwargs.pop('user_profile_instance', None)
captcha_answer = kwargs.pop('captcha_answer', None)
RegistrationForm.__init__(self, captcha_answer=captcha_answer, *args, **kwargs)
ArtistProfileUpdateForm.__init__(self, user_profile_instance=user_profile_instance, *args, **kwargs)
# Move CAPTCHA and EULA fields to the end
self.fields.keyOrder.remove('captcha')
self.fields.keyOrder.remove('over13')
self.fields.keyOrder.remove('accept_eula')
self.fields.keyOrder.extend(['captcha', 'over13', 'accept_eula'])
示例13: createUser
def createUser(request):
if request.method == 'POST': # If the form has been submitted...
form = RegistrationForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
try:
form.save()
except ValidationError, err:
error = unicode(err)
return render(request, 'createuser.html', {'form': form, 'error': error})
return HttpResponseRedirect('/thanks/') # Redirect after POST
示例14: register
def register(request):
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = form.save()
return redirect('registration_completed')
else:
form = RegistrationForm()
return TemplateResponse(request, 'registration/register.html', {'form': form})
示例15: _register_all
def _register_all(trial_run, email_func):
if trial_run:
def trial_email(subject, body, from_, addresses, fail_silently):
print "-" * 60
print "Would send this mail:"
print "To: %s" % ", ".join(addresses)
print "From: %s" % from_
print "Subject: %s" % subject
print
print body
print '-' * 60
email_func = trial_email
anon_racks = Rack.objects.filter(user=u'')
addrs = set([rack.email.strip() for rack in anon_racks])
names_seen = set()
current_site = Site.objects.get(id=settings.SITE_ID)
for email in addrs:
name = email.split('@', 1)[0]
import re
name = re.sub(r'[^!A-Za-z0-9_-]', '_', name)
if name in names_seen:
raise ValueError("Oh crap, already saw name %r" % name)
names_seen.add(name)
password = randpass() # Just so we always have a non-empty password.
data = {'username': name, 'email': email,
'password1': password, 'password2': password,}
template_args = {'name': name, 'email': email, 'domain': current_site.domain,
'password': password,
'activation_days': settings.ACCOUNT_ACTIVATION_DAYS,
}
form = RegistrationForm(data=data)
if form.is_valid():
# Register an inactive account and get the key.
template = register_email_txt
user = form.save()
reg_profile = RegistrationProfile.objects.filter(user=user)[0]
template_args['key'] = reg_profile.activation_key
# We also need to provide a way to set your password.
template_args['password_reset_token'] = default_token_generator.make_token(user)
template_args['uidb36'] = int_to_base36(user.id)
if trial_run:
user.delete(); reg_profile.delete()
else:
if form.errors.get('username', [''])[0].count(u'already taken'):
# Send an email without the link to the predetermined username.
template = register_email_name_taken_txt
else:
print "Problem with address %s:" % email
import pprint
pprint.pprint(form.errors)
continue
send_email(template, trial_run, email_func=email_func, **template_args)