1313
1414@activityinfo_bp .route ('/' )
1515def index ():
16+ """ Home page
17+ If the user has an API key, redirect to databases
18+ If not, show a page to enter the API key
19+ """
20+ extra_vars = {
21+ 'api_key' : get_user_token (current_user .name ),
22+ }
23+ if extra_vars ['api_key' ]:
24+ return toolkit .redirect_to ('activity_info.databases' )
25+ return toolkit .render ('activity_info/index.html' , extra_vars )
26+
27+
28+ @activityinfo_bp .route ('/api-key' )
29+ def api_key ():
30+ """ Create or update the current ActivityInfo API key for the logged-in user.
31+ """
1632 extra_vars = {
1733 'api_key' : get_user_token (current_user .name ),
1834 }
@@ -30,7 +46,7 @@ def databases():
3046 message = f"Could not retrieve ActivityInfo databases: { e } "
3147 log .error (message )
3248 toolkit .h .flash_error (message )
33- return toolkit .redirect_to ('activity_info.index ' )
49+ return toolkit .redirect_to ('activity_info.api_key ' )
3450
3551 log .info (f"Retrieved { ai_databases } " )
3652 # add the ActivityInfo URL to each database
@@ -110,7 +126,7 @@ def update_api_key():
110126 message = 'Missing ActivityInfo API key.'
111127 log .error (message )
112128 toolkit .h .flash_error (message )
113- return toolkit .redirect_to ('activity_info.index ' )
129+ return toolkit .redirect_to ('activity_info.api_key ' )
114130
115131 plugin_extras = get_activity_info_user_plugin_extras (toolkit .c .user ) or {}
116132 activity_info_extras = plugin_extras .get ('activity_info' , {})
@@ -125,7 +141,7 @@ def update_api_key():
125141 }
126142 )
127143 toolkit .h .flash_success ('ActivityInfo API key updated successfully.' )
128- return toolkit .redirect_to ('activity_info.index ' )
144+ return toolkit .redirect_to ('activity_info.api_key ' )
129145
130146
131147@activityinfo_bp .route ('/remove-api-key' , methods = ['POST' ])
@@ -134,7 +150,7 @@ def remove_api_key():
134150 plugin_extras = get_activity_info_user_plugin_extras (toolkit .c .user ) or {}
135151 if not plugin_extras or 'activity_info' not in plugin_extras :
136152 toolkit .h .flash_error ('No ActivityInfo API key found to remove.' )
137- return toolkit .redirect_to ('activity_info.index ' )
153+ return toolkit .redirect_to ('activity_info.api_key ' )
138154
139155 activity_info_extras = plugin_extras .get ('activity_info' , {})
140156 activity_info_extras .pop ('api_key' , None )
@@ -148,4 +164,4 @@ def remove_api_key():
148164 }
149165 )
150166 toolkit .h .flash_success ('ActivityInfo API key removed successfully.' )
151- return toolkit .redirect_to ('activity_info.index ' )
167+ return toolkit .redirect_to ('activity_info.api_key ' )
0 commit comments