From 8d544d58af232e82c740cfcb271d20965020c133 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 21 May 2024 21:11:19 -0400 Subject: things --- src/db/rest/rest.sql | 1 + src/db/rest/user/api_update_password.sql | 44 +++++++++++++++++++++++++++++ src/db/rest/user/api_user_update.sql | 20 ------------- src/public/css/home.css | 2 +- src/web/_views/apps/settings/main.php | 48 ++++++++++++++++++++++++++++++++ src/web/_views/modal/about.php | 7 ++--- src/web/lang/Makefile | 19 ------------- src/web/lang/_bin/transpile.sh | 30 -------------------- src/web/lang/en_US/api_lang.php | 1 + src/web/lang/en_US/apps/settings.php | 6 ++++ src/web/lang/en_US/common_lang.php | 2 +- 11 files changed, 104 insertions(+), 76 deletions(-) create mode 100644 src/db/rest/user/api_update_password.sql delete mode 100644 src/web/lang/Makefile delete mode 100755 src/web/lang/_bin/transpile.sh (limited to 'src') diff --git a/src/db/rest/rest.sql b/src/db/rest/rest.sql index 2b71ebe..6c3fb7d 100644 --- a/src/db/rest/rest.sql +++ b/src/db/rest/rest.sql @@ -26,6 +26,7 @@ GRANT USAGE ON SCHEMA _api TO rest_anon, rest_user; \i /db/rest/user/api_user_insert.sql; \i /db/rest/user/api_user_update.sql; \i /db/rest/user/api_user_delete.sql; +\i /db/rest/user/api_update_password.sql; -- post \i /db/rest/post/api_post.sql; diff --git a/src/db/rest/user/api_update_password.sql b/src/db/rest/user/api_update_password.sql new file mode 100644 index 0000000..34cc1ac --- /dev/null +++ b/src/db/rest/user/api_update_password.sql @@ -0,0 +1,44 @@ +CREATE FUNCTION api.update_password( + current_password TEXT, + new_password TEXT +) +RETURNS void +LANGUAGE plpgsql VOLATILE +AS $BODY$ +DECLARE + _user_id INTEGER; + _real_password TEXT; +BEGIN + _user_id = _api.get_user_id(); + + PERFORM _api.validate_text( + _text => new_password, + _column => 'password', + _min => 1, + _max => 256 + ); + + SELECT password + INTO _real_password + FROM admin.user + WHERE id = _user_id; + + IF _real_password <> current_password THEN + PERFORM _api.raise( + _msg => 'api_invalid_password' + ); + END IF; + + UPDATE + admin.user + SET + "password" = new_password + WHERE + id = _user_id; +END +$BODY$; + +GRANT EXECUTE ON FUNCTION api.update_password(TEXT, TEXT) + TO rest_user; +GRANT SELECT, UPDATE ON TABLE admin.user + TO rest_user; diff --git a/src/db/rest/user/api_user_update.sql b/src/db/rest/user/api_user_update.sql index 2e7cd50..c26c680 100644 --- a/src/db/rest/user/api_user_update.sql +++ b/src/db/rest/user/api_user_update.sql @@ -32,25 +32,6 @@ BEGIN _changed = TRUE; END IF; - -- password - SELECT password - INTO OLD.password - FROM admin.user - WHERE id = OLD.id; - - NEW.password = COALESCE(NEW.password, OLD.password); - NEW.password := _api.trim(NEW.password); - PERFORM _api.validate_text( - _text => NEW.password, - _column => 'password', - _min => 1, - _max => 256 - ); - - IF NEW.password IS DISTINCT FROM OLD.password THEN - _changed = TRUE; - END IF; - -- first name NEW.first_name = COALESCE(NEW.first_name, OLD.first_name); NEW.first_name := _api.trim(NEW.first_name); @@ -138,7 +119,6 @@ BEGIN IF _changed THEN UPDATE admin.user SET username = NEW.username, - password = NEW.password, first_name = NEW.first_name, last_name = NEW.last_name, middle_name = NEW.middle_name, diff --git a/src/public/css/home.css b/src/public/css/home.css index 3fdc381..40e1063 100644 --- a/src/public/css/home.css +++ b/src/public/css/home.css @@ -13,7 +13,7 @@ font-size: 1.5rem; margin: 1rem 0; width: 100%; - height: 70%; + height: 10rem; flex-grow: 1; background-color: transparent; color: var(--text); diff --git a/src/web/_views/apps/settings/main.php b/src/web/_views/apps/settings/main.php index 0cdc4f2..00c1601 100644 --- a/src/web/_views/apps/settings/main.php +++ b/src/web/_views/apps/settings/main.php @@ -54,6 +54,23 @@ function handleSubmit(e) { } +function handlePassword(e) { + e.preventDefault(); + let el = e.target.elements; + let curr = el.curr_password.value; + let newp = el.new_password.value; + + $.ajax({ + url: '/api/rpc/update_password', + method: 'POST', + data: JSON.stringify({ + new_password: newp, + current_password: curr + }), + success: onSuccess + }) +} + const toBase64 = file => new Promise((resolve, reject) => { const reader = new FileReader(); reader.readAsDataURL(file); @@ -111,6 +128,37 @@ function resetMedia(media_type) {
+

+ +
+
+ + +
+
+ + +
+ +
+

diff --git a/src/web/_views/modal/about.php b/src/web/_views/modal/about.php index 746607e..d434908 100644 --- a/src/web/_views/modal/about.php +++ b/src/web/_views/modal/about.php @@ -2,11 +2,10 @@
-
-
- Source Code + Source Code +

For reports of abuse, please email contact@freyacat.org