本文整理匯總了Python中accounts.forms.RegistrationForm類的典型用法代碼示例。如果您正苦於以下問題:Python RegistrationForm類的具體用法?Python RegistrationForm怎麽用?Python RegistrationForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了RegistrationForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: WeightloserRegistration
def WeightloserRegistration(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method=='POST':
form=RegistrationForm(request.POST)
if form.is_valid():
emailtemp=str(form.cleaned_data['emailId'])
name=emailtemp.split("@")[0]
user = User.objects.create_user(username=name, email = form.cleaned_data['emailId'], password = form.cleaned_data['password'])
user.save()
weightloser = WeightLoser(user=user, fname=form.cleaned_data['fname'],lname=form.cleaned_data['lname'], dob=form.cleaned_data['dob'],gender=form.cleaned_data['gender'],emailId=form.cleaned_data['emailId'],currentWeight=form.cleaned_data['currentWeight'])
weightloser.save()
userwloser = authenticate(username=name, password=form.cleaned_data['password'])
login(request, userwloser)
print "user is "+str(request.user.is_authenticated())
return HttpResponseRedirect('/profile/')
else: #display the form when not valid
return render_to_response('RegisterPage.html',{'form':form}, context_instance=RequestContext(request))
else: #Showing the form
'''user is not submitting the form, show them a blank registration form'''
form=RegistrationForm()
context={'form':form}
return render_to_response('RegisterPage.html',context, context_instance=RequestContext(request))
示例2: register
def register(request):
code = ""
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
email = request.POST['email']
form = RegistrationForm(request.POST)
if form.is_valid():
salt = sha.new(str(random.random())).hexdigest()[:5]
activation_code = sha.new(salt+username).hexdigest()
key_expires = datetime.datetime.today() + datetime.timedelta(7)
user = User.objects.create_user(username=username, email=email, password=password)
user.is_active = False
user.save()
profile = form.save(commit=False)
profile.user = user
profile.activation_code = activation_code
profile.key_expires = key_expires
profile.save()
return render_to_response('accounts/register.html',
{'code':activation_code, 'profile':profile}, context_instance=RequestContext(request))
else:
salt = sha.new(str(random.random())).hexdigest()[:5]
activation_code = sha.new(salt+username).hexdigest()
return render_to_response('accounts/register.html',
{'form':form, 'code':activation_code}, context_instance=RequestContext(request))
else:
form = RegistrationForm()
return render_to_response('accounts/register.html',{'form':form, 'code':code})
示例3: test_invalid_email
def test_invalid_email(self):
form = RegistrationForm(self.invalid_email)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors,
{'email': [u'Enter a valid email address.']}
)
示例4: test_non_matching_passwords
def test_non_matching_passwords(self):
form = RegistrationForm(self.non_matching_passwords)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors,
{'__all__': [u"Passwords don't match."]}
)
示例5: login
def login(request):
login_form = LoginForm()
register_form = RegistrationForm()
next = request.REQUEST.get('next', settings.LOGIN_REDIRECT_URL)
# Special case next urls that will lead us into redirect loops
if next == settings.LOGIN_URL:
next = settings.LOGIN_REDIRECT_URL
if 'kind' in request.POST:
if request.POST['kind'] == 'register':
register_form = RegistrationForm(request.POST)
if register_form.is_valid():
_backend_hackend(request, register_form.save())
return HttpResponseRedirect(next)
elif request.POST['kind'] == 'login':
login_form = LoginForm(request.POST)
if login_form.is_valid() and login_form.user:
_backend_hackend(request, login_form.user)
return HttpResponseRedirect(next)
context = {
'login_form': login_form,
'register_form': register_form,
'next': next,
}
return render_to_response('accounts/login.html', context,
context_instance=RequestContext(request))
示例6: register
def register(request):
"""
用戶注冊
"""
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
user = User.objects.create_user(
username=form.cleaned_data['username'],
password=form.cleaned_data['password2'],
email=form.cleaned_data['email'],
)
user.save()
#保存用戶城市數據
users = Users(
user=user,
city=form.cleaned_data['citycode'],
)
users.save()
#注冊成功
return render_to_response('warn.html',{'warning':'注冊成功!',}, context_instance=RequestContext(request))
else:
form = RegistrationForm()
return render_to_response('account/register.html',{'form':form,},
context_instance=RequestContext(request))
示例7: signup
def signup(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/profile/')
if request.method=="POST":
form = RegistrationForm(request.POST) #take the form and fill it with what has been POST'ed
if form.is_valid():
user = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password'])
user.save()
#possibly might need these lines of code for edit profile
#uprofile = user.get_profile() #remember its set in settings
#uprofile.avatar = form.cleaned_data['avatar']
#uprofile.name = form.cleaned_data['name']
#uprofile.website = form.cleaned_data['website']
#uprofile.bio = form.cleaned_data['bio']
#uprofile.save() #save our UserProfile object, which contains our User extra data or subclass.
"""create UserProfile object manually. uncomment when done in editprofile view"""
# userprofile = UserProfile(user=user, avatar=form.cleaned_data['avatar'],name=form.cleaned_data['name'],)
# userprofile.save()
return HttpResponseRedirect('/a/profile/') # because we have to return HTTP response else error is thrown
else: #in case form isnt valid show the form again. this time possibly with errors and such
return render_to_response('accounts/register.html', {'form':form}, context_instance=RequestContext(request))
else:
form = RegistrationForm()
context = {'form':form}
return render_to_response('accounts/register.html', context, context_instance=RequestContext(request))
示例8: register
def register(self, request, **kwargs):
"""
Create and immediately log in a new user.
"""
invitation_key = kwargs.get('invitation_key', None)
email = kwargs.get('email', None)
if request.POST:
form = RegistrationForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
user.email = email # email was omitted from form - it's required to use the same email invitation was sent to
user.save() # default groups and all pending accesses are automatically assigned - signal
else:
return None
#username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
#User.objects.create_user(username, email, password)
# authenticate() always has to be called before login(), and
# will return the user we just created.
new_user = authenticate(username=user.username, password=form.cleaned_data['password1'])
login(request, new_user)
signals.user_registered.send(sender=self.__class__,
user=new_user,
invitation_key=invitation_key,
request=request)
return new_user
示例9: RegisterView
class RegisterView(TemplateView):
template_name = "register.html"
def __init__(self):
super(RegisterView, self).__init__()
self.form = RegistrationForm()
def get_context(self, request, *args, **kwargs):
context = {
'form': self.form
}
return context
def get(self, request, *args, **kwargs):
return self.render_to_response(self.get_context(request))
def post(self, request, *args, **kwargs):
self.form = RegistrationForm(request.POST)
if self.form.is_valid():
self.form.save()
user = auth.authenticate(username=self.form.user.email, password=self.form.str_password)
auth.login(request, user)
send([user], 'registration')
return HttpResponseRedirect("/accounts/personal-data-master/")
return self.render_to_response(self.get_context(request))
示例10: register
def register(request):
if request.user != None and request.user.is_authenticated():
return redirect('/')
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
#Create the user
email = form.cleaned_data.get('email')
passwd = form.cleaned_data.get('password1')
user = User(email=email)
user.set_password(passwd)
user.save()
user.username = user.pk
user.save()
user_profile = UserProfile(user=user)
user_profile.save()
user.backend='user_backends.email_username.EmailOrUsernameModelBackend'
#logs the new user
login(request,user)
return redirect('/')
else:
form = RegistrationForm()
return locals()
示例11: post
def post(self, request, *args, **kwargs):
form = RegistrationForm(request.POST)
if form.is_valid():
fname = form.cleaned_data.get('fname')
lname = form.cleaned_data.get('lname')
usrnm = form.cleaned_data.get('usrnm')
email = form.cleaned_data.get('email')
passw = form.cleaned_data.get('pass1')
user = User.objects.create_user(usrnm, email, passw)
user.first_name = fname
user.last_name = lname
user.save()
messages.info(request,
'''Your new account has been created.
You may now login using your username and password.''')
return redirect('account_login')
else:
return self.render_to_response({
'form': form
})
示例12: register
def register(request):
#create_superuser('[email protected]', 'password')
register_success = False
form = RegistrationForm()
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
# Check this, change it to email in html template
# in html, the input element has name as 'username', but we are showing label as email, so we will accept it as 'email'
email = request.POST.get('username')
password = request.POST.get('password1')
# There are errors, if the email gets repeated,
# check, some authentication, if UserValid only then fire a create_user, else, print some error in html
if not user_exists(email):
create_user(email, password)
else: # if user exists, then log him in
# If user created properly, then login
# This login is NOT WORKING, see y?
#import django.contrib.auth.views as v
#v.login(request)
pass
register_success = True
# return HttpResponseRedirect("/")
else:
form = RegistrationForm(request.POST)
d = { 'form': form, "register_success": register_success, }
#return render(request, "registration/register.html", { 'form': form, })
return render(request, 'registration/registration.html', d, context_instance=RequestContext(request))
示例13: register
def register(request):
if request.method == 'POST':
form = RegistrationForm(data=request.POST)
if form.is_valid():
user = form.save()
return redirect('/accounts/register_success')
else:
form = RegistrationForm()
return render(request,'accounts/register.html', {'form':form,})
示例14: register
def register(request,template_name='register/p_register.html'):
if request.user.is_authenticated():
return HttpResponseRedirect(reverse('views.home'))
template_var={}
form = RegistrationForm()
if request.method == 'POST':
form = RegistrationForm(request.POST.copy())
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password']
user = User.objects.create_user(username,email,password)
if accounts_settings.USER_ACTIVE_BY_EMAIL == True:
user.is_active = False
user.save()
if accounts_settings.USER_ACTIVE_BY_EMAIL == False:
#if it's unnecessary to active by email, login directly.
_login(request, email, password)
return HttpResponseRedirect(reverse('views.home'))
else:
"""
Generates a one-use only link for activation and sends to the user
"""
from django.core.mail import send_mail
email_template_name = 'register/activation_email.html'
current_site = get_current_site(request)
site_name = current_site.name
domain = current_site.domain
use_https = False
t = loader.get_template(email_template_name)
c = {
'email': user.email,
'domain': domain,
'site_name': site_name,
'uid': int_to_base36(user.id),
'user': user,
'token': default_token_generator.make_token(user),
'protocol': use_https and 'https' or 'http',
}
try:
send_mail(_(u'%s:激活賬戶') % site_name,
t.render(Context(c)), None, [user.email])
return HttpResponseRedirect(reverse('accounts.views.register_complete'))
except:
user.delete()
return TemplateView.as_view(template_name='register/register_fail.html')
template_var['form'] = form
return render_to_response(template_name, template_var, context_instance=RequestContext(request))
示例15: create_user_from_weibo
def create_user_from_weibo(request, template_name='register/create_user_from_weibo.html'):
oauth_access_token = request.session.get('oauth_access_token', None)
if request.user.is_authenticated() or oauth_access_token is None:
return HttpResponseRedirect(reverse('home.views.index'))
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=_get_weibo_callback_url(request))
client.set_access_token(oauth_access_token['access_token'], oauth_access_token['expires_in'])
weibo_user = client.get.users__show(uid=oauth_access_token['uid'])
weibo_username = weibo_user.screen_name
template_var = {}
form = RegistrationForm(initial={'username': weibo_username })
if request.method == 'POST':
form = RegistrationForm(request.POST.copy())
if request.method == 'POST':
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password']
user = User.objects.create_user(username,email,password)
user.is_active = True
user.save()
profile = UserProfile()
profile.user = user
profile.song_ord_filed = 'post_datetime'
profile.save()
#weibo信息記錄
w_user = WeiboUser()
w_user.user = user
w_user.weibo_user_id = oauth_access_token['uid']
w_user.weibo_username = weibo_username
w_user.oauth_access_token = oauth_access_token['access_token']
w_user.save()
#發微博提示
if request.POST.get('update_msg'):
msg = request.POST.get('bind_msg')[0:140]
client.post.statuses__update(status=msg)
user = authenticate(username=username, password=password)
auth_login(request,user)
return HttpResponseRedirect(reverse('songs.views.my_home'))
template_var['form'] = form
template_var['weibo_username'] = weibo_username
return render_to_response(template_name, template_var, context_instance=RequestContext(request))