forked from ticketfrei/ticketfrei
Merge branch 'multi-deployment' of dl6tom.de:public/ticketfrei into multi-deployment
This commit is contained in:
commit
1af14a5db4
1
db.py
1
db.py
|
@ -79,6 +79,7 @@ class DB(object):
|
|||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
user_id INTEGER,
|
||||
request_token TEXT,
|
||||
request_token_secret TEXT,
|
||||
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS twitter_accounts (
|
||||
|
|
27
frontend.py
27
frontend.py
|
@ -101,21 +101,18 @@ def login_twitter(user):
|
|||
Starts the twitter OAuth authentication process.
|
||||
:return: redirect to twitter.
|
||||
"""
|
||||
consumer_key = config["twitter"]["consumer_key"]
|
||||
consumer_secret = config["twitter"]["consumer_secret"]
|
||||
callback_url = url("login/twitter/callback")
|
||||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret, callback_url)
|
||||
try:
|
||||
consumer_key = config["twitter"]["consumer_key"]
|
||||
consumer_secret = config["twitter"]["consumer_secret"]
|
||||
callback_url = url("/login/twitter/callback")
|
||||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret, callback_url)
|
||||
try:
|
||||
redirect_url = auth.get_authorization_url()
|
||||
except tweepy.TweepError:
|
||||
logger.error('Twitter OAuth Error: Failed to get request token.',
|
||||
exc_info=True)
|
||||
return dict(error="Failed to get request token.")
|
||||
user.save_request_token(auth.request_token)
|
||||
return bottle.redirect(redirect_url)
|
||||
except Exception:
|
||||
logger.error("Error with Sign in with Twitter.", exc_info= True)
|
||||
redirect_url = auth.get_authorization_url()
|
||||
except tweepy.TweepError:
|
||||
logger.error('Twitter OAuth Error: Failed to get request token.',
|
||||
exc_info=True)
|
||||
return dict(error="Failed to get request token.")
|
||||
user.save_request_token(auth.request_token)
|
||||
return bottle.redirect(redirect_url)
|
||||
|
||||
|
||||
@get('/login/twitter/callback')
|
||||
|
@ -174,3 +171,5 @@ bottle.install(SessionPlugin('/'))
|
|||
if __name__ == '__main__':
|
||||
# testing only
|
||||
bottle.run(host='localhost', port=8080)
|
||||
else:
|
||||
application.catchall = False
|
||||
|
|
11
user.py
11
user.py
|
@ -128,16 +128,17 @@ class User(object):
|
|||
return dict(foo='bar')
|
||||
|
||||
def save_request_token(self, token):
|
||||
db.execute("INSERT INTO twitter_request_tokens(user_id, request_token) VALUES(?, ?);",
|
||||
(self.uid, token))
|
||||
db.execute("INSERT INTO twitter_request_tokens(user_id, request_token, request_token_secret) VALUES(?, ?, ?);",
|
||||
(self.uid, token["oauth_token"], token["oauth_token_secret"]))
|
||||
db.commit()
|
||||
|
||||
def get_request_token(self):
|
||||
db.execute("SELECT request_token FROM twitter_request_tokens WHERE user_id = ?;", (id,))
|
||||
request_token = db.cur.fetchone()[0]
|
||||
db.execute("SELECT request_token, request_token_secret FROM twitter_request_tokens WHERE user_id = ?;", (id,))
|
||||
request_token = db.cur.fetchone()
|
||||
db.execute("DELETE FROM twitter_request_tokens WHERE user_id = ?;", (id,))
|
||||
db.commit()
|
||||
return request_token
|
||||
return {"oauth_token" : request_token[0],
|
||||
"oauth_token_secret" : request_token[1]}
|
||||
|
||||
def save_twitter_token(self, access_token, access_token_secret):
|
||||
db.execute(
|
||||
|
|
Loading…
Reference in a new issue