當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。