This is for security, just in case two users have the same cookie, althought it is unlikely, but nevertheless less guessable. I also need to refresh the cookie when the user changes their email address, because it is liked toghether. It does mean that it will logout from everywhere else, but i can not do anything about that.
24 lines
600 B
PL/PgSQL
24 lines
600 B
PL/PgSQL
-- Deploy numerus:current_user_cookie to pg
|
|
-- requires: schema_numerus
|
|
|
|
begin;
|
|
|
|
set search_path to numerus;
|
|
|
|
create or replace function current_user_cookie() returns text as
|
|
$$
|
|
select current_setting('request.user.cookie', true);
|
|
$$
|
|
language sql
|
|
stable;
|
|
|
|
comment on function current_user_cookie() is
|
|
'Returns the cookie of the current Numerus user';
|
|
|
|
revoke execute on function current_user_cookie() from public;
|
|
grant execute on function current_user_cookie() to guest;
|
|
grant execute on function current_user_cookie() to invoicer;
|
|
grant execute on function current_user_cookie() to admin;
|
|
|
|
commit;
|