tangled
alpha
login
or
join now
ligo.at
/
core
6
fork
atom
decentralized and customizable links page on top of atproto
ligo.at
atproto
link-in-bio
python
uv
6
fork
atom
overview
issues
2
pulls
pipelines
use flask `session`
nauta.one
5 months ago
42e1fef6
ee68644d
+20
-20
2 changed files
expand all
collapse all
unified
split
.gitignore
src
main.py
+1
.gitignore
···
1
1
+
.env
1
2
.venv
2
3
*.pyc
+19
-20
src/main.py
···
2
2
from atproto.exceptions import AtProtocolError
3
3
from atproto_client.models import ComAtprotoRepoCreateRecord
4
4
from atproto_client.models.app.bsky.actor.defs import ProfileViewDetailed
5
5
-
from flask import Flask, make_response, redirect, render_template, request
5
5
+
from flask import Flask, session, redirect, render_template, request
6
6
from urllib import request as http_request
7
7
import json
8
8
9
9
app = Flask(__name__)
10
10
+
_ = app.config.from_prefixed_env()
11
11
+
10
12
pdss: dict[str, str] = {}
11
13
dids: dict[str, str] = {}
12
14
links: dict[str, list[dict[str, str]]] = {}
···
45
47
46
48
@app.get("/login")
47
49
def page_login():
48
48
-
if "session" in request.cookies:
50
50
+
if "session" in session:
49
51
return redirect("/editor")
50
52
return render_template("login.html")
51
53
52
54
53
55
@app.get("/editor")
54
56
def page_editor():
55
55
-
session = request.cookies.get("session")
56
56
-
if session is None or not session:
57
57
+
sess: str | None = session.get("session")
58
58
+
if sess is None or not sess:
57
59
return redirect("/login")
58
60
client = Client()
59
61
profile: ProfileViewDetailed | None
60
62
try:
61
61
-
profile = client.login(session_string=session)
63
63
+
profile = client.login(session_string=sess)
62
64
except AtProtocolError:
63
63
-
r = make_response(redirect("/login", 303))
64
64
-
r.delete_cookie("session")
65
65
-
return r
65
65
+
session.clear()
66
66
+
return redirect("/login", 303)
66
67
67
68
pds = resolve_pds_from_did(profile.did)
68
69
if not pds:
···
81
82
82
83
@app.post("/editor/profile")
83
84
def post_editor_profile():
84
84
-
session = request.cookies.get("session")
85
85
-
if session is None or not session:
85
85
+
sess: str | None = session.get("session")
86
86
+
if sess is None or not sess:
86
87
return redirect("/login", 303)
87
88
client = Client()
88
88
-
profile = client.login(session_string=session)
89
89
+
profile = client.login(session_string=sess)
89
90
90
91
display_name = request.form.get("displayName")
91
92
description = request.form.get("description") or ""
···
109
110
110
111
@app.post("/editor/links")
111
112
def post_editor_links():
112
112
-
session = request.cookies.get("session")
113
113
-
if session is None or not session:
113
113
+
sess: str | None = session.get("session")
114
114
+
if sess is None or not sess:
114
115
return redirect("/login", 303)
115
116
client = Client()
116
116
-
profile = client.login(session_string=session)
117
117
+
profile = client.login(session_string=sess)
117
118
118
119
links: list[dict[str, str]] = []
119
120
urls = request.form.getlist("link-url")
···
255
256
256
257
@app.route("/auth/logout")
257
258
def auth_logout():
258
258
-
r = make_response(redirect("/"))
259
259
-
r.delete_cookie("session")
260
260
-
return r
259
259
+
session.clear()
260
260
+
return redirect("/")
261
261
262
262
263
263
@app.post("/auth/login")
···
275
275
session_string = client.export_session_string()
276
276
except AtProtocolError:
277
277
return redirect("/login", 303)
278
278
-
r = make_response(redirect("/editor", code=303))
279
279
-
r.set_cookie("session", session_string)
280
280
-
return r
278
278
+
session["session"] = session_string
279
279
+
return redirect("/editor", code=303)