decentralized and customizable links page on top of atproto ligo.at
atproto link-in-bio python uv

get user or redirect

+19 -9
+14 -4
src/main.py
··· 116 @app.route("/auth/logout") 117 def auth_logout(): 118 session.clear() 119 - return redirect("/", 303) 120 121 122 @app.get("/editor") 123 async def page_editor(): 124 user = get_user() 125 if user is None: 126 - return redirect("/login") 127 128 did: str = user.did 129 pds: str = user.pds_url ··· 152 async def post_editor_profile(): 153 user = get_user() 154 if user is None: 155 - return redirect("/login", 303) 156 157 display_name = request.form.get("displayName") 158 description = request.form.get("description", "") ··· 177 if success: 178 kv = KV(app, app.logger, "profile_from_did") 179 kv.set(user.did, json.dumps(record)) 180 181 if htmx: 182 return htmx_response( ··· 191 async def post_editor_links(): 192 user = get_user() 193 if user is None: 194 - return redirect("/login", 303) 195 196 links: list[dict[str, str]] = [] 197 hrefs = request.form.getlist("link-href") ··· 232 if success: 233 kv = KV(app, app.logger, "links_from_did") 234 kv.set(user.did, json.dumps(record)) 235 236 if htmx: 237 return htmx_response(
··· 116 @app.route("/auth/logout") 117 def auth_logout(): 118 session.clear() 119 + return redirect(url_for("page_login"), 303) 120 121 122 @app.get("/editor") 123 async def page_editor(): 124 user = get_user() 125 if user is None: 126 + return redirect("/login", 302) 127 128 did: str = user.did 129 pds: str = user.pds_url ··· 152 async def post_editor_profile(): 153 user = get_user() 154 if user is None: 155 + url = url_for("auth_logout") 156 + return htmx_response(redirect=url) if htmx else redirect(url, 303) 157 158 display_name = request.form.get("displayName") 159 description = request.form.get("description", "") ··· 178 if success: 179 kv = KV(app, app.logger, "profile_from_did") 180 kv.set(user.did, json.dumps(record)) 181 + else: 182 + app.logger.warning("log out user for now") 183 + url = url_for("auth_logout") 184 + return htmx_response(redirect=url) if htmx else redirect(url, 303) 185 186 if htmx: 187 return htmx_response( ··· 196 async def post_editor_links(): 197 user = get_user() 198 if user is None: 199 + url = url_for("auth_logout") 200 + return htmx_response(redirect=url) if htmx else redirect(url, 303) 201 202 links: list[dict[str, str]] = [] 203 hrefs = request.form.getlist("link-href") ··· 238 if success: 239 kv = KV(app, app.logger, "links_from_did") 240 kv.set(user.did, json.dumps(record)) 241 + else: 242 + app.logger.warning("log out user for now") 243 + url = url_for("auth_logout") 244 + return htmx_response(redirect=url) if htmx else redirect(url, 303) 245 246 if htmx: 247 return htmx_response(
+5 -1
src/templates/_editor_links.html
··· 6 </template> 7 </div> 8 9 <form 10 method="post" 11 action="/editor/links" ··· 29 <div x-show="!editing"> 30 <link-editor-buttons> 31 <button type="button" @click="editing = true">edit</button> 32 - <button type="button" @click="if (confirm('delete ' + link.title + '?')) links.splice(index, 1)">delete</button> 33 </link-editor-buttons> 34 </div> 35 <div x-show="editing">
··· 6 </template> 7 </div> 8 9 + <noscript> 10 + JavaScript is needed for a better experience configuring the links. 11 + </noscript> 12 + 13 <form 14 method="post" 15 action="/editor/links" ··· 33 <div x-show="!editing"> 34 <link-editor-buttons> 35 <button type="button" @click="editing = true">edit</button> 36 + <button type="button" @click="if (confirm('delete ' + link.title + '?')) { linksChanged = true; links.splice(index, 1); }">delete</button> 37 </link-editor-buttons> 38 </div> 39 <div x-show="editing">
-4
src/templates/editor.html
··· 36 <h2>profile</h2> 37 {% include "_editor_profile.html" %} 38 39 - <noscript> 40 - JavaScript is needed for a better experience configuring the links. 41 - </noscript> 42 - 43 {% include "_editor_links.html" %} 44 45 <footer>
··· 36 <h2>profile</h2> 37 {% include "_editor_profile.html" %} 38 39 {% include "_editor_links.html" %} 40 41 <footer>