31 lines
814 B
PL/PgSQL
31 lines
814 B
PL/PgSQL
-- Deploy tipus:change_password to pg
|
|
-- requires: roles
|
|
-- requires: schema_tipus
|
|
-- requires: schema_auth
|
|
-- requires: user
|
|
|
|
begin;
|
|
|
|
set search_path to tipus, auth, public;
|
|
|
|
create or replace function change_password(new_password text) returns void as
|
|
$$
|
|
update "user"
|
|
set password = new_password
|
|
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, tipus, pg_temp;
|
|
|
|
revoke execute on function change_password(text) from public;
|
|
grant execute on function change_password(text) to publisher;
|
|
grant execute on function change_password(text) to admin;
|
|
|
|
comment on function change_password(text) is
|
|
'Changes the password for the current app user';
|
|
|
|
commit;
|