Created
October 7, 2016 14:09
-
-
Save deinspanjer/1424dff95d8467f215ff9487b75a9997 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION validate_user( | |
| email TEXT | |
| , token UUID | |
| ) | |
| RETURNS BOOL | |
| LANGUAGE plpgsql | |
| AS $$ | |
| DECLARE | |
| BEGIN | |
| IF exists(SELECT | |
| 1 | |
| FROM tokens | |
| WHERE tokens.email = validate_user.username | |
| AND tokens.token = validate_user.token | |
| AND token_type = 'validation') | |
| THEN | |
| UPDATE application.users | |
| SET verified = TRUE | |
| WHERE users.email = validate_user.email; | |
| DELETE FROM tokens | |
| WHERE tokens.email = validate_user.email | |
| AND tokens.token = reset_password.token | |
| AND token_type = 'validation'; | |
| ELSE | |
| RAISE EXCEPTION | |
| USING MESSAGE = 'Invalid user or token'; | |
| END IF; | |
| END; | |
| $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment