Skip to content
This repository has been archived by the owner. It is now read-only.

Link venmo #1857

Merged
merged 30 commits into from Jan 10, 2014
Merged

Link venmo #1857

Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba597f6
Began adding account linking with Venmo
Jan 7, 2014
ff9ab95
Add venmo api keys for dev, began associate
Jan 7, 2014
dcb34fd
typo
Jan 7, 2014
f167db9
WIP connecting venmo
simon-weber Jan 7, 2014
c3f780b
Save venmo information to db, including oauth
Jan 7, 2014
880663d
Refactor confirm
Jan 7, 2014
8df9b9c
create platform -> class registry for AccountElsewhere
simon-weber Jan 7, 2014
2d6bc4b
leave registry interface as dictionary
simon-weber Jan 7, 2014
3ed0f6e
wip refactor
Jan 7, 2014
6359aea
remove username helpers comment
simon-weber Jan 8, 2014
fbdb2ac
Merge branch 'D-refactor-platforms' into link-venmo
simon-weber Jan 8, 2014
e475555
Merge branch 'refactor-platforms' into link-venmo
simon-weber Jan 8, 2014
2a677c6
Merge branch 'master' into link-venmo
simon-weber Jan 8, 2014
32b7d70
Update/organize default env files
Jan 8, 2014
2d7ee98
use requests.json rather than json.loads
simon-weber Jan 8, 2014
277ca54
DRYer AccountElsewhere
Jan 8, 2014
b763a21
WIP link
Jan 8, 2014
ff7298e
note platform_classes requirement
simon-weber Jan 8, 2014
bcdaa14
Merge branch 'link-venmo' of github.com:venmo/www.gittip.com into lin…
simon-weber Jan 8, 2014
8f5915f
resolve platform_classes ordering
simon-weber Jan 8, 2014
c0029ac
prevent data leakage in %username/public.json
simon-weber Jan 9, 2014
427ae5e
ensure platform_classes is populated at config-time
simon-weber Jan 9, 2014
cac31ca
use platform_classes in configure-aspen
simon-weber Jan 9, 2014
2897cad
Merge branch 'master' into link-venmo
Jan 9, 2014
30988e8
Add openstreetmap to list of accounts
Jan 9, 2014
5262b2c
remove debug line from associate view
Jan 9, 2014
257647a
wrap schema changes in transaction
simon-weber Jan 10, 2014
8a8cffa
remove duplicated ProblemChangingUsername exception
simon-weber Jan 10, 2014
9780f0b
Merge upstream
simon-weber Jan 10, 2014
1d2ce2f
remove unused platforms_ordered import
simon-weber Jan 10, 2014
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

wip refactor

  • Loading branch information...
Thomas Boyt
Thomas Boyt committed Jan 7, 2014
commit 3ed0f6edd3d7c51d04fc46015caff621a8b60850
@@ -6,13 +6,13 @@
from psycopg2 import IntegrityError

import gittip
from gittip.security.user import User
from gittip.models.participant import Participant, reserve_a_random_username
from gittip.models.participant import ProblemChangingUsername
from gittip.utils.username import reserve_a_random_username, ProblemChangingUsername


ACTIONS = [u'opt-in', u'connect', u'lock', u'unlock']

platform_classes = {}


class AccountElsewhere(object):

@@ -34,9 +34,6 @@ def __init__(self, db, user_id, user_info=None):
self.balance = d


def get_participant(self):
return Participant.query.get(username=self.participant)


def set_is_locked(self, is_locked):
self.db.run("""
@@ -51,6 +48,8 @@ def set_is_locked(self, is_locked):
def opt_in(self, desired_username):
"""Given a desired username, return a User object.
"""
from gittip.security.user import User

self.set_is_locked(False)
user = User.from_username(self.participant)
user.sign_in()
@@ -5,6 +5,9 @@
from aspen.utils import typecheck
from psycopg2 import IntegrityError

from gittip.utils.username import reserve_a_random_username, gen_random_usernames
from gittip.elsewhere import platform_classes


# Exceptions
# ==========
@@ -148,9 +151,6 @@ def take_over(self, account_elsewhere, have_confirmation=False):
This is done in one transaction.
"""
# Lazy imports to dodge circular imports.
from gittip.models.participant import reserve_a_random_username
from gittip.models.participant import gen_random_usernames

platform = account_elsewhere.platform
user_id = account_elsewhere.user_id
@@ -11,7 +11,6 @@
from __future__ import print_function, unicode_literals

import datetime
import random
import uuid
from decimal import Decimal

@@ -24,6 +23,7 @@
from gittip.models._mixin_elsewhere import MixinElsewhere
from gittip.models._mixin_team import MixinTeam
from gittip.utils import canonicalize
from gittip.utils.username import reserve_a_random_username, ProblemChangingUsername


ASCII_ALLOWED_IN_USERNAME = set("0123456789"
@@ -682,10 +682,6 @@ def get_age_in_seconds(self):
# Exceptions
# ==========

class ProblemChangingUsername(Exception):
def __str__(self):
return self.msg.format(self.args[0])

class UsernameIsEmpty(ProblemChangingUsername):
msg = "You need to provide a username!"

@@ -708,51 +704,6 @@ class NoSelfTipping(Exception): pass
class BadAmount(Exception): pass


# Username Helpers
# ================

def gen_random_usernames():
"""Yield up to 100 random 12-hex-digit unicodes.
We raise :py:exc:`StopIteration` after 100 usernames as a safety
precaution.
"""
seatbelt = 0
while 1:
yield hex(int(random.random() * 16**12))[2:].zfill(12).decode('ASCII')
seatbelt += 1
if seatbelt > 100:
raise StopIteration


def reserve_a_random_username(txn):
"""Reserve a random username.
:param txn: a :py:class:`psycopg2.cursor` managed as a :py:mod:`postgres`
transaction
:database: one ``INSERT`` on average
:returns: a 12-hex-digit unicode
:raises: :py:class:`StopIteration` if no acceptable username is found
within 100 attempts
The returned value is guaranteed to have been reserved in the database.
"""
for username in gen_random_usernames():
try:
txn.execute( "INSERT INTO participants (username, username_lower) "
"VALUES (%s, %s)"
, (username, username.lower())
)
except IntegrityError: # Collision, try again with another value.
pass
else:
break

return username


def typecast(request):
"""Given a Request, raise Response or return Participant.
@@ -1,6 +1,5 @@
from gittip.models.participant import Participant


class User(object):
"""Represent a user of our website.
"""
@@ -0,0 +1,51 @@
from psycopg2 import IntegrityError
import random

# Username Helpers
# ================

def gen_random_usernames():
"""Yield up to 100 random 12-hex-digit unicodes.
We raise :py:exc:`StopIteration` after 100 usernames as a safety
precaution.
"""
seatbelt = 0
while 1:
yield hex(int(random.random() * 16**12))[2:].zfill(12).decode('ASCII')
seatbelt += 1
if seatbelt > 100:
raise StopIteration


def reserve_a_random_username(txn):
"""Reserve a random username.
:param txn: a :py:class:`psycopg2.cursor` managed as a :py:mod:`postgres`
transaction
:database: one ``INSERT`` on average
:returns: a 12-hex-digit unicode
:raises: :py:class:`StopIteration` if no acceptable username is found
within 100 attempts
The returned value is guaranteed to have been reserved in the database.
"""
for username in gen_random_usernames():
try:
txn.execute( "INSERT INTO participants (username, username_lower) "
"VALUES (%s, %s)"
, (username, username.lower())
)
except IntegrityError: # Collision, try again with another value.
pass
else:
break

return username


class ProblemChangingUsername(Exception):

This comment has been minimized.

Copy link
@chadwhitacre

chadwhitacre Jan 10, 2014

Contributor

This duplicates what's in gittip/exceptions.py, no?

This comment has been minimized.

Copy link
@simon-weber

simon-weber Jan 10, 2014

Contributor

Good catch -- we must have missed that during a merge.

def __str__(self):
return self.msg.format(self.args[0])
@@ -1,6 +1,6 @@
from aspen import Response, log_dammit
from gittip.models.participant import Participant
from gittip.models.participant import ProblemChangingUsername
from gittip.utils.username import ProblemChangingUsername


[-----------------------------------------------------------------------------]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.