當前位置: 首頁>>代碼示例>>Python>>正文


Python RegistrationForm.is_valid方法代碼示例

本文整理匯總了Python中accounts.forms.RegistrationForm.is_valid方法的典型用法代碼示例。如果您正苦於以下問題:Python RegistrationForm.is_valid方法的具體用法?Python RegistrationForm.is_valid怎麽用?Python RegistrationForm.is_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在accounts.forms.RegistrationForm的用法示例。


在下文中一共展示了RegistrationForm.is_valid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_reg_form_unique_email

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
    def test_reg_form_unique_email(self):
        """
        Test that ``RegistrationForm`` validates uniqueness
        of email addresses.

        """
        # Create a user so we can verify that duplicate addresses aren't permitted.
        User.objects.create_user('alice', '[email protected]', 'secret')

        form = RegistrationForm(data={'username': 'foo',
                                      'email': '[email protected]',
                                      'password1': 'foo',
                                      'password2': 'foo',
                                      'tos': True})
        self.failIf(form.is_valid())
        self.assertEqual(form.errors['email'], [u"This email address is already in use. Please supply a different email address."])

        form = RegistrationForm(data={'username': 'foo1',
                                      'email': '[email protected]',
                                      'password1': 'foo',
                                      'password2': 'foo',
                                      'tos': True})
        print form.is_valid()
        print form.errors
        self.failUnless(form.is_valid())
開發者ID:JTarball,項目名稱:docker-django-polymer,代碼行數:27,代碼來源:test_forms.py

示例2: WeightloserRegistration

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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))
開發者ID:lose4good,項目名稱:prototype,代碼行數:27,代碼來源:views.py

示例3: test_non_matching_passwords

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
 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."]}
     )
開發者ID:imxiaohui,項目名稱:django-todolist-1,代碼行數:9,代碼來源:tests.py

示例4: test_invalid_email

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
 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.']}
     )
開發者ID:imxiaohui,項目名稱:django-todolist-1,代碼行數:9,代碼來源:tests.py

示例5: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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))
開發者ID:0x55aa,項目名稱:django-accounts,代碼行數:30,代碼來源:views.py

示例6: login

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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))
開發者ID:ariel17,項目名稱:servertail,代碼行數:29,代碼來源:views.py

示例7: RegisterView

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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))
開發者ID:andruwwwka,項目名稱:super5,代碼行數:28,代碼來源:views.py

示例8: signup

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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))
開發者ID:FrantzdyRomain,項目名稱:peekd-django-project,代碼行數:31,代碼來源:views.py

示例9: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
    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
開發者ID:bluusystemsinc,項目名稱:bluu,代碼行數:30,代碼來源:backends.py

示例10: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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()
開發者ID:arruda,項目名稱:rmr,代碼行數:28,代碼來源:views.py

示例11: post

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
 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
         })
開發者ID:PeithVergil,項目名稱:django-uploadify,代碼行數:27,代碼來源:views.py

示例12: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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})
開發者ID:semillastan,項目名稱:juatsemilla,代碼行數:31,代碼來源:views.py

示例13: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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))
開發者ID:ashish2,項目名稱:PySite,代碼行數:37,代碼來源:views.py

示例14: register

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
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,})
開發者ID:curlylrt,項目名稱:testsite,代碼行數:11,代碼來源:views.py

示例15: test_reg_form

# 需要導入模塊: from accounts.forms import RegistrationForm [as 別名]
# 或者: from accounts.forms.RegistrationForm import is_valid [as 別名]
    def test_reg_form(self):
        """
        Test that ``RegistrationForm`` enforces username constraints
        and matching passwords.
        """
        # Create a user so we can verify that duplicate usernames aren't permitted.
        User.objects.create_user('alice', '[email protected]', 'secret')

        invalid_data_dicts = [
            # Non-alphanumeric username.
            {'data': {'username': 'foo/bar',
                      'email': '[email protected]',
                      'password1': 'foo',
                      'password2': 'foo',
                      'tos': True},
            'error': ('username', [u"This value may contain only letters, numbers and @/./+/-/_ characters."])},
            # Already-existing username.
            {'data': {'username': 'alice',
                      'email': '[email protected]',
                      'password1': 'secret',
                      'password2': 'secret',
                      'tos': True},
            'error': ('username', [u"A user with that username already exists."])},
            # Mismatched passwords.
            {'data': {'username': 'foo',
                      'email': '[email protected]',
                      'password1': 'foo',
                      'password2': 'bar',
                      'tos': True},
            'error': ('__all__', [u"The two password fields didn't match."])},
            ]

        for invalid_dict in invalid_data_dicts:
            form = RegistrationForm(data=invalid_dict['data'])
            self.failIf(form.is_valid())
            self.assertEqual(form.errors[invalid_dict['error'][0]],
                             invalid_dict['error'][1])

        form = RegistrationForm(data={'username': 'foo',
                                      'email': '[email protected]',
                                      'password1': 'foo',
                                      'password2': 'foo',
                                      'tos': True})
        self.failUnless(form.is_valid())
開發者ID:JTarball,項目名稱:docker-django-polymer,代碼行數:46,代碼來源:test_forms.py


注:本文中的accounts.forms.RegistrationForm.is_valid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。