campingmontagut/deploy/logout.sql
jordi fita mas 5d0861824a Add authentication relations, views, and functions for PostgreSQL
Most of them are exactly the same as we use for Numerus, but with the
main application schema changed to camper.

Closes #1
2023-07-22 01:59:12 +02:00

35 lines
893 B
PL/PgSQL

-- Deploy camper:logout to pg
-- requires: roles
-- requires: schema_auth
-- requires: schema_camper
-- requires: current_user_email
-- requires: current_user_cookie
-- requires: user
begin;
set search_path to camper, auth, public;
create or replace function logout() returns void as
$$
update "user"
set cookie = default
, cookie_expires_at = default
where email = current_user_email()
and cookie = current_user_cookie()
and cookie_expires_at > current_timestamp
and length(cookie) > 30
$$
language sql
security definer
set search_path to auth, camper, pg_temp;
comment on function logout() is
'Removes the cookie and its expiry data from the current user, as returned by current_user_email and current_user_cookie';
revoke execute on function logout() from public;
grant execute on function logout() to employee;
grant execute on function logout() to admin;
commit;