added telegram to frontend

master
b3yond 2018-06-24 00:00:48 +02:00
parent 4aa1bf90af
commit db8110de6e
4 changed files with 36 additions and 0 deletions

9
db.py
View File

@ -90,6 +90,13 @@ class DB(object):
active INTEGER,
FOREIGN KEY(user_id) REFERENCES user(id)
);
CREATE TABLE IF NOT EXISTS telegram_accounts (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
user_id INTEGER,
apikey TEXT,
active INTEGER,
FOREIGN KEY(user_id) REFERENCES user(id)
);
CREATE TABLE IF NOT EXISTS seen_tweets (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
user_id INTEGER,
@ -173,6 +180,8 @@ u\d\d?
uid = json['uid']
self.execute("INSERT INTO email (user_id, email) VALUES(?, ?);",
(uid, json['email']))
self.execute("""INSERT INTO telegram_accounts (user_id, apikey,
active) VALUES(?, ?, ?);""", (uid, "", 1))
self.commit()
user = User(uid)
user.set_city(city)

View File

@ -114,6 +114,14 @@ def update_badwords(user):
return user.state()
@post('/settings/telegram')
@view('template/settings.tpl')
def register_telegram(user):
apikey = request.forms['apikey']
user.set_telegram_key(apikey)
return user.state()
@get('/api/state')
def api_enable(user):
return user.state()

View File

@ -67,6 +67,21 @@
</p>
</section>
<div style="float: left; padding: 1.5em;">
<h2>Connect with Telegram</h2>
<p>
If you have a Telegram account, you can register a bot there. Just write to @botfather. You can find detailed
instructions <a href="https://botsfortelegram.com/project/the-bot-father/" target="_blank">on Bots for
Telegram</a>.
</p>
<p>
The botfather will give you an API key - with the API key, Ticketfrei can use the Telegram bot. Enter it here:
</p>
<form action="/settings/telegram" method="post">
<input type="text" name="apikey" placeholder="Telegram bot API key" id="apikey" required>
<input name='confirm' value='Login with Telegram' type='submit'/>
</div
<div style="float: left; padding: 1.5em;">
<h2>Edit your city page</h2>
<p>

View File

@ -205,6 +205,10 @@ schlitz
(self.uid, ))
return db.cur.fetchall()
def set_telegram_key(self, apikey):
db.execute("UPDATE telegram_accounts SET apikey = ? WHERE user_id = ?;", (apikey, self.uid))
db.commit()
def get_mastodon_app_keys(self, instance):
db.execute("SELECT client_id, client_secret FROM mastodon_instances WHERE instance = ?;", (instance, ))
try: