-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
70 lines (55 loc) · 1.82 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask_script import Manager
import traceback
import sys
from eve_app import eapp
from sqldb import db, User, Token, Client
manager = Manager(eapp)
@manager.command
def prefill_database():
"""Prefill the database with some default values including the currently
hardcoded client_id and client_secret values
"""
db.create_all()
db.session.commit()
client1 = Client(
name='dev', client_id='dev', client_secret='dev',
_redirect_uris=(
'https://localhost:5000/authorized '
'https://127.0.0.1:5000/authorized '
'https://localhost/authorized'
),
)
client2 = Client(
name='confidential', client_id='confidential',
client_secret='confidential', client_type='confidential',
_redirect_uris=(
'https://localhost:5000/authorized '
'https://127.0.0.1:5000/authorized '
'https://localhost/authorized'
),
)
user = User(username='admin')
access_token = Token(
user_id=1, client_id='dev', access_token='expired', expires_in=0
)
try:
db.session.add(client1)
db.session.add(client2)
db.session.add(user)
db.session.add(access_token)
db.session.commit()
except:
print("Warning: Some SQL Operations have failed. Please review the stack trace and fix it!")
traceback.print_exc(file=sys.stdout)
db.session.rollback()
@manager.command
def delete_token():
user = User.query.filter_by(username='admin').first()
token = Token.query.filter_by(user_id=user.id).first()
# Modifying the admins token value so that the client no longer knows it.
token.access_token='expired'
token.refresh_token='expired'
db.session.add(token)
db.session.commit()
if __name__ == "__main__":
manager.run()