• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python forms.RegisterForm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中users.forms.RegisterForm的典型用法代码示例。如果您正苦于以下问题:Python RegisterForm类的具体用法?Python RegisterForm怎么用?Python RegisterForm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了RegisterForm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'})
开发者ID:aswinm,项目名称:onlinejudge,代码行数:30,代码来源:views.py


示例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)
    )
开发者ID:ysyfff,项目名称:wimi,代码行数:28,代码来源:views.py


示例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 })
开发者ID:Aoshee,项目名称:pastebin-django,代码行数:25,代码来源:views.py


示例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)
开发者ID:Lisaveta-K,项目名称:lisaveta-k.github.io,代码行数:29,代码来源:auth.py


示例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:
开发者ID:shunyata,项目名称:nobooru,代码行数:25,代码来源:views.py


示例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})
开发者ID:clee15,项目名称:groupfit,代码行数:28,代码来源:views.py


示例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)
开发者ID:mandlaweb,项目名称:Zero-Users,代码行数:27,代码来源:views.py


示例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()
开发者ID:Curlified,项目名称:kitsune,代码行数:25,代码来源:utils.py


示例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))
开发者ID:kpx13,项目名称:galant,代码行数:59,代码来源:views.py


示例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)
开发者ID:eshikvtumane,项目名称:coinRepo,代码行数:8,代码来源:views.py


示例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})
开发者ID:amacasieb,项目名称:meso,代码行数:9,代码来源:views.py


示例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)
开发者ID:RevolutionTech,项目名称:flamingo,代码行数:10,代码来源:tests.py


示例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()
开发者ID:LucianU,项目名称:kuma,代码行数:10,代码来源:utils.py


示例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)
开发者ID:scolex,项目名称:flask-forum,代码行数:10,代码来源:views.py


示例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)
开发者ID:ericmok,项目名称:djangosimpleblog,代码行数:11,代码来源:test_forms.py


示例16: register

def register(request):
  form = RegisterForm()
  if request.method == 'POST':
    form = RegisterForm(request.POST)
    if form.is_valid():
      user = form.save()
      mail_welcome(user)
      authenticate(request, user)
      util.add_success(request, "Welcome to %s" % ConfigData.get_configdata('SITE_NAME'))
      return redirect(reverse('admin_dashboard'))

  c = template.RequestContext(request, locals())
  return render_to_response('users_register.html', c)
开发者ID:zerofuxor,项目名称:ContentQ-CMS,代码行数:13,代码来源:views.py


示例17: register

def register(request):
    if (request.method=='POST'):
        form = RegisterForm(data=request.POST)
        if(form.is_valid()):
            #check captcha first
            session = UserSession.objects.get(session_key=request.session.session_key)
            print("session captcha: "+session.captcha)
            print("form captcha: "+form.cleaned_data["captcha"])
            if(session.captcha != form.cleaned_data["captcha"]):
                messages.add_message(request, messages.ERROR, _('The captcha was entered wrong.'))
            else:
                referer = request.META.get('HTTP_REFERER')
                user = form.save()
                user.groups.add(Group.objects.get(name='User'))
                user.is_active = False
                user.set_password(user.password)
                user.save()
                import uuid
                lv_uuid = str(uuid.uuid1())[0:30]

                message = """<html>
                <body>
                    <h3>Registration at """+get_current_site(request).name+"""</h3><br/>
                    <p>
                        Please click the following link to end your registration.
                    </p>
                    <p>
                        <a href='https://"""+get_current_site(request).domain+""""/user/activate/"""+lv_uuid+"""/'>Activation Link</a>
                    </p>
                </html>
                """

                send_mail('Registration at '+get_current_site(request).name, 'Hello '+user.username+
                          '\n\nPlease click the following the link to end your registration.\n\n'+
                          'Activation Link: https://'+get_current_site(request).domain+'/user/activate/'+lv_uuid+'/', settings.SYSTEMMAIL,
                        [user.email], fail_silently=False,html_message=message)
                profile = UserProfile()
                profile.user = user
                profile.posts = 0
                profile.threads = 0
                profile.activate = lv_uuid
                profile.theme = Theme.objects.get(default=True)
                profile.banned = False
                profile.save()
                messages.add_message(request, messages.INFO, _('User successful registrated.'))
                #return redirect(urlresolvers.reverse('board.views.index'))
                return redirect(referer)
    else:
        form = RegisterForm()
        f_profile = ProfileForm()
    return render_to_response('user/register.html',{'form':form},context_instance=RequestContext(request))
开发者ID:hisoka999,项目名称:silverbb,代码行数:51,代码来源:views.py


示例18: test_bad_username

 def test_bad_username(self):
     #  Simple match.
     form = RegisterForm({'username': 'ass',
                          'password': 'adssadfsadf',
                          'password2': 'adssadfsadf',
                          'email': '[email protected]'})
     assert not form.is_valid()
     # Simple obfuscation.
     form = RegisterForm({'username': 'a.s.s',
                          'password': 'adssadfsadf',
                          'password2': 'adssadfsadf',
                          'email': '[email protected]'})
     assert not form.is_valid()
     # Partial match.
     form = RegisterForm({'username': 'ass.assassin',
                          'password': 'adssadfsadf',
                          'password2': 'adssadfsadf',
                          'email': '[email protected]'})
     assert not form.is_valid()
     # No match.
     form = RegisterForm({'username': 'assassin',
                          'password': 'adssadfsadf',
                          'password2': 'adssadfsadf',
                          'email': '[email protected]'})
     assert form.is_valid()
开发者ID:readevalprint,项目名称:kitsune,代码行数:25,代码来源:test_forms.py


示例19: register

def register(request):
	if request.method == 'POST':
		form = RegisterForm(request.POST)
		if form.is_valid():
			
			# Validate fields
			if form.cleaned_data['password1'] == form.cleaned_data['password2']:
				password = form.cleaned_data['password1']
			else:
				return render_to_response('users/register.html',
										  {'form':form,
										   'invalid':"Passwords mismatched"},
										   context_instance=RequestContext(request))
			
			# Django User Data
			username = form.cleaned_data['username']
			email = form.cleaned_data['email']
			
			# User Profile Data
			birthday = form.cleaned_data['birthday']
			nickname = form.cleaned_data['nickname']
			gender = form.cleaned_data['gender']
			interests = form.cleaned_data['interests']
			
			# Save User to database
			newuser = User(username=username,email=email)
			newuser.set_password(password)
			newuser.save()

			# save user profile to database
			user = User.objects.get(username=username)
			newUserProfile = UserProfile.objects.create(user=user,
														birthday=birthday,
														nickname=nickname,
														gender=gender,
														interests=interests)
			newUserProfile.save()

			return HttpResponseRedirect('/login/')
		
		else:
			return render_to_response('users/register.html',
									  {'form':form,
									   'invalid':"Some required fields have not been filled"},
									  context_instance=RequestContext(request))
	else:
		form = RegisterForm()

	return render_to_response('users/register.html',
							  context_instance=RequestContext(request))	
开发者ID:Sneakyburger,项目名称:Highlander-Tumblr,代码行数:50,代码来源:views.py


示例20: handle_register

def handle_register(request):
    """Handle to help registration."""
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            
            new_user = User.objects.create_user(username, email, password)
            new_user.save()
            Profile.objects.create(user=new_user)
        return form
    return RegisterForm()
开发者ID:ryansnyder,项目名称:spark,代码行数:14,代码来源:utils.py



注:本文中的users.forms.RegisterForm类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python forms.RegistrationForm类代码示例发布时间:2022-05-27
下一篇:
Python forms.ProfileForm类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap