feature #4: create procedure for user

This commit is contained in:
2019-07-26 02:47:43 +02:00
parent 578587f430
commit 0a92316128
8 changed files with 100 additions and 4 deletions

View File

@@ -0,0 +1,18 @@
create or replace function check_user(in username text, in plain_password text, out resource json) language plpgsql as
$$
declare
_username alias for username;
begin
select
case when count(u) = 1
then to_json(json_populate_record(null::user_lite, to_json(u))) -- TODO refactor this !
else null end
into resource
from "user" as u
where u.username = lower(_username)
and u.password = crypt(plain_password, u.password)
group by u;
end;
$$;
-- drop function if exists check_user(text, text, out json);