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


Python forms.UserRegistrationForm类代码示例

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


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

示例1: register

def register(request):
    #if we have a post to the url then populate the registration form with the request.POST information
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:
                customer = stripe.Customer.create(
                    email = form.cleaned_data['email'],
                    card = form.cleaned_data['stripe_id'],
                    plan = 'REG_MONTHLY',
                )

            except stripe.error.CardError, e:
                messages.error(request, "Your (valid) card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'),
                                        password = request.POST.get('password1'))
                if user:
                    auth.login(request,user)

                    messages.success(request, "You have successfully registered. Your customer id number is")
                    return redirect(reverse('profile'))
            else:
                messages.error(request,'Unable to log you in at this time!')
        else:
            messages.error(request, "We were unable to take a payment with that card!")
开发者ID:amcevoy83,项目名称:musichub,代码行数:33,代码来源:views.py

示例2: register

def register(request):
    if request.method == "POST":
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data["email"], card=form.cleaned_data["stripe_id"], plan="REG_MONTHLY"
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get("email"), password=request.POST.get("password1"))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse("profile"))

                else:
                    messages.error(request, "We were unable to log you in at this time")
            else:
                messages.error(request, "We were unable to take payment from the card provided")
开发者ID:DarraghB1992,项目名称:wearesocial,代码行数:28,代码来源:views.py

示例3: register

def register(request):
    """
    Handles the new user's email and password to create their account.
    :param request:
    :return:
    """
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            user = auth.authenticate(email=request.POST.get('email'),
                                     password=request.POST.get('password1'))

            if user:
                messages.success(request, "You have successfully registered")
                return redirect(reverse('profile'))

            else:
                messages.error(request, "unable to log you in at this time!")

    else:
        form = UserRegistrationForm()

    args = {'form': form}
    args.update(csrf(request))

    return render(request, 'register.html', args)
开发者ID:Code-Institute-Org,项目名称:full_stack_solutions,代码行数:28,代码来源:views.py

示例4: register

def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    plan='REG_MONTHLY',
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if 'user_profile_picture' in request.FILES:
                    profile.user_profile_picture = request.FILES['user_profile_picture']

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "We were unable to log you in at this time")
            else:
                messages.error(request, "We were unable to take payment from the card provided")
开发者ID:abmist,项目名称:we_are_social_network,代码行数:33,代码来源:views.py

示例5: register

def register(request):
    if request.method == "POST":
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:
                customer = stripe.Charge.create(
                    amount=499,
                    currency="USD",
                    description=form.cleaned_data["email"],
                    card=form.cleaned_data["stripe_id"],
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")

            if customer.paid:
                form.save()

                user = auth.authenticate(email=request.POST.get("email"), password=request.POST.get("password1"))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse("profile"))

                else:
                    messages.error(request, "unable to log you in at this time!")
            else:
                messages.error(request, "We wer unable to take a payment with that card!")
开发者ID:Mrbrianojee,项目名称:stripe,代码行数:29,代码来源:views.py

示例6: register

def register(request):
    #if we have a post to the url then populate the registration form with the request.POST information
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():

            try:
                #send web services call to stripe - makes association with credit card and customer
                customer = stripe.Charge.create(
                    amount = 499,
                    currency = "EUR",
                    description = form.cleaned_data['email'],
                    card = form.cleaned_data['stripe_id'],
                )
               # print "IM THE CUSTOMER", json.dumps(customer)

            except stripe.error.CardError, e:
                messages.error(request, "Your (valid) card was declined!")

            if customer.paid:
                form.save()
                user = auth.authenticate(email=request.POST.get('email'),
                                         password = request.POST.get('password1'))

                if user:
                    auth.login(request,user)

                    messages.success(request, "You have successfully registered. Your customer id number is")
                    return redirect(reverse('profile'))
                else:
                    messages.error(request,'Unable to log you in at this time!')
            else:
                messages.error(request, "We were unable to take a payment with that card!")
开发者ID:amcevoy83,项目名称:travelblog,代码行数:33,代码来源:views_nosubsription.py

示例7: register

def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'], # this is currently the card token/id#
                    plan='REG_MONTHLY')

            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")
            if customer:
                user = form.save()
                user.stripe_id = customer.stripe_id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()
                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))
                else:
                    messages.error(request, "unable to log you in at this time!")
            else:
                messages.error(request, "unable to log you in at this time!")
开发者ID:GrahamFox,项目名称:DjangoWebsite_Stripe,代码行数:27,代码来源:views.py

示例8: register

def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                        email=form.cleaned_data['email'],
                        card=form.cleaned_data['stripe_id'],  # this is currently the card token/id
                        plan='REG_MONTHLY',
                )

                if customer:
                    user = form.save()  # save here to create the user and get its instance

                    # now we replace the card id with the actual user id for later
                    user.stripe_id = customer.id
                    user.subscription_end = arrow.now().replace(weeks=+4).datetime  # add 4 weeks from now
                    user.save()

                # check we saved correctly and can login
                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "unable to log you in at this time!")

            except stripe.error.CardError, e:
                form.add_error(request, "Your card was declined!")
开发者ID:PatrickMonks,项目名称:we_are_social_blog,代码行数:33,代码来源:views.py

示例9: register

def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                    plan="Sub1"
                )
            except stripe.error.CardError, e:
                messages.error(e._message)
                # messages.error(request, "Your card was declined!")

            if customer:
                user = form.save()
                user.stripe_id = customer.id
                user.subscription_end = arrow.now().replace(weeks=+4).datetime
                user.save()

                user = auth.authenticate(email=request.POST.get('email'),
                                         password=request.POST.get('password1'))

                if user:
                    messages.success(request, "You have successfully registered")
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, "unable to log you in at this time!")

            else:
                messages.error(request, "We were unable to take a payment with that card!")
开发者ID:Cvd2014,项目名称:user-auth,代码行数:32,代码来源:views.py

示例10: register

def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                customer = stripe.Charge.create(
                    amount=499,
                    currency='EUR',
                    description=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],
                )
            except stripe.error.CardError, e:
                messages.error(request, 'Your card was declined')

            if customer.paid:
                console.log(customer)

                form.save()

                user = auth.authenticate(email=request.POST.get('email'), password=request.POST.get('password1'))

                if user:
                    auth.login(request, user)
                    messages.success(request, 'You have successfully registered')
                    return redirect(reverse('profile'))

                else:
                    messages.error(request, 'Unable to log you in at this time ')
            else:
                messages.error(request, 'Unable to take payment with that card')
开发者ID:ScottWoodbyrne,项目名称:AuthUsers,代码行数:30,代码来源:views.py

示例11: register

def register(request):
    data = wrap_data_accounts(request)
    data.update(csrf(request))
    success = False
    if request.method == 'POST':
        reg_form = UserRegistrationForm(request.POST)
        if reg_form.is_valid():
            domain = request.get_host()
            new_user = reg_form.save(domain)
            #username = user.username
            #password = reg_form.cleaned_data.get('password1') # user.password is a hashed value
            #auth_user = authenticate(username=username, password=password)
            #login(request, auth_user)
            success = True
        else:
            for error in reg_form.non_field_errors():
                data['errors'].append(error)
    else:
        reg_form = UserRegistrationForm()
    data['reg_form'] = reg_form
    destination = None
    if success:
        destination = redirect(reverse('account_register_done'))
    else:
        destination = _r('account/register.html', data)
    return destination
开发者ID:hacktoolkit,项目名称:htk-django-skeleton,代码行数:26,代码来源:views.py

示例12: register

def register(request):
    """
    Gets a new users email and password and creates an account.
    """
    context = {}
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            try:
                # create a charge customer object for one off payments.
                # customer = stripe.Charge.create(
                #     amount=999,
                #     currency="USD",
                #     description=form.cleaned_data['email'],
                #     card=form.cleaned_data['stripe_id'],
                # )

                # create a customer object within Stripe using the email and
                # Stripe token/id for a re-occurring subscription.
                customer = stripe.Customer.create(
                    email=form.cleaned_data['email'],
                    card=form.cleaned_data['stripe_id'],  # this is currently the card token/id
                    plan='REG_MONTHLY2',  # name of plan. See 'Plans' in Stripe website.
                )
            except stripe.error.CardError, e:
                messages.error(request, "Your card was declined!")
            else:
                # charge() method above returns a customer object that contains a 'paid' boolean field.
                # If customer.paid:
                # form.save()

                if customer:
                    user = form.save()

                    # Used in updating/cancelling the subscription
                    user.stripe_id = customer.id  # This will be a string of the form ‘cus_XXXXXXXXXXXXXX’)

                    # Arrow is a fast way of dealing with dates and times in Python.
                    # Create a date that is exactly 4 weeks from now and convert it
                    # into a datetime object which is compatible with our DateTimeField
                    # in the User model.
                    user.subscription_end = arrow.now().replace(weeks=+4).datetime

                    user.save()

                    # request.POST.get() - gets specific data
                    user = auth.authenticate(email=request.POST.get('email'),
                                             password=request.POST.get('password1'))

                    if user:
                        auth.login(request, user)  # login customer/user in.
                        messages.success(request, "You have successfully registered.")
                        # reverse refers to the 'name' given to a route in urls.py
                        return redirect(reverse('profile'))

                    else:
                        messages.error(request, "unable to log you in at this time!")

                else:
                    messages.error(request, "We were unable to take payment from the card provided.")
开发者ID:peterbristow,项目名称:codeinstitute-stream-three,代码行数:60,代码来源:views.py

示例13: registration

def registration(request):
    """Render the registration page"""
    if request.user.is_authenticated:
        return redirect(reverse('index'))
         
    if request.method =="POST":
        registration_form = UserRegistrationForm(request.POST)
        
        if registration_form.is_valid():
            registration_form.save()
            
            user = auth.authenticate(username=request.POST['username'], 
                                        password=request.POST['password1'])
            
            if user:
                auth.login(user=user, request=request)
                messages.success(request, "You have successfully registered")
                return redirect(reverse('index'))
            else:
                messages.error(request, "Unable to register your account at this time")
    
    else:
        registration_form = UserRegistrationForm()
            
    
    return render(request, 'registration.html', 
        {"registration_form": registration_form})
开发者ID:sarahcrosby,项目名称:djangoproject,代码行数:27,代码来源:views.py

示例14: register

def register(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()

            user = auth.authenticate(username=request.POST.get('username'), password=request.POST.get('password1'))

            if user:
                messages.success(request, "you have successfully registered, big woop.")
                auth.login(request, user)
                print ("hihihhihihih")
                return redirect(reverse('index'))
            else:
                print ("hi")
                messages.error(request, "unable to log you in at this time!")


    else:
        form = UserRegistrationForm()
        print ("hi-hooooo")
    args = {'form': form}
    args.update(csrf(request))

    return render(request, 'register.html', args)
开发者ID:Shaneoc83,项目名称:DjangoToDo,代码行数:25,代码来源:views.py

示例15: test_registration_form

    def test_registration_form(self):
        form = UserRegistrationForm({
            'password1': 'letmein',
            'password2': 'letmein'
        })

        self.assertTrue(form.is_valid())
        self.assertRaisesMessage(form.ValidationError, "This field is required.", form.clean)
开发者ID:shanemcnulty,项目名称:First_Django_Project,代码行数:8,代码来源:tests.py


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