Fix reset password, ambigouis colunm

This commit is contained in:
xbgmsharp
2023-09-24 15:39:28 +02:00
parent f46787ca72
commit 4e1e890ef7

View File

@@ -115,8 +115,9 @@ COMMENT ON FUNCTION
DROP FUNCTION IF EXISTS api.reset; DROP FUNCTION IF EXISTS api.reset;
CREATE OR REPLACE FUNCTION api.reset(in pass text, in token text, in uuid text) returns BOOLEAN CREATE OR REPLACE FUNCTION api.reset(in pass text, in token text, in uuid text) returns BOOLEAN
AS $reset_fn$ AS $reset_fn$
DECLARE DECLARE
_email TEXT := NULL; _email TEXT := NULL;
_pass TEXT := pass;
BEGIN BEGIN
-- Check parameters -- Check parameters
IF token IS NULL OR uuid IS NULL OR pass IS NULL THEN IF token IS NULL OR uuid IS NULL OR pass IS NULL THEN
@@ -124,25 +125,25 @@ AS $reset_fn$
END IF; END IF;
-- Verify token -- Verify token
SELECT auth.verify_otp_fn(token) INTO _email; SELECT auth.verify_otp_fn(token) INTO _email;
IF _email IS NOT NULL THEN IF _email IS NOT NULL THEN
SELECT email INTO _email FROM auth.accounts WHERE user_id = uuid; SELECT email INTO _email FROM auth.accounts WHERE user_id = uuid;
IF _email IS NULL THEN IF _email IS NULL THEN
RETURN False; RETURN False;
END IF; END IF;
-- Set user new password -- Set user new password
UPDATE auth.accounts UPDATE auth.accounts
SET pass = pass SET pass = _pass
WHERE email = _email; WHERE email = _email;
-- Enable email_validation into user preferences -- Enable email_validation into user preferences
PERFORM api.update_user_preferences_fn('{email_valid}'::TEXT, True::TEXT); PERFORM api.update_user_preferences_fn('{email_valid}'::TEXT, True::TEXT);
-- Enable email_notifications -- Enable email_notifications
PERFORM api.update_user_preferences_fn('{email_notifications}'::TEXT, True::TEXT); PERFORM api.update_user_preferences_fn('{email_notifications}'::TEXT, True::TEXT);
-- Delete token when validated -- Delete token when validated
DELETE FROM auth.otp DELETE FROM auth.otp
WHERE user_email = _email; WHERE user_email = _email;
RETURN True; RETURN True;
END IF; END IF;
RETURN False; RETURN False;
END; END;
$reset_fn$ language plpgsql security definer; $reset_fn$ language plpgsql security definer;
-- Description -- Description