#7 Disable empty First- and Last Names as well as empty Passwords on Sign-Up

This commit is contained in:
Christoph Lienhard 2020-12-27 21:00:53 +01:00
parent 103a137a62
commit b6f6adac22
Signed by: christoph.lienhard
GPG key ID: 6B98870DDC270884
2 changed files with 20 additions and 8 deletions

View file

@ -2,8 +2,8 @@
create table candymat_data.person
(
id serial primary key,
first_name character varying(200),
last_name character varying(200),
first_name character varying(200) check (first_name <> ''),
last_name character varying(200) check (last_name <> ''),
about character varying(2000),
created_at timestamp default now(),
role candymat_data.role not null default 'candymat_person'

View file

@ -16,13 +16,23 @@ grant execute on function candymat_data.current_person() to candymat_person;
create function candymat_data.register_person(
first_name text,
last_name text,
email text,
password text
) returns candymat_data.person as $$
last_name text,
email text,
password text
) returns candymat_data.person as
$$
declare
person candymat_data.person;
begin
if (trim(register_person.first_name) <> '') is not true then
raise 'Invalid first name: ''%''', register_person.first_name;
end if;
if (trim(register_person.last_name) <> '') is not true then
raise 'Invalid last name: ''%''', register_person.last_name;
end if;
if (trim(register_person.password) <> '') is not true then
raise 'Invalid password.';
end if;
insert into candymat_data.person (first_name, last_name)
values ($1, $2)
returning * into person;
@ -31,8 +41,10 @@ begin
values (person.id, $3, crypt($4, gen_salt('bf')));
return person;
end;
$$ language plpgsql strict security definer;
end ;
$$ language plpgsql strict
security definer;
grant execute on function candymat_data.register_person(text, text, text, text) to candymat_anonymous;
create function candymat_data.authenticate(