当前位置: 首页>>代码示例>>Python>>正文


Python forms.UserCreateForm类代码示例

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


在下文中一共展示了UserCreateForm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_user

def create_user(request):
    context = {}
    context_instance = RequestContext(request)
    form = UserCreateForm(request.POST or None)
    context['form'] = form
    
    if request.user.is_authenticated():
        return redirect('/user/dashboard')

    if request.method == 'POST' and form.is_valid():
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        email = form.cleaned_data['email']
        phone = form.cleaned_data['phone']
        try:
            users_manager.create_user(first_name, last_name, username, password, email, phone)
            # authenticate and login
            user = authenticate(username=username, password=password)
            login_auth(request, user)
            return redirect('/user/dashboard')
        except Exception as exc:
            # 400
            form.errors['__all__'] = form.error_class(["Error: %s" % exc.message])

    # GET / POST with invalid input
    return render_to_response('user/create.html', context, context_instance=context_instance)
开发者ID:wormangel,项目名称:bandontherun,代码行数:28,代码来源:views_user.py

示例2: signup

def signup(request):
    """
    User registration view.
    """
    auth_form = AuthenticateForm()

    if request.method == 'POST':
        form = UserCreateForm(data=request.POST)
        if form.is_valid():
            form.save()
            user = authenticate(email=request.POST['email'], password=request.POST['password2'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return redirect('/')

        else:
            return render_to_response('home.html', {
                'auth_form': auth_form, 'user_form': form, 
            }, context_instance=RequestContext(request))

    elif request.method == 'GET':
        form = UserCreateForm()
        return render_to_response('home.html', {
            'auth_form': auth_form, 'user_form': form, 
        }, context_instance=RequestContext(request))
开发者ID:KophyGiddie,项目名称:Tweetify,代码行数:26,代码来源:views.py

示例3: register

def register(request):
	context = {}
	context["news"] = get_news_by_request(request)
	user = User()
	if request.method == 'POST':
		form = UserCreateForm(request.POST, instance = user)
		if form.is_valid():
			pw = user.password
			user.set_password(user.password)
			user.theme_id=4
			user.input_type_id=1
			if not open_registration:
				user.is_active = False
			form.save()
			ro = ReminderOffsets.objects.get(value=0)
			user.reminder_offset.add(ro)
			ro = ReminderOffsets.objects.get(value=2)
			user.reminder_offset.add(ro)
			if open_registration:
				group = Group.objects.filter(name="BuLiTipp")[0]
				user.groups.add(group)
				user = authenticate(username=user.username, password=pw)
				djlogin(request, user)
				messages.success(request, "Benutzer erfolgreich angelegt! Tritt als nächstes einer Tippgemeinschaft bei!")
				return HttpResponseRedirect(reverse("user", args=["tgchange"]))
			else:
				mail.send("BuLiTipp: User registriert", "[email protected]", "Bitte administriere den neuen User " + user.username+ " !")
				messages.success(request, "Benutzer erfolgreich angelegt! Du kannst dich einloggen sobald der Administrator dich freigeschaltet hat.")
				return HttpResponseRedirect(reverse("home"))
			
	else:
		form = UserCreateForm(instance=user)
	context["form"] = form
	return render(request, 'registration/register.html', context)
开发者ID:laDanz,项目名称:BuLiTipp,代码行数:34,代码来源:views.py

示例4: customregister

def customregister(request):
    returnJson = ifReturnJson(request)
    data_dict = {}
    data_dict['type'] = 'register'
    if request.method == 'POST':
        form = UserCreateForm(request.POST)
        if form.is_valid():
            new_user = form.save()

            data_dict['success'] = 1
            data_dict['uid'] = new_user.id
            data_dict['username'] = new_user.username
            data_dict['name'] = new_user.first_name + new_user.last_name
            data_dict['email'] = new_user.email

            #Redirect to the registration complete page
            #return HttpResponseRedirect("/homepage/")
        else:
            data_dict['success'] = 0
            #invalid form
            data_dict['error_message'] = 'invalid registration form'
        if returnJson == 1:
            return HttpResponse(json.dumps(data_dict),content_type='application/json')
        elif returnJson == 0:
            return redirect('/accounts/register')
    else:
        form = UserCreateForm()
        return render(request, "registration/registration_form.html", {
            'form': form,
        })
开发者ID:ZhigangAndyWang,项目名称:FoodJournal,代码行数:30,代码来源:views.py

示例5: create_user

	def create_user(self, version = 0):
		"""
		Creates a UserProfile. Version is an integer that determines which userprofile to generate (one of two)
		"""
		registration_values = self.create_valid_user_vals(version)
		user_form = UserCreateForm(registration_values)
		if user_form.is_valid():
			return user_form.save()
开发者ID:rmwdeveloper,项目名称:rainforest,代码行数:8,代码来源:tests.py

示例6: register

def register(request):
    if request.method == "POST":
        form = UserCreateForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/videos/")
    else:
        form = UserCreateForm()
    return render(request, "registration/register.html", {"form": form})
开发者ID:johnwm47,项目名称:487-Project,代码行数:9,代码来源:views.py

示例7: new_user

def new_user(request):
    if request.method=='POST':
        formulario = UserCreateForm(request.POST)
        if formulario.is_valid:
            formulario.save()
            return HttpResponseRedirect('/')
    else:
        formulario = UserCreateForm()
    return render_to_response('new_user.html',{'formulario':formulario},context_instance=RequestContext(request))
开发者ID:gbarbosa4,项目名称:Concessionari,代码行数:9,代码来源:views.py

示例8: post

    def post(self):
        form = UserCreateForm()
        if not form.validate_on_submit():
            return form.errors, 422

        user = User(form.email.data, form.password.data)
        db.session.add(user)
        db.session.commit()
        return UserSerializer(user).data
开发者ID:jjp9624022,项目名称:angularFlaskBlog,代码行数:9,代码来源:views.py

示例9: create_account

def create_account(request):
    if request.method == "POST":
        form = UserCreateForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/success/')
    else:
        form = UserCreateForm()
    return render(request,'create.html',{'form':form})
开发者ID:pgp-pasteur-fr,项目名称:MetaGenSense,代码行数:9,代码来源:views.py

示例10: register

def register(request):
    register_success = reverse('user_register_success')
    if request.method == 'POST':
		form = UserCreateForm(request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect(register_success)
    else:
		form = UserCreateForm()
    return render_to_response('newaccounts/registration.html', {'form':form}, context_instance=RequestContext(request))
开发者ID:mtmarsh2,项目名称:InstaSellProject,代码行数:10,代码来源:views.py

示例11: signup

def signup(request, template_name="authentication/signup.html"):
    form = UserCreateForm(request.POST or None)

    if request.POST:
        if form.is_valid():
            form.save()

            return HttpResponseRedirect(reverse("home"))

    return render(request, template_name, {"form": form})
开发者ID:dogancankilment,项目名称:MViG,代码行数:10,代码来源:views.py

示例12: create_user

def create_user(request):
    """Creates a new user"""
    if request.method == "POST":
        form = UserCreateForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/')
    else:
        form = UserCreateForm()
    return render(request, 'quiz/create_user.html', context={'form': form})
开发者ID:Jasonbhaas,项目名称:Quiz-Project,代码行数:10,代码来源:views.py

示例13: register

def register(request):
    if request.user.is_authenticated():
        
        return redirect('/')

    if request.method == 'POST':
        user_information = {
        'username': request.POST['username'],
        'password1': request.POST['password1'],
        'password2': request.POST['password2'],
        'last_name': request.POST['last_name'],
        'city': request.POST['city'],
        'first_name': request.POST['first_name'],
        'state': request.POST['state'],
        'middle_initial': request.POST['middle_initial'],
        'birth_date': request.POST['birth_date'],
        'email': request.POST['email'],
        'street_address': request.POST['street_address'],
        'zip_code': request.POST['zip_code']
        }

        form = UserCreateForm(user_information)
        if form.is_valid():
           
            form.save()
            return redirect('/') 
        else: 
            form_errors = form.errors
            return render_to_response('register.html', {'errors': form_errors, 'form': form}, context_instance=RequestContext(request))
    else: #AJAX form validation
        request_copy = request.GET.copy()
      

        if 'username' in request_copy: #Username in use?
            name = request_copy['username']
            response_data = {}

            if UserProfile.objects.filter(username__iexact=name): 
                response_data['result'] = 'false'
            else:           
                response_data['result'] = 'true'
            return HttpResponse(response_data['result'], content_type='text/plain')
          
            # return HttpResponse(json.dumps(response_data), content_type = "application/json")
        if 'email' in request_copy: #Email in use?
            entered_email = request_copy['email']
            response_data = {}
            if UserProfile.objects.filter(email__iexact=entered_email):
                response_data['result'] = 'false'
            else:
               response_data['result'] = 'true'
            return HttpResponse(response_data['result'], content_type = 'text/plain')
        else:
            form = UserCreateForm()
            return render_to_response("register.html", {'form': form, 'errors':form.errors}, context_instance=RequestContext(request))
开发者ID:rmwdeveloper,项目名称:rainforest,代码行数:55,代码来源:views.py

示例14: register

def register(request):
    if request.method == 'POST':
        form = UserCreateForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/importinfo/")
    else:
        form = UserCreateForm()
    return render_to_response("registration/register.html", {
        'form': form,
    }, context_instance=RequestContext(request))
开发者ID:chenshengkai,项目名称:riskscoringweb,代码行数:11,代码来源:views.py

示例15: post

	def post(self, request):
		form = UserCreateForm(request.POST)
		if form.is_valid():
			form.save()
			request.session["temp_user"] = {
				'username': request.POST["username"],
				'new': True,
			}
			return redirect('/accounts/register/done/')
		else:
			return render(request, self.template_name, {'user_create_form': form})
开发者ID:ryanoflaherty,项目名称:OpenEMR-API,代码行数:11,代码来源:views.py


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