Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add insert_user() and change_pass().
  • Loading branch information
theory committed Dec 31, 2013
1 parent d58ea2f commit c9b4d68
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
21 changes: 21 additions & 0 deletions deploy/change_pass.sql
@@ -0,0 +1,21 @@
-- Deploy change_pass
-- requires: users
-- requires: appschema

BEGIN;

CREATE OR REPLACE FUNCTION flipr.change_pass(
nick TEXT,
oldpass TEXT,
newpass TEXT
) RETURNS BOOLEAN LANGUAGE plpgsql SECURITY DEFINER AS $$
BEGIN
UPDATE flipr.users
SET password = md5($3)
WHERE nickname = $1
AND password = md5($2);
RETURN FOUND;
END;
$$;

COMMIT;
14 changes: 14 additions & 0 deletions deploy/insert_user.sql
@@ -0,0 +1,14 @@
-- Deploy insert_user
-- requires: users
-- requires: appschema

BEGIN;

CREATE OR REPLACE FUNCTION flipr.insert_user(
nickname TEXT,
password TEXT
) RETURNS VOID LANGUAGE SQL SECURITY DEFINER AS $$
INSERT INTO flipr.users VALUES($1, md5($2));
$$;

COMMIT;
7 changes: 7 additions & 0 deletions revert/change_pass.sql
@@ -0,0 +1,7 @@
-- Revert change_pass

BEGIN;

DROP FUNCTION flipr.change_pass(TEXT, TEXT, TEXT);

COMMIT;
7 changes: 7 additions & 0 deletions revert/insert_user.sql
@@ -0,0 +1,7 @@
-- Revert insert_user

BEGIN;

DROP FUNCTION flipr.insert_user(TEXT, TEXT);

COMMIT;
2 changes: 2 additions & 0 deletions sqitch.plan
Expand Up @@ -4,3 +4,5 @@

appschema 2013-12-30T23:19:45Z Marge N. O’Vera <marge@example.com> # Add schema for all flipr objects.
users [appschema] 2013-12-30T23:49:00Z Marge N. O’Vera <marge@example.com> # Creates table to track our users.
insert_user [users appschema] 2013-12-30T23:57:36Z Marge N. O’Vera <marge@example.com> # Creates a function to insert a user.
change_pass [users appschema] 2013-12-30T23:57:45Z Marge N. O’Vera <marge@example.com> # Creates a function to change a user password.
7 changes: 7 additions & 0 deletions verify/change_pass.sql
@@ -0,0 +1,7 @@
-- Verify change_pass

BEGIN;

SELECT has_function_privilege('flipr.change_pass(text, text, text)', 'execute');

ROLLBACK;
7 changes: 7 additions & 0 deletions verify/insert_user.sql
@@ -0,0 +1,7 @@
-- Verify insert_user

BEGIN;

SELECT has_function_privilege('flipr.insert_user(text, text)', 'execute');

ROLLBACK;

0 comments on commit c9b4d68

Please sign in to comment.