summaryrefslogtreecommitdiff
path: root/sql/functions/auth.insert_registration.sql
blob: 0f0b73db361071c3c7b40f059e6730f3c10df4fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
drop function auth.insert_registration (
    p_first_name character varying,
    p_last_name character varying,
    p_email character varying,
    p_role_groups text
);

create or replace function auth.insert_registration (
    p_first_name character varying,
    p_last_name character varying,
    p_email character varying,
    p_role_groups text
)
returns bigint
as $$
declare
  l_id bigint;
begin
    insert into auth.registrations (
        hash,
        first_name,
        last_name,
        email,
        role_groups
    ) values (
        digest(concat(cast(current_timestamp as text), random()::text), 'sha512'),
        p_first_name,
        p_last_name,
        p_email,
        p_role_groups
    );

    select id into l_id
    from auth.registrations
    where first_name = p_first_name
        and last_name = p_last_name
        and email = p_email
        and role_groups = p_role_groups;

    return l_id;
end;
$$ language plpgsql;