rDrama/files/routes/settings.py

1013 lines
35 KiB
Python
Raw Normal View History

2022-05-04 23:09:46 +00:00
from __future__ import unicode_literals
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
import os
from shutil import copyfile
import pyotp
import requests
import yt_dlp
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
2023-07-26 17:27:30 +00:00
from sqlalchemy.orm import load_only
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.actions import *
2022-05-04 23:09:46 +00:00
from files.helpers.alerts import *
from files.helpers.config.const import *
from files.helpers.slurs_and_profanities import censor_slurs_profanities
2022-06-24 13:19:53 +00:00
from files.helpers.get import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.mail import *
2023-03-06 19:32:08 +00:00
from files.helpers.media import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.regex import *
from files.helpers.sanitize import *
from files.helpers.sanitize import filter_emojis_only
2022-10-06 22:59:50 +00:00
from files.helpers.security import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.useractions import *
from files.routes.wrappers import *
2022-05-04 23:09:46 +00:00
from .front import frontlist
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.__main__ import app, cache, limiter
@app.get("/settings")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
2023-07-30 00:42:06 +00:00
def settings(v):
return redirect("/settings/personal")
@app.get("/settings/personal")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
2023-07-30 00:42:06 +00:00
def settings_personal(v):
2023-09-17 20:14:41 +00:00
return render_template("settings/personal.html", v=v, msg=get_msg(), error=get_error())
2022-05-04 23:09:46 +00:00
@app.post('/settings/remove_background')
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-11-06 12:08:39 +00:00
@auth_required
def remove_background(v):
if v.background:
if v.background.startswith('/images/'):
remove_media_using_link(v.background)
v.background = None
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-04 23:09:46 +00:00
return {"message": "Background removed!"}
@app.post('/settings/custom_background')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def upload_custom_background(v):
if g.is_tor: abort(403, "Image uploads are not allowed through TOR!")
if not v.patron:
abort(403, f"Custom site backgrounds are only available to {patron}s!")
file = request.files["file"]
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
background = process_image(name, v)
if background:
if v.background and v.background.startswith('/images/'):
remove_media_using_link(v.background)
v.background = background
2023-03-16 06:27:58 +00:00
g.db.add(v)
return redirect('/settings/personal')
def notify_removed_users(removed_users, kind):
if removed_users and removed_users != 'everyone':
text = f"@{g.v.username} has removed you from their {kind} list!"
cid = notif_comment(text)
for x in removed_users:
add_notif(cid, x, text, pushnotif_url=f'{SITE_FULL}{g.v.url}')
@app.post("/settings/personal")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_personal_post(v):
2022-12-27 05:31:28 +00:00
if v.id == 253 and request.values.get("private"):
abort(403)
2022-05-04 23:09:46 +00:00
updated = False
2022-11-07 03:28:27 +00:00
# begin common selectors #
2023-01-01 11:36:20 +00:00
2023-07-30 00:42:06 +00:00
def update_flag(column_name, request_name):
2022-11-07 02:03:09 +00:00
if not request.values.get(request_name, ''): return False
request_flag = request.values.get(request_name, '') == 'true'
if request_flag != getattr(v, column_name):
setattr(v, column_name, request_flag)
return True
return False
2023-01-01 11:36:20 +00:00
2023-07-30 00:42:06 +00:00
def update_potentially_permanent_flag(column_name, request_name, friendly_name, badge_id):
if not request.values.get(request_name): return False
current_value = getattr(v, column_name)
if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and current_value > 1:
abort(403, f"Cannot change the {friendly_name} setting after you've already set it permanently!")
request_flag = int(request.values.get(request_name, '') == 'true')
if current_value and request_flag and request.values.get("permanent", '') == 'true' and request.values.get("username") == v.username:
if v.client: abort(403, f"Cannot set {friendly_name} permanently from the API")
request_flag = int(time.time())
setattr(v, column_name, request_flag)
if badge_id: badge_grant(v, badge_id)
2023-08-11 21:50:23 +00:00
return {"message": f"You have set the {friendly_name} permanently! Enjoy your new badge!"}
elif current_value != request_flag:
setattr(v, column_name, request_flag)
return True
return False
2023-07-30 00:42:06 +00:00
def set_selector_option(column_name, api_name, valid_values, error_msg="value"):
2022-11-07 03:28:27 +00:00
opt = request.values.get(api_name)
if opt: opt = opt.strip()
if not opt: return False
2023-09-05 14:32:36 +00:00
if opt in valid_values.keys():
2022-11-07 03:28:27 +00:00
setattr(v, column_name, opt)
return True
abort(400, f"'{opt}' is not a valid {error_msg}")
# end common selectors #
background = request.values.get("background", v.background)
2022-11-07 03:50:38 +00:00
if background != v.background and background.endswith(".webp") and len(background) <= 20:
v.background = '/i/backgrounds/' + request.values.get("background")
2022-11-07 03:28:27 +00:00
updated = True
2022-05-04 23:09:46 +00:00
elif request.values.get("reddit", v.reddit) != v.reddit:
reddit = request.values.get("reddit")
if reddit in {'old.reddit.com', 'new.reddit.com', 'reddit.com', 'teddit.net', 'libreddit.hu', 'undelete.pullpush.io'}:
2022-05-04 23:09:46 +00:00
updated = True
v.reddit = reddit
elif request.values.get("poor", v.poor) != v.poor:
updated = True
2023-08-03 20:26:53 +00:00
session['poor'] = request.values.get("poor", v.poor) == 'true'
if session['poor']:
v.show_sigs = False
2023-10-12 19:27:37 +00:00
if v.frontsize > 25:
v.frontsize = 25
2023-01-01 11:36:20 +00:00
slur_filter_updated = updated or update_potentially_permanent_flag("slurreplacer", "slurreplacer", "slur replacer", 192)
if isinstance(slur_filter_updated, bool):
updated = slur_filter_updated
else:
2023-03-16 06:27:58 +00:00
g.db.add(v)
return slur_filter_updated
2023-01-01 11:36:20 +00:00
profanity_filter_updated = updated or update_potentially_permanent_flag("profanityreplacer", "profanityreplacer", "profanity replacer", 190)
if isinstance(profanity_filter_updated, bool):
updated = profanity_filter_updated
else:
2023-03-16 06:27:58 +00:00
g.db.add(v)
return profanity_filter_updated
updated = updated or update_flag("hidevotedon", "hidevotedon")
updated = updated or update_flag("newtab", "newtab")
updated = updated or update_flag("newtabexternal", "newtabexternal")
2024-02-08 00:36:54 +00:00
updated = updated or update_flag("nitter", "nitter")
2023-10-12 14:20:28 +00:00
updated = updated or update_flag("imgsed", "imgsed")
updated = updated or update_flag("controversial", "controversial")
2023-10-05 10:33:01 +00:00
updated = updated or update_flag("show_sigs", "show_sigs")
updated = updated or update_flag("is_private", "private")
2023-08-03 04:57:09 +00:00
updated = updated or update_flag("lifetimedonated_visible", "lifetimedonated_visible")
if not updated and request.values.get("spider", v.spider) != v.spider and v.spider <= 1:
2022-09-25 02:44:19 +00:00
updated = True
v.spider = int(request.values.get("spider") == 'true')
if v.spider: badge_grant(user=v, badge_id=179)
2023-01-01 11:36:20 +00:00
else:
badge = v.has_badge(179)
2023-09-07 15:26:31 +00:00
if badge:
g.db.delete(badge)
2023-08-03 20:40:15 +00:00
elif not updated and request.values.get("cursormarsey", v.cursormarsey) != v.cursormarsey:
updated = True
session["cursormarsey"] = int(request.values.get("cursormarsey") == 'true')
elif not updated and request.values.get("nsfw_warnings", v.nsfw_warnings) != v.nsfw_warnings:
updated = True
session["nsfw_warnings"] = int(request.values.get("nsfw_warnings") == 'true')
elif not updated and IS_EVENT() and request.values.get("event_music", v.event_music) != v.event_music:
2023-12-01 19:31:45 +00:00
if not v.grinch:
abort(403, "You need to award yourself the grinch award to be able to disable event music!")
2023-09-28 23:58:09 +00:00
updated = True
session['event_music'] = request.values.get("event_music", v.event_music) == 'true'
elif not updated and request.values.get("marsify", v.marsify) != v.marsify and v.marsify <= 1:
if not v.patron:
abort(403, f"Perma-marsify is only available to {patron}s!")
updated = True
v.marsify = int(request.values.get("marsify") == 'true')
if v.marsify: badge_grant(user=v, badge_id=170)
else:
badge = v.has_badge(170)
2023-03-16 06:27:58 +00:00
if badge: g.db.delete(badge)
2023-01-01 05:33:09 +00:00
elif not updated and request.values.get("bio") == "" and not request.files.get('file'):
2022-05-04 23:09:46 +00:00
v.bio = None
v.bio_html = None
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your bio has been updated."}
2022-05-04 23:09:46 +00:00
elif not updated and request.values.get("sig") == "":
2022-05-04 23:09:46 +00:00
v.sig = None
v.sig_html = None
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your sig has been updated."}
2022-05-04 23:09:46 +00:00
2023-10-19 16:31:01 +00:00
elif not updated and request.values.get("friends") == "" and v.friends:
removed_users = NOTIFY_USERS(v.friends, v)
notify_removed_users(removed_users, 'friends')
2022-05-04 23:09:46 +00:00
v.friends = None
v.friends_html = None
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your friends list has been updated."}
2022-05-04 23:09:46 +00:00
2023-10-19 16:31:01 +00:00
elif not updated and request.values.get("enemies") == "" and v.enemies:
removed_users = NOTIFY_USERS(v.enemies, v)
notify_removed_users(removed_users, 'enemies')
2022-05-04 23:09:46 +00:00
v.enemies = None
v.enemies_html = None
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your enemies list has been updated."}
2022-05-04 23:09:46 +00:00
elif not updated and request.values.get("sig"):
if not v.patron:
abort(403, f"Signatures are only available to {patron}s!")
sig = request.values.get("sig").replace('\n','').replace('\r','').strip()
2023-08-16 23:46:42 +00:00
sig = process_files(request.files, v, sig)
sig = sig.strip() # process_files potentially adds characters to the post
if len(sig) > 200:
abort(400, "New signature is too long (max 200 characters)")
2023-08-16 23:46:42 +00:00
2023-02-07 03:31:49 +00:00
sig_html = sanitize(sig, blackjack="signature")
2022-05-04 23:09:46 +00:00
if len(sig_html) > 1000:
2023-08-11 21:50:23 +00:00
abort(400, "Your sig is too long")
2022-05-04 23:09:46 +00:00
2023-08-16 23:46:42 +00:00
v.sig = sig
v.sig_html = sig_html
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your sig has been updated."}
2022-05-04 23:09:46 +00:00
elif not updated and FEATURES['USERS_PROFILE_BODYTEXT'] and request.values.get("friends"):
friends = request.values.get("friends")[:BIO_FRIENDS_ENEMIES_LENGTH_LIMIT]
2022-05-04 23:09:46 +00:00
2023-02-07 03:31:49 +00:00
friends_html = sanitize(friends, blackjack="friends")
2022-05-04 23:09:46 +00:00
if len(friends_html) > BIO_FRIENDS_ENEMIES_HTML_LENGTH_LIMIT:
2023-08-11 21:50:23 +00:00
abort(400, "Your friends list is too long")
2022-05-04 23:09:46 +00:00
friends = friends[:BIO_FRIENDS_ENEMIES_LENGTH_LIMIT]
notify_users = NOTIFY_USERS(friends, v, oldtext=v.friends)
2022-05-04 23:09:46 +00:00
if notify_users:
2023-02-24 02:28:10 +00:00
text = f"@{v.username} has added you to their friends list!"
cid = notif_comment(text)
2023-03-02 00:32:51 +00:00
if notify_users == 'everyone':
alert_everyone(cid)
else:
for x in notify_users:
2023-08-16 23:04:56 +00:00
add_notif(cid, x, text, pushnotif_url=f'{SITE_FULL}{v.url}')
2022-05-04 23:09:46 +00:00
if v.friends:
try:
removed_users = NOTIFY_USERS(v.friends, v, charge=False) - NOTIFY_USERS(friends, v, charge=False)
except TypeError:
pass
else:
notify_removed_users(removed_users, 'friends')
v.friends = friends
2022-05-04 23:09:46 +00:00
v.friends_html=friends_html
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your friends list has been updated."}
2022-05-04 23:09:46 +00:00
elif not updated and FEATURES['USERS_PROFILE_BODYTEXT'] and request.values.get("enemies"):
enemies = request.values.get("enemies")[:BIO_FRIENDS_ENEMIES_LENGTH_LIMIT]
2022-05-04 23:09:46 +00:00
2023-02-07 03:31:49 +00:00
enemies_html = sanitize(enemies, blackjack="enemies")
2022-05-04 23:09:46 +00:00
if len(enemies_html) > BIO_FRIENDS_ENEMIES_HTML_LENGTH_LIMIT:
2023-08-11 21:50:23 +00:00
abort(400, "Your enemies list is too long")
2022-05-04 23:09:46 +00:00
enemies = enemies[:BIO_FRIENDS_ENEMIES_LENGTH_LIMIT]
notify_users = NOTIFY_USERS(enemies, v, oldtext=v.enemies)
2022-05-04 23:09:46 +00:00
if notify_users:
2023-02-24 02:28:10 +00:00
text = f"@{v.username} has added you to their enemies list!"
cid = notif_comment(text)
2023-03-02 00:32:51 +00:00
if notify_users == 'everyone':
alert_everyone(cid)
else:
for x in notify_users:
2023-08-16 23:04:56 +00:00
add_notif(cid, x, text, pushnotif_url=f'{SITE_FULL}{v.url}')
2022-05-04 23:09:46 +00:00
if v.enemies:
try:
removed_users = NOTIFY_USERS(v.enemies, v, charge=False) - NOTIFY_USERS(enemies, v, charge=False)
except TypeError:
pass
else:
notify_removed_users(removed_users, 'enemies')
v.enemies = enemies
2022-05-04 23:09:46 +00:00
v.enemies_html=enemies_html
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your enemies list has been updated."}
2022-05-04 23:09:46 +00:00
elif not updated and FEATURES['USERS_PROFILE_BODYTEXT'] and \
(request.values.get("bio") or request.files.get('file')):
2023-10-18 18:23:53 +00:00
bio = request.values.get("bio", "")[:BIO_FRIENDS_ENEMIES_LENGTH_LIMIT]
2023-02-26 12:08:37 +00:00
bio = process_files(request.files, v, bio)
2022-05-22 10:26:59 +00:00
bio = bio.strip()
2023-02-07 03:31:49 +00:00
bio_html = sanitize(bio, blackjack="bio")
2022-05-04 23:09:46 +00:00
if len(bio_html) > BIO_FRIENDS_ENEMIES_HTML_LENGTH_LIMIT:
2023-08-11 21:50:23 +00:00
abort(400, "Your bio is too long")
2022-05-04 23:09:46 +00:00
v.bio = bio[:BIO_FRIENDS_ENEMIES_LENGTH_LIMIT]
2022-05-04 23:09:46 +00:00
v.bio_html=bio_html
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your bio has been updated."}
2022-05-04 23:09:46 +00:00
frontsize = request.values.get("frontsize")
if frontsize:
frontsize = int(frontsize)
if frontsize in PAGE_SIZES:
v.frontsize = frontsize
2022-05-04 23:09:46 +00:00
updated = True
cache.delete_memoized(frontlist)
else: abort(400)
2023-01-01 11:36:20 +00:00
2022-11-07 03:28:27 +00:00
updated = updated or set_selector_option("defaultsortingcomments", "defaultsortingcomments", COMMENT_SORTS, "comment sort")
2023-09-05 14:32:36 +00:00
updated = updated or set_selector_option("defaultsorting", "defaultsorting", POST_SORTS, "post sort")
2022-11-07 03:28:27 +00:00
updated = updated or set_selector_option("defaulttime", "defaulttime", TIME_FILTERS, "time filter")
2022-05-04 23:09:46 +00:00
theme = request.values.get("theme")
2022-11-07 03:28:27 +00:00
if not updated and theme:
if theme in THEMES:
if v.theme == "win98": v.themecolor = DEFAULT_COLOR
2022-05-04 23:09:46 +00:00
v.theme = theme
if theme == "win98": v.themecolor = "30409f"
updated = True
else: abort(400, f"{theme} is not a valid theme")
2022-05-04 23:09:46 +00:00
house = request.values.get("house")
2024-01-31 21:23:57 +00:00
if not updated and house and house in ["None"]+HOUSES and FEATURES['HOUSES']:
2022-08-27 02:57:19 +00:00
if v.bite: abort(403)
if v.house:
if v.house.replace(' Founder', '') == house: abort(409, f"You're already in House {house}")
cost = HOUSE_SWITCH_COST
2023-01-01 11:36:20 +00:00
else:
cost = HOUSE_JOIN_COST
2022-05-04 23:09:46 +00:00
success = v.charge_account('coins/marseybux', cost)[0]
2022-11-01 05:25:19 +00:00
if not success: abort(403)
2022-05-04 23:09:46 +00:00
2024-01-31 22:00:08 +00:00
if house == "None":
house = ''
2024-01-31 22:02:01 +00:00
elif SITE == 'watchpeopledie.tv' and time.time() < 1707343158:
2024-01-31 22:00:08 +00:00
house += ' Founder'
2022-05-04 23:09:46 +00:00
v.house = house
updated = True
if updated:
2023-03-16 06:27:58 +00:00
g.db.add(v)
return {"message": "Your settings have been updated!"}
2022-05-04 23:09:46 +00:00
else:
abort(400, "You didn't change anything!")
2022-05-04 23:09:46 +00:00
@app.post("/settings/filters")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-07-30 00:42:06 +00:00
def filters(v):
filters = request.values.get("filters", "").strip()
2022-05-04 23:09:46 +00:00
if filters == v.custom_filter_list:
2023-08-11 21:50:23 +00:00
abort(400, "You didn't change anything!")
2022-05-04 23:09:46 +00:00
if len(filters) > 1000:
abort(400, "Filters are too long (max 1000 characters)")
2022-05-04 23:09:46 +00:00
v.custom_filter_list=filters
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your custom filters have been updated!"}
2022-05-04 23:09:46 +00:00
2023-08-11 21:50:23 +00:00
def set_color(v, attr):
color = request.values.get(attr)
current = getattr(v, attr)
color = color.strip().lower() if color else None
if color:
if color.startswith('#'): color = color[1:]
if not color_regex.fullmatch(color):
return render_template("settings/personal.html", v=v, error="Invalid color hex code!")
if color and current != color:
setattr(v, attr, color)
2023-03-16 06:27:58 +00:00
g.db.add(v)
return render_template("settings/personal.html", v=v, msg="Color successfully updated!")
2022-05-04 23:09:46 +00:00
@app.post("/settings/namecolor")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def namecolor(v):
2023-08-11 21:50:23 +00:00
return set_color(v, "namecolor")
2023-01-01 11:36:20 +00:00
2022-05-04 23:09:46 +00:00
@app.post("/settings/themecolor")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def themecolor(v):
2023-08-11 21:50:23 +00:00
return set_color(v, "themecolor")
2022-05-04 23:09:46 +00:00
2023-10-17 18:54:02 +00:00
@app.post("/settings/flaircolor")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-10-17 18:54:02 +00:00
def flaircolor(v):
return set_color(v, "flaircolor")
2022-05-04 23:09:46 +00:00
@app.post("/settings/verifiedcolor")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def verifiedcolor(v):
if not v.verified: abort(403, "You don't have a checkmark to edit its color!")
2023-08-11 21:50:23 +00:00
return set_color(v, "verifiedcolor")
2022-05-04 23:09:46 +00:00
@app.post("/settings/security")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_security_post(v):
if request.values.get("new_password"):
if request.values.get("new_password") != request.values.get("cnf_password"):
2023-08-11 21:50:23 +00:00
abort(400, "Passwords do not match!")
2022-05-04 23:09:46 +00:00
if not valid_password_regex.fullmatch(request.values.get("new_password")):
2023-08-11 21:50:23 +00:00
abort(400, "Password must be between 8 and 100 characters!")
2022-05-04 23:09:46 +00:00
if not v.verifyPass(request.values.get("old_password")):
2023-08-11 21:50:23 +00:00
abort(400, "Incorrect password")
2022-05-04 23:09:46 +00:00
2022-10-06 22:59:50 +00:00
v.passhash = hash_password(request.values.get("new_password"))
2022-05-04 23:09:46 +00:00
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Your password has been changed successfully!"}
2022-05-04 23:09:46 +00:00
if request.values.get("new_email"):
if not v.verifyPass(request.values.get('password')):
return render_template("settings/security.html", v=v, error="Invalid password!")
2022-05-04 23:09:46 +00:00
new_email = request.values.get("new_email","").strip().lower()
if new_email == v.email:
return render_template("settings/security.html", v=v, error="This email is already yours!")
2022-05-04 23:09:46 +00:00
url = f"{SITE_FULL}/activate"
now = int(time.time())
token = generate_hash(f"{new_email}+{v.id}+{now}")
params = f"?email={quote(new_email)}&id={v.id}&time={now}&token={token}"
link = url + params
send_mail(to_address=new_email,
2022-09-04 23:15:37 +00:00
subject="Verify your email address.",
html=render_template("email/email_change.html",
action_url=link,
v=v)
)
2022-05-04 23:09:46 +00:00
return render_template("settings/security.html", v=v, msg="We have sent you an email, click the verification link inside it to complete the email change. Check your spam folder if you can't find it!")
2022-05-04 23:09:46 +00:00
if request.values.get("2fa_token"):
if not v.verifyPass(request.values.get('password')):
2023-08-11 21:50:23 +00:00
abort(400, "Invalid password!")
2022-05-04 23:09:46 +00:00
secret = request.values.get("2fa_secret")
x = pyotp.TOTP(secret)
if not x.verify(request.values.get("2fa_token"), valid_window=1):
2023-08-11 21:50:23 +00:00
abort(400, "Invalid token!")
2022-05-04 23:09:46 +00:00
v.mfa_secret = secret
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Two-factor authentication enabled!"}
2022-05-04 23:09:46 +00:00
if request.values.get("2fa_remove"):
if not v.verifyPass(request.values.get('password')):
2023-08-11 21:50:23 +00:00
abort(400, "Invalid password!")
2022-05-04 23:09:46 +00:00
token = request.values.get("2fa_remove")
2022-12-20 21:15:24 +00:00
if not token or not v.validate_2fa(token):
2023-08-11 21:50:23 +00:00
abort(400, "Invalid token!")
2022-05-04 23:09:46 +00:00
v.mfa_secret = None
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Two-factor authentication disabled!"}
2022-05-04 23:09:46 +00:00
@app.post("/settings/log_out_all_others")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_log_out_others(v):
submitted_password = request.values.get("password", "").strip()
if not v.verifyPass(submitted_password):
2023-08-11 21:50:23 +00:00
abort(400, "Incorrect password!")
2022-05-04 23:09:46 +00:00
v.login_nonce += 1
session["login_nonce"] = v.login_nonce
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "All other devices have been logged out!"}
2022-05-04 23:09:46 +00:00
@app.post("/settings/images/profile")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_images_profile(v):
if g.is_tor: abort(403, "Image uploads are not allowed through TOR!")
2022-05-04 23:09:46 +00:00
file = request.files["profile"]
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
highres = process_image(name, v)
2022-05-04 23:09:46 +00:00
if not highres: abort(400)
name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2)
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
imageurl = process_image(name2, v, resize=100)
2022-05-04 23:09:46 +00:00
if not imageurl: abort(400)
2023-02-17 14:21:12 +00:00
if v.highres and '/images/' in v.highres and path.isfile(v.highres):
remove_media_using_link(v.highres)
2022-12-05 15:10:15 +00:00
2023-02-17 14:21:12 +00:00
if v.profileurl and '/images/' in v.profileurl and path.isfile(v.profileurl):
remove_media_using_link(v.profileurl)
2023-02-17 14:21:12 +00:00
2022-05-04 23:09:46 +00:00
v.highres = highres
v.profileurl = imageurl
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-04 23:09:46 +00:00
2023-01-25 03:18:17 +00:00
cache.delete_memoized(get_profile_picture, v.id)
cache.delete_memoized(get_profile_picture, v.username)
cache.delete_memoized(get_profile_picture, v.original_username)
2023-11-25 21:57:15 +00:00
cache.delete_memoized(get_profile_picture, v.extra_username)
2023-05-13 04:53:14 +00:00
cache.delete_memoized(get_profile_picture, v.prelock_username)
2022-05-04 23:09:46 +00:00
2023-01-27 11:48:48 +00:00
return redirect("/settings/personal?msg=Profile picture successfully updated!")
2022-05-04 23:09:46 +00:00
@app.post("/settings/images/banner")
2022-11-14 15:11:05 +00:00
@feature_required('USERS_PROFILE_BANNER')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_images_banner(v):
if g.is_tor: abort(403, "Image uploads are not allowed through TOR!")
2022-05-04 23:09:46 +00:00
file = request.files["banner"]
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
bannerurl = process_image(name, v)
2022-05-04 23:09:46 +00:00
if bannerurl:
2022-12-23 21:44:47 +00:00
if v.bannerurl and '/images/' in v.bannerurl and path.isfile(v.bannerurl):
remove_media_using_link(v.bannerurl)
2022-05-04 23:09:46 +00:00
v.bannerurl = bannerurl
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-04 23:09:46 +00:00
2023-01-27 11:48:48 +00:00
return redirect("/settings/personal?msg=Banner successfully updated!")
2022-05-04 23:09:46 +00:00
@app.post("/settings/images/profile_background")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def settings_images_profile_background(v):
if g.is_tor: abort(403, "Image uploads are not allowed through TOR!")
file = request.files["profile_background"]
name = f'/images/{time.time()}'.replace('.','') + '.webp'
file.save(name)
profile_background = process_image(name, v)
if profile_background:
if v.profile_background and '/images/' in v.profile_background and path.isfile(v.profile_background):
remove_media_using_link(v.profile_background)
v.profile_background = profile_background
g.db.add(v)
2023-08-18 19:01:56 +00:00
badge_grant(badge_id=193, user=v)
return redirect("/settings/personal?msg=Profile background successfully updated!")
2022-05-04 23:09:46 +00:00
@app.get("/settings/css")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-07-30 00:42:06 +00:00
def settings_css_get(v):
2023-08-11 21:50:23 +00:00
return render_template("settings/css.html", v=v, profilecss=v.profilecss)
2022-05-04 23:09:46 +00:00
@app.post("/settings/css")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_css(v):
2023-08-11 21:50:23 +00:00
if v.chud:
abort(400, "Chudded users can't edit CSS!")
2023-12-24 21:53:49 +00:00
css = request.values.get("css", v.css).strip().replace('\\', '')
if len(css) > CSS_LENGTH_LIMIT:
abort(400, f"CSS is too long (max {CSS_LENGTH_LIMIT} characters)")
2022-05-04 23:09:46 +00:00
v.css = css
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Custom CSS successfully updated!"}
2022-05-04 23:09:46 +00:00
@app.post("/settings/profilecss")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_profilecss(v):
2023-12-24 21:53:49 +00:00
profilecss = request.values.get("profilecss", v.profilecss).strip().replace('\\', '')
if len(profilecss) > CSS_LENGTH_LIMIT:
abort(400, f"Profile CSS is too long (max {CSS_LENGTH_LIMIT} characters)")
valid, error = validate_css(profilecss)
if not valid:
2023-08-11 21:50:23 +00:00
abort(400, error)
2022-05-04 23:09:46 +00:00
v.profilecss = profilecss
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Profile CSS successfully updated!"}
@app.get("/settings/security")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
2023-07-30 00:42:06 +00:00
def settings_security(v):
return render_template("settings/security.html",
v=v,
mfa_secret=pyotp.random_base32() if not v.mfa_secret else None,
now=int(time.time()),
)
2022-05-04 23:09:46 +00:00
@app.get("/settings/blocks")
@auth_required
2023-07-30 00:42:06 +00:00
def settings_blocks(v):
2023-09-07 08:51:51 +00:00
return redirect(f'/@{v.username}/blocking')
2023-09-07 08:51:57 +00:00
@app.post("/block_user")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit("20/day", deduct_when=lambda response: response.status_code < 400)
@limiter.limit("20/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_block_user(v):
user = get_user(request.values.get("username"))
2023-01-01 11:36:20 +00:00
2022-05-04 23:09:46 +00:00
if user.unblockable:
send_notification(user.id, f"@{v.username} has tried to block you and failed because of your unblockable status!")
g.db.commit()
2022-11-12 10:11:46 +00:00
abort(403, f"@{user.username} is unblockable!")
2022-05-04 23:09:46 +00:00
if user.id == v.id: abort(400, "You can't block yourself")
2022-11-12 10:11:46 +00:00
if user.id == AUTOJANNY_ID: abort(403, f"You can't block @{user.username}")
if v.has_blocked(user): abort(409, f"You have already blocked @{user.username}")
2022-05-04 23:09:46 +00:00
new_block = UserBlock(user_id=v.id, target_id=user.id)
2023-03-16 06:27:58 +00:00
g.db.add(new_block)
2022-05-04 23:09:46 +00:00
2023-09-05 12:30:16 +00:00
send_notification(user.id, f"@{v.username} has blocked you!")
2022-05-04 23:09:46 +00:00
cache.delete_memoized(frontlist)
return {"message": f"@{user.username} blocked!"}
2022-05-04 23:09:46 +00:00
2023-09-07 08:51:57 +00:00
@app.post("/unblock_user")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_unblock_user(v):
user = get_user(request.values.get("username"))
x = v.has_blocked(user)
if not x: abort(409, "You can't unblock someone you haven't blocked")
2023-03-16 06:27:58 +00:00
g.db.delete(x)
2023-09-05 12:30:16 +00:00
send_notification(user.id, f"@{v.username} has unblocked you!")
2022-05-04 23:09:46 +00:00
cache.delete_memoized(frontlist)
2022-12-04 15:40:32 +00:00
return {"message": f"@{user.username} unblocked successfully!"}
2022-05-04 23:09:46 +00:00
@app.get("/settings/apps")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-07-30 00:42:06 +00:00
def settings_apps(v):
return render_template("settings/apps.html", v=v)
2022-05-04 23:09:46 +00:00
@app.get("/settings/advanced")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-07-30 00:42:06 +00:00
def settings_advanced_get(v):
2023-08-11 21:50:23 +00:00
return render_template("settings/advanced.html", v=v)
2022-05-04 23:09:46 +00:00
@app.post("/settings/name_change")
2023-11-25 23:36:03 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
2022-05-04 23:09:46 +00:00
def settings_name_change(v):
2023-07-24 14:41:22 +00:00
if SITE == 'rdrama.net' and v.id == 10489:
abort(403)
if v.namechanged: abort(403)
2023-05-13 04:53:14 +00:00
2024-01-01 21:21:09 +00:00
new_name = request.values.get("name", "").strip()
2022-05-04 23:09:46 +00:00
if new_name == v.username:
2023-08-11 21:50:23 +00:00
abort(400, "You didn't change anything")
2022-05-04 23:09:46 +00:00
if v.patron:
used_regex = valid_username_patron_regex
else:
used_regex = valid_username_regex
if not used_regex.fullmatch(new_name):
2023-08-11 21:50:23 +00:00
abort(400, "This isn't a valid username.")
2022-05-04 23:09:46 +00:00
existing = get_user(new_name, graceful=True)
2022-05-04 23:09:46 +00:00
if existing and existing.id != v.id:
2023-08-11 21:50:23 +00:00
abort(400, f"Username `{new_name}` is already in use.")
2022-05-04 23:09:46 +00:00
2024-01-02 19:09:44 +00:00
if v.patron and v.username != v.original_username:
2023-11-25 21:57:15 +00:00
v.extra_username = v.username
v.username = new_name
if new_name.lower() == v.original_username.lower():
v.original_username = new_name
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-04 23:09:46 +00:00
2023-10-26 20:08:29 +00:00
execute_blackjack(v, None, v.username, 'username')
2023-08-11 21:50:23 +00:00
return {"message": "Name successfully changed!"}
2022-05-24 23:26:50 +00:00
@app.post("/settings/song_change_mp3")
2022-11-14 15:11:05 +00:00
@feature_required('USERS_PROFILE_SONG')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400)
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-24 23:26:50 +00:00
@auth_required
def settings_song_change_mp3(v):
file = request.files['file']
if file.content_type != 'audio/mpeg':
2023-01-27 11:48:48 +00:00
return redirect("/settings/personal?error=Not a valid MP3 file!")
2022-05-24 23:26:50 +00:00
2022-07-10 15:43:27 +00:00
song = str(time.time()).replace('.','')
2023-09-17 20:14:41 +00:00
process_audio(file, v, f'/songs/{song}') #to ensure not malware
2022-05-24 23:26:50 +00:00
2023-03-16 06:27:58 +00:00
if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1:
2023-03-25 15:07:12 +00:00
os.remove(f"/songs/{v.song}.mp3")
2022-07-10 15:43:27 +00:00
v.song = song
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-24 23:26:50 +00:00
2023-01-27 11:48:48 +00:00
return redirect("/settings/personal?msg=Profile Anthem successfully updated!")
2022-05-24 23:26:50 +00:00
def _change_song_youtube(vid, id):
ydl_opts = {
2023-02-25 17:45:13 +00:00
'cookiefile': '/cookies',
2023-02-17 16:42:55 +00:00
'outtmpl': '/temp_songs/%(id)s.%(ext)s',
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try: ydl.download([f"https://youtube.com/watch?v={id}"])
except Exception as e:
print(e, flush=True)
return
2023-02-17 16:42:55 +00:00
os.rename(f"/temp_songs/{id}.mp3", f"/songs/{id}.mp3")
2023-07-28 00:27:01 +00:00
db = db_session()
v = db.query(User).filter_by(id=vid).options(load_only(User.song)).one()
if v.song and path.isfile(f"/songs/{v.song}.mp3") and db.query(User).filter_by(song=v.song).count() == 1:
os.remove(f"/songs/{v.song}.mp3")
v.song = id
db.add(v)
db.commit()
db.close()
stdout.flush()
2022-05-04 23:09:46 +00:00
@app.post("/settings/song_change")
2022-11-14 15:11:05 +00:00
@feature_required('USERS_PROFILE_SONG')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400)
@limiter.limit("10/day", deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
def settings_song_change(v):
2023-08-23 21:57:39 +00:00
song = request.values.get("song").strip()
2022-05-04 23:09:46 +00:00
if song == "" and v.song:
2023-03-16 06:27:58 +00:00
if path.isfile(f"/songs/{v.song}.mp3") and g.db.query(User).filter_by(song=v.song).count() == 1:
2023-03-25 15:07:12 +00:00
os.remove(f"/songs/{v.song}.mp3")
2022-05-04 23:09:46 +00:00
v.song = None
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-01-27 11:48:48 +00:00
return redirect("/settings/personal?msg=Profile Anthem successfully removed!")
2022-05-04 23:09:46 +00:00
song = song.replace("https://music.youtube.com", "https://youtube.com")
if song.startswith(("https://www.youtube.com/watch?v=", "https://youtube.com/watch?v=", "https://m.youtube.com/watch?v=")):
id = song.split("v=")[1]
elif song.startswith("https://youtu.be/"):
id = song.split("https://youtu.be/")[1]
else:
return redirect("/settings/personal?error=Not a YouTube link!")
2022-05-04 23:09:46 +00:00
if "?" in id: id = id.split("?")[0]
if "&" in id: id = id.split("&")[0]
2022-11-22 12:13:44 +00:00
if not yt_id_regex.fullmatch(id):
return redirect("/settings/personal?error=Not a YouTube link!")
2023-12-24 22:00:59 +00:00
2023-01-01 11:36:20 +00:00
if path.isfile(f'/songs/{id}.mp3'):
2022-05-04 23:09:46 +00:00
v.song = id
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-01-27 11:48:48 +00:00
return redirect("/settings/personal?msg=Profile Anthem successfully updated!")
2023-01-01 11:36:20 +00:00
2023-02-17 15:20:51 +00:00
if YOUTUBE_KEY != DEFAULT_CONFIG_VALUE:
2023-09-09 17:06:26 +00:00
req = requests.get(f"https://www.googleapis.com/youtube/v3/videos?id={id}&key={YOUTUBE_KEY}&part=contentDetails", headers=HEADERS, timeout=5).json()
2023-08-25 21:11:32 +00:00
try:
duration = req['items'][0]['contentDetails']['duration']
except:
return redirect("/settings/personal?error=Anthem change failed, please try another video!")
if "D" in duration:
return redirect("/settings/personal?error=Can't use a live youtube video!")
2022-05-04 23:09:46 +00:00
2023-02-17 15:20:51 +00:00
if "H" in duration:
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!")
2022-05-04 23:09:46 +00:00
2023-02-17 15:20:51 +00:00
if "M" in duration:
duration = int(duration.split("PT")[1].split("M")[0])
if duration > 15:
return redirect("/settings/personal?error=Duration of the video must not exceed 15 minutes!")
2023-02-17 15:20:51 +00:00
gevent.spawn(_change_song_youtube, v.id, id)
2022-05-04 23:09:46 +00:00
return redirect("/settings/personal?msg=Profile Anthem successfully updated. Wait 5 minutes for the change to take effect.")
2022-05-04 23:09:46 +00:00
def process_settings_plaintext(value, current, length, default_value):
value = request.values.get(value, "").strip()
if not value:
return default_value
if len(value) > 100:
2023-08-11 21:50:23 +00:00
abort(400, "The value you entered exceeds the character limit (100 characters)")
if value == current:
2023-08-11 21:50:23 +00:00
abort(400, "You didn't change anything!")
return value
2023-10-04 12:29:41 +00:00
@app.post("/settings/change_flair")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-04 23:09:46 +00:00
@auth_required
2023-10-04 12:29:41 +00:00
def settings_change_flair(v):
2022-05-04 23:09:46 +00:00
if v.flairchanged: abort(403)
2023-01-01 11:36:20 +00:00
2023-10-17 18:50:13 +00:00
flair = process_settings_plaintext("flair", v.flair, 100, None)
2022-12-28 09:28:00 +00:00
2023-10-05 10:39:12 +00:00
if flair:
flair_html = filter_emojis_only(flair)
flair_html = censor_slurs_profanities(flair_html, None)
2022-05-04 23:09:46 +00:00
2023-10-05 10:39:12 +00:00
if len(flair_html) > 1000:
abort(400, "Flair too long!")
2023-10-31 20:35:05 +00:00
execute_blackjack(v, None, flair, "flair")
else:
2023-10-05 10:39:12 +00:00
flair_html = None
2022-07-12 20:09:59 +00:00
2023-10-05 10:39:12 +00:00
v.flair = flair
v.flair_html = flair_html
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-05-04 23:09:46 +00:00
2023-08-11 21:50:23 +00:00
return {"message": "Flair successfully updated!"}
2022-05-04 23:09:46 +00:00
2022-07-11 16:46:08 +00:00
@app.post("/settings/pronouns_change")
@feature_required('PRONOUNS')
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-07-11 16:46:08 +00:00
@auth_required
def settings_pronouns_change(v):
pronouns = process_settings_plaintext("pronouns", v.pronouns, 15, "they/them")
2023-08-01 07:38:58 +00:00
2022-07-11 16:46:08 +00:00
if not pronouns_regex.fullmatch(pronouns):
2023-08-11 21:50:23 +00:00
abort(400, "The pronouns you entered don't match the required format!")
2022-07-11 16:46:08 +00:00
2022-08-16 16:16:04 +00:00
bare_pronouns = pronouns.lower().replace('/', '')
if 'nig' in bare_pronouns: pronouns = 'BI/POC'
elif 'fag' in bare_pronouns: pronouns = 'cute/twink'
2022-07-11 16:46:08 +00:00
v.pronouns = pronouns
2023-03-16 06:27:58 +00:00
g.db.add(v)
2022-07-11 16:46:08 +00:00
2023-08-11 21:50:23 +00:00
return {"message": "Pronouns successfully updated!"}
2022-07-11 16:46:08 +00:00
2022-05-10 07:20:49 +00:00
@app.post("/settings/checkmark_text")
2023-02-27 05:33:45 +00:00
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
2022-05-10 07:20:49 +00:00
@auth_required
def settings_checkmark_text(v):
if not v.verified:
abort(403, "You don't have a checkmark to edit its hover text!")
v.verified = process_settings_plaintext("checkmark-text", v.verified, 100, "Verified")
2023-03-16 06:27:58 +00:00
g.db.add(v)
2023-08-11 21:50:23 +00:00
return {"message": "Checkmark Text successfully updated!"}