diff --git a/drama/routes/admin.py b/drama/routes/admin.py index 8db5a2e24b..cf616d9860 100644 --- a/drama/routes/admin.py +++ b/drama/routes/admin.py @@ -606,7 +606,6 @@ def admin_title_change(user_id, v): new_name=request.form.get("title").strip() user.customtitleplain=new_name - new_name=new_name.replace('_','\_') new_name = sanitize(new_name, linkgen=True) user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first() @@ -937,7 +936,7 @@ def admin_toggle_ban_domain(v): reason=request.form.get("reason", "").strip() - d = g.db.query(BannedDomain).filter_by(domain=domain.replace("_","\_")).first() + d = g.db.query(BannedDomain).filter_by(domain=domain).first() if d: g.db.delete(d) else: d = BannedDomain(domain=domain, reason=reason) diff --git a/drama/routes/oauth.py b/drama/routes/oauth.py index af0c933d46..16283b14cf 100644 --- a/drama/routes/oauth.py +++ b/drama/routes/oauth.py @@ -206,4 +206,20 @@ def admin_apps_list(v): apps = g.db.query(OauthApp).all() - return render_template("admin/apps.html", v=v, apps=apps) \ No newline at end of file + return render_template("admin/apps.html", v=v, apps=apps) + + +@app.post("/oauth/reroll/") +@auth_required +def reroll_oauth_tokens(aid, v): + + aid = aid + + a = g.db.query(OauthApp).filter_by(id=aid).first() + + if a.author_id != v.id: abort(403) + + a.client_id = secrets.token_urlsafe(64)[:64] + g.db.add(a) + + return {"message": "Client ID Rerolled", "id": a.client_id} \ No newline at end of file diff --git a/drama/routes/posts.py b/drama/routes/posts.py index b5ae29edf0..1a574b59c0 100644 --- a/drama/routes/posts.py +++ b/drama/routes/posts.py @@ -619,11 +619,13 @@ def submit_post(v): embed = requests.get("https://graph.facebook.com/v9.0/instagram_oembed", params={"url":url,"access_token":environ.get("FACEBOOK_TOKEN","").strip(),"omitscript":'true'}, headers={"User-Agent":"Instagram embedder for Drama"}).json()["html"] elif app.config['SERVER_NAME'] in domain: - matches = re.match(re.compile(f"^.*{domain}/post/+\w+/(\w+)(/\w+/(\w+))?"), url) - post_id = matches.group(1) - comment_id = matches.group(3) - if comment_id: embed = f"https://{app.config['SERVER_NAME']}/embed/comment/{comment_id}" - else: embed = f"https://{app.config['SERVER_NAME']}/embed/post/{post_id}" + try: + matches = re.match(re.compile(f"^.*{domain}/post/+\w+/(\w+)(/\w+/(\w+))?"), url) + post_id = matches.group(1) + comment_id = matches.group(3) + if comment_id: embed = f"https://{app.config['SERVER_NAME']}/embed/comment/{comment_id}" + else: embed = f"https://{app.config['SERVER_NAME']}/embed/post/{post_id}" + except: embed = None else: embed = None diff --git a/drama/routes/search.py b/drama/routes/search.py index b16648bdd4..31cd8dc76a 100644 --- a/drama/routes/search.py +++ b/drama/routes/search.py @@ -275,7 +275,6 @@ def searchusers(v): term=term.replace('\\','') term=term.replace('_','\_') - now=int(time.time()) users=g.db.query(User).filter(User.username.ilike(f'%{term}%')) users=users.order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc()) diff --git a/drama/routes/settings.py b/drama/routes/settings.py index 40fb696c4a..78a20e73c0 100644 --- a/drama/routes/settings.py +++ b/drama/routes/settings.py @@ -684,7 +684,6 @@ def settings_title_change(v): error="You didn't change anything") v.customtitleplain = new_name - new_name = new_name.replace('_','\_') new_name = sanitize(new_name, flair=True) v = g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=v.id).first() diff --git a/drama/templates/settings_apps.html b/drama/templates/settings_apps.html index e75d27985d..7c61599f24 100644 --- a/drama/templates/settings_apps.html +++ b/drama/templates/settings_apps.html @@ -29,6 +29,14 @@ + + + {% if app.client_id %} + + + {% endif %} + + @@ -37,7 +45,7 @@ @@ -62,6 +70,12 @@ + + {% if app.client_id %} + + + {% endif %} + @@ -91,7 +105,6 @@
-
diff --git a/schema.sql b/schema.sql index 2312459bbd..48bcc63e06 100644 --- a/schema.sql +++ b/schema.sql @@ -501,17 +501,8 @@ CREATE TABLE public.client_auths ( id integer NOT NULL, user_id integer, oauth_client integer, - scope_identity boolean, - scope_create boolean, - scope_read boolean, - scope_update boolean, - scope_delete boolean, - scope_vote boolean, scope_guildmaster boolean, - access_token character(128), - refresh_token character(128), - oauth_code character(128), - access_token_expire_utc integer + access_token character(128) ); @@ -889,11 +880,9 @@ ALTER SEQUENCE public.notifications_id_seq OWNED BY public.notifications.id; CREATE TABLE public.oauth_apps ( id integer NOT NULL, client_id character(64), - client_secret character(128), app_name character varying(50), redirect_uri character varying(4096), author_id integer, - is_banned boolean, description character varying(256) ); @@ -1681,14 +1670,6 @@ ALTER TABLE ONLY public.client_auths ADD CONSTRAINT unique_access UNIQUE (access_token); --- --- Name: client_auths unique_code; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.client_auths - ADD CONSTRAINT unique_code UNIQUE (oauth_code); - - -- -- Name: oauth_apps unique_id; Type: CONSTRAINT; Schema: public; Owner: postgres -- @@ -1697,22 +1678,6 @@ ALTER TABLE ONLY public.oauth_apps ADD CONSTRAINT unique_id UNIQUE (client_id); --- --- Name: client_auths unique_refresh; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.client_auths - ADD CONSTRAINT unique_refresh UNIQUE (refresh_token); - - --- --- Name: oauth_apps unique_secret; Type: CONSTRAINT; Schema: public; Owner: postgres --- - -ALTER TABLE ONLY public.oauth_apps - ADD CONSTRAINT unique_secret UNIQUE (client_secret); - - -- -- Name: badges user_badge_constraint; Type: CONSTRAINT; Schema: public; Owner: postgres -- @@ -1906,20 +1871,6 @@ CREATE INDEX block_user_idx ON public.userblocks USING btree (user_id); CREATE INDEX cflag_user_idx ON public.commentflags USING btree (user_id); --- --- Name: client_access_token_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX client_access_token_idx ON public.client_auths USING btree (access_token, access_token_expire_utc); - - --- --- Name: client_refresh_token_idx; Type: INDEX; Schema: public; Owner: postgres --- - -CREATE INDEX client_refresh_token_idx ON public.client_auths USING btree (refresh_token); - - -- -- Name: comment_body_idx; Type: INDEX; Schema: public; Owner: postgres --