Mercurial > gemma
diff schema/manage_users.sql @ 185:a9d9c2b1d08c
Add database function to create role and user profile
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 19 Jul 2018 16:37:52 +0200 |
parents | |
children | 5dc8e734487a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/manage_users.sql Thu Jul 19 16:37:52 2018 +0200 @@ -0,0 +1,23 @@ +-- +-- Functions encapsulating user management functionality and +-- exposing it to privileged users +-- + +CREATE OR REPLACE FUNCTION create_user( + userrole varchar, + username user_profiles.username%TYPE, + pw varchar, + country user_profiles.country%TYPE, + map_extent user_profiles.map_extent%TYPE, + email_adress user_profiles.email_adress%TYPE + ) + RETURNS void +AS $$ +BEGIN + INSERT INTO user_profiles VALUES ( + username, country, map_extent, email_adress); + EXECUTE format( + 'CREATE ROLE %I IN ROLE %I LOGIN PASSWORD %L', username, userrole, pw); +END; +$$ +LANGUAGE plpgsql;