Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up the distribution boilerplate and random paypal registration st…
…uff that is all borken.
- Loading branch information
Dusty Phillips
committed
Jun 16, 2010
1 parent
3590dad
commit 4bf133d
Showing
10 changed files
with
213 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.1, 2010-06-16 -- Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
Copyright (c) 2010, Dusty Phillips | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of the author nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include *.txt | ||
recursive-include docs *.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from django.conf import settings | ||
from django.contrib.sites.models import RequestSite | ||
from django.contrib.sites.models import Site | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# Edited version of the django_registration defaultbackend | ||
from django.conf import settings | ||
from django.contrib.sites.models import RequestSite | ||
from django.contrib.sites.models import Site | ||
|
||
from registration import signals | ||
from registration.forms import RegistrationForm | ||
from paypal_registration.models import RegistrationProfile | ||
|
||
|
||
class PaypalBackend(object): | ||
""" | ||
A registration backend which requires payment from paypal. | ||
The workflow is: | ||
1. User signs up for account. | ||
2. User is directed to paypal to pay for their account. | ||
3. Paypal notifies site that account has been paid for. | ||
4. User receives email containing instructions for activating the account. | ||
5. User activates and begins using the site. | ||
To use it: | ||
* ensure registration and paypal_registration are both in settings.py | ||
INSTALLED_APPS | ||
* run syncdb to install the paypal_registration model | ||
""" | ||
def register(self, request, **kwargs): | ||
""" | ||
Given a username, email address and password, register a new | ||
user account, which will initially be inactive. | ||
Along with the new ``User`` object, a new | ||
``paypal_registration.models.RegistrationProfile`` will be created, | ||
tied to that ``User``, containing the activation key which | ||
will be used for this account, and indicating that they are unpaid. | ||
The user will be redirected to a paypal payment selection page. | ||
After the ``User`` and ``RegistrationProfile`` are created and | ||
the activation email is sent, the signal | ||
``registration.signals.user_registered`` will be sent, with | ||
the new ``User`` as the keyword argument ``user`` and the | ||
class of this backend as the sender. | ||
""" | ||
username, email, password = kwargs['username'], kwargs['email'], kwargs['password1'] | ||
if Site._meta.installed: | ||
site = Site.objects.get_current() | ||
else: | ||
site = RequestSite(request) | ||
new_user = RegistrationProfile.objects.create_inactive_user(username, email, | ||
password, site) | ||
signals.user_registered.send(sender=self.__class__, | ||
user=new_user, | ||
request=request) | ||
return new_user | ||
|
||
def activate(self, request, activation_key): | ||
""" | ||
Given an an activation key, look up and activate the user | ||
account corresponding to that key (if possible). | ||
After successful activation, the signal | ||
``registration.signals.user_activated`` will be sent, with the | ||
newly activated ``User`` as the keyword argument ``user`` and | ||
the class of this backend as the sender. | ||
""" | ||
activated = RegistrationProfile.objects.activate_user(activation_key) | ||
if activated: | ||
signals.user_activated.send(sender=self.__class__, | ||
user=activated, | ||
request=request) | ||
return activated | ||
|
||
def registration_allowed(self, request): | ||
""" | ||
Indicate whether account registration is currently permitted, | ||
based on the value of the setting ``REGISTRATION_OPEN``. This | ||
is determined as follows: | ||
* If ``REGISTRATION_OPEN`` is not specified in settings, or is | ||
set to ``True``, registration is permitted. | ||
* If ``REGISTRATION_OPEN`` is both specified and set to | ||
``False``, registration is not permitted. | ||
""" | ||
return getattr(settings, 'REGISTRATION_OPEN', True) | ||
|
||
def get_form_class(self, request): | ||
""" | ||
Return the default form class used for user registration. | ||
""" | ||
return RegistrationForm | ||
|
||
def post_registration_redirect(self, request, user): | ||
""" | ||
Return the name of the URL to redirect to after successful | ||
user registration. | ||
""" | ||
return ('pay_with_paypal', (), {}) | ||
|
||
def post_activation_redirect(self, request, user): | ||
""" | ||
Return the name of the URL to redirect to after successful | ||
account activation. | ||
""" | ||
return ('registration_activation_complete', (), {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
URLconf for registration and activation, using the paypal_registration backend | ||
If the default behavior of these views is acceptable to you, simply | ||
use a line like this in your root URLconf to set up the default URLs | ||
for registration:: | ||
(r'^accounts/', include('registration.backends.default.urls')), | ||
""" | ||
|
||
|
||
from django.conf.urls.defaults import * | ||
from django.views.generic.simple import direct_to_template | ||
|
||
from registration.views import activate | ||
from registration.views import register | ||
|
||
|
||
urlpatterns = patterns('', | ||
url(r'^activate/complete/$', | ||
direct_to_template, | ||
{'template': 'registration/activation_complete.html'}, | ||
name='registration_activation_complete'), | ||
url(r'^activate/(?P<activation_key>\w+)/$', | ||
activate, | ||
{'backend': 'paypal_registration.PaypalBackend'}, | ||
name='registration_activate'), | ||
url(r'^register/$', | ||
register, | ||
{'backend': 'paypal_registration.PaypalBackend'}, | ||
name='registration_register'), | ||
url(r'^register/complete/$', | ||
direct_to_template, | ||
{'template': 'registration/registration_complete.html'}, | ||
name='registration_complete'), | ||
url(r'^register/closed/$', | ||
direct_to_template, | ||
{'template': 'registration/registration_closed.html'}, | ||
name='registration_disallowed'), | ||
url(r'^pay_with_paypal/(P<username>\w+)/$', | ||
'paypal_registration.views.pay_with_paypal', | ||
name='pay_with_paypal'), | ||
(r'', include('registration.auth_urls')), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
def pay_with_paypal(request, username): | ||
from django.http import HttpResponse | ||
return HttpResponse("paying with paypal today, are we?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from distutils.core import setup | ||
|
||
setup( | ||
name="django-registration-paypal", | ||
version="0.1.0", | ||
author="Dusty Phillips", | ||
author_email="dusty@archlinux.ca", | ||
packages=['paypal_registration'], | ||
url="", | ||
license="LICENSE.txt", | ||
description="django-registration backend to support paypal payments", | ||
long_description=open('README.txt').read(), | ||
) |