numerus/deploy/login.sql

42 lines
910 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: schema_auth
-- requires: email
-- requires: user
begin;
set search_path to numerus, auth;
create or replace function login(email email, password text) returns name as
$$
declare
user_role name;
begin
select role
into user_role
from "user"
where "user".email = login.email
and "user".password = crypt(login.password, "user".password);
if user_role is null then
raise invalid_password using message = 'invalid user or password';
end if;
return user_role;
end;
$$
language plpgsql
stable
security definer
set search_path = auth, numerus, pg_temp;
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;