summaryrefslogtreecommitdiff
path: root/sql/functions/auth.insert_user.sql
diff options
context:
space:
mode:
authorckonstanski <kostcarl@isu.edu>2026-07-18 21:18:18 -0600
committerckonstanski <kostcarl@isu.edu>2026-07-18 21:18:18 -0600
commit08e435104c42751689553537b1f20ffb14b8dfcc (patch)
treef83d8db1a02d4be448ab044d28fda7411470bd7c /sql/functions/auth.insert_user.sql
initial commit
Diffstat (limited to 'sql/functions/auth.insert_user.sql')
-rw-r--r--sql/functions/auth.insert_user.sql59
1 files changed, 59 insertions, 0 deletions
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;