numerus/deploy/login.sql

35 lines
772 B
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Deploy numerus:login to pg
-- requires: roles
-- requires: schema_numerus
-- requires: email
-- requires: user
-- requires: find_user_role
begin;
set search_path to numerus, auth;
create or replace function login(email email, password text) returns name as
$$
declare
role name;
begin
select auth.find_user_role(email, password) into role;
if role is null then
raise invalid_password using message = 'invalid user or password';
end if;
return role;
end;
$$
language plpgsql
stable
security definer;
comment on function login(email, text) is
'Checks that the email and password pair is valid and returns the users databasse role.';
revoke execute on function login(email, text) from public;
grant execute on function login(email, text) to guest;
commit;