From b8423f4d05c75094b7b9d09c6f0bb353acc9be1c Mon Sep 17 00:00:00 2001 From: ckonstanski Date: Sat, 25 May 2024 18:03:25 -0600 Subject: initial commit --- sql/functions/auth.insert_user.sql | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 sql/functions/auth.insert_user.sql (limited to 'sql/functions/auth.insert_user.sql') diff --git a/sql/functions/auth.insert_user.sql b/sql/functions/auth.insert_user.sql new file mode 100644 index 0000000..597fd39 --- /dev/null +++ b/sql/functions/auth.insert_user.sql @@ -0,0 +1,59 @@ +drop function auth.insert_user( + p_username character varying, + p_pwd character varying, + p_first_name character varying, + p_last_name character varying, + p_email character varying, + p_phone character varying, + p_active boolean +); + +create or replace function auth.insert_user ( + p_username character varying, + p_pwd character varying, + p_first_name character varying, + p_last_name character varying, + p_email character varying, + p_phone character varying, + p_active boolean +) +returns bigint +as $$ +declare + l_id bigint; +begin + select u.id into l_id + from auth.users u + where u.username = p_username + and u.pwd = digest(p_pwd, 'sha512'); + + if(l_id is null) then + insert into auth.users ( + username, + pwd, + first_name, + last_name, + email, + phone, + active + ) values ( + p_username, + digest(p_pwd, 'sha512'), + p_first_name, + p_last_name, + p_email, + p_phone, + p_active + ); + + select u.id into l_id + from auth.users u + where u.username = p_username + and u.pwd = digest(p_pwd, 'sha512'); + + return l_id; + else + return null; + end if; +end; +$$ language plpgsql; -- cgit v1.3