Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1 from fedora-infra/apikey
Browse files Browse the repository at this point in the history
Add an API key field to User
  • Loading branch information
ralphbean committed Jan 20, 2014
2 parents 1d434f2 + 509e6a2 commit 155895a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fmn/lib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class User(BASE):

openid = sa.Column(sa.Text, primary_key=True)
openid_url = sa.Column(sa.Text, unique=True)
# doesn't have to be unique, because we'll require the openid url, too.
api_key = sa.Column(sa.Text)
created_on = sa.Column(sa.DateTime, default=datetime.datetime.utcnow)

@classmethod
Expand All @@ -173,6 +175,11 @@ def by_openid(cls, session, openid):
def all(cls, session):
return session.query(cls).all()

def reset_api_key(self, session):
self.api_key = str(uuid.uuid4())
session.flush()
session.commit()

@classmethod
def get_or_create(cls, session, openid, openid_url, create_defaults=True):
user = cls.by_openid(session, openid)
Expand All @@ -182,7 +189,7 @@ def get_or_create(cls, session, openid, openid_url, create_defaults=True):

@classmethod
def create(cls, session, openid, openid_url, create_defaults):
user = cls(openid=openid, openid_url=openid_url)
user = cls(openid=openid, openid_url=openid_url, api_key=str(uuid.uuid4()))
session.add(user)
session.flush()

Expand Down

0 comments on commit 155895a

Please sign in to comment.