Permalink
Browse files

stop user from creating multiple memberships based on ticket from bri…

…an.. github issue #3. also include a helpful readme
  • Loading branch information...
1 parent 41725ab commit d7d609d9de74da5a3e6d53125545077104393bb0 jonathan committed Apr 13, 2011
Showing with 59 additions and 12 deletions.
  1. +47 −12 main.py
  2. +12 −0 readme.txt
View
59 main.py
@@ -93,24 +93,54 @@ def post(self):
self.response.out.write(template.render('templates/main.html', {
'is_prod': is_prod, 'plan': plan, 'message': "Sorry, we need all three fields."}))
else:
- existing_member = Membership.get_by_email(email)
- if existing_member and existing_member.status in [None, 'paypal']:
- existing_member.delete()
- membership = Membership(
- first_name=first_name, last_name=last_name, email=email, plan=plan)
- if self.request.get('paypal') == '1':
- membership.status = 'paypal'
- membership.hash = hashlib.md5(membership.email).hexdigest()
- membership.referrer = self.request.get('referrer')
- membership.put()
+ # this just runs a check twice. (there is no OR in GQL)
+ # first name, last name
+ existing_member = db.GqlQuery("SELECT * FROM Membership WHERE first_name = '%s' AND last_name = '%s'" % (first_name, last_name)).get()
+ if existing_member:
+ membership = existing_member
+ # email
+ existing_member = db.GqlQuery("SELECT * FROM Membership WHERE email = '%s'" % email).get()
+ if existing_member:
+ membership = existing_member
+
+ first_part = re.compile(r'[^\w]').sub('', first_name.split(' ')[0])
+ last_part = re.compile(r'[^\w]').sub('', last_name)
+ if len(first_part)+len(last_part) >= 15:
+ last_part = last_part[0]
+ username = '.'.join([first_part, last_part]).lower()
+ if username in fetch_usernames():
+ username = email.split('@')[0].lower()
+
+ # username@hackerdojo.com
+ existing_member = db.GqlQuery("SELECT * FROM Membership WHERE email = '%s@hackerdojo.com'" % username).get()
+ if existing_member:
+ membership = existing_member
+
+ try:
+ membership
+ except NameError:
+ membership = None
+
+ # old code below
+ #existing_member = Membership.get_by_email(email)
+ #if existing_member and existing_member.status in [None, 'paypal']:
+ # existing_member.delete()
+ if membership is None:
+ membership = Membership(
+ first_name=first_name, last_name=last_name, email=email, plan=plan)
+ if self.request.get('paypal') == '1':
+ membership.status = 'paypal'
+ membership.hash = hashlib.md5(membership.email).hexdigest()
+ membership.referrer = self.request.get('referrer')
+ membership.put()
self.redirect('/account/%s' % membership.hash)
class AccountHandler(webapp.RequestHandler):
def get(self, hash):
membership = Membership.get_by_hash(hash)
-
+ # steal this part to detect if they registered with hacker dojo email above
first_part = re.compile(r'[^\w]').sub('', membership.first_name.split(' ')[0]) # First word of first name
last_part = re.compile(r'[^\w]').sub('', membership.last_name)
if len(first_part)+len(last_part) >= 15:
@@ -155,8 +185,13 @@ def post(self, hash):
query_str = urllib.urlencode({'first_name': membership.first_name, 'last_name': membership.last_name,
'email': membership.email, 'return_url': 'http://%s/success/%s' % (self.request.host, membership.hash)})
- self.redirect("https://spreedly.com/%s/subscribers/%s/subscribe/%s/%s?%s" %
+ # check if they are active already since we didn't create a new member above
+ # apparently the URL will be different
+ if membership.status != "active":
+ self.redirect("https://spreedly.com/%s/subscribers/%s/subscribe/%s/%s?%s" %
(SPREEDLY_ACCOUNT, customer_id, PLAN_IDS[membership.plan], username, query_str))
+ else:
+ self.redirect("https://www.spreedly.com/%s/subscriber_accounts/%s" % (SPREEDLY_ACCOUNT, membership.spreedly_token))
class CreateUserTask(webapp.RequestHandler):
View
@@ -0,0 +1,12 @@
+How to Work on this app
+
+Keymaster Error:
+Navigate to /_km/key
+Login as admin
+Add the below as a key value pair
+spreedly:hackerdojotest = e0cbfb79cc82ba9b5ff21ec2441feee92f535b7e
+Note: no = sign in the actual pair
+
+Trick the App into thinking Spreedly posted to it:
@dustball

dustball Apr 13, 2011

Could use a little more explanation about what is actually happening. Also note the subscriber_id won't always be one. The developer should login with SDK console to find out what ID was created.

+curl http://localhost:8080/update -v --data-ascii subscriber_ids=1
+Note: Don't forget to use the correct port

0 comments on commit d7d609d

Please sign in to comment.