Commit ac125b9b by Jan Hrabal

terms

parent 756ea1b4
CREATE DATABASE suite CREATE DATABASE suite
WITH WITH
OWNER = postgres OWNER = postgres
ENCODING = 'utf8' ENCODING = 'utf8'
TABLESPACE = pg_default TABLESPACE = pg_default
CONNECTION LIMIT = -1; CONNECTION LIMIT = -1;
-- --
CREATE SEQUENCE ID_GENERATOR; CREATE SEQUENCE ID_GENERATOR;
-- version procedure -- version procedure
CREATE OR REPLACE FUNCTION process_version_check() RETURNS TRIGGER AS $version_check$ CREATE OR REPLACE FUNCTION process_version_check() RETURNS TRIGGER AS $version_check$
BEGIN BEGIN
IF (OLD.VERSION > NEW.VERSION) THEN IF (OLD.VERSION > NEW.VERSION) THEN
RAISE EXCEPTION 'row_version_conflict' using RAISE EXCEPTION 'row_version_conflict' using
ERRCODE = 99001, ERRCODE = 99001,
MESSAGE = ('Cannot update record % in table %. Actual version: %, provided version %', NEW.ID, TG_TABLE_NAME, OLD.VERSION, NEW.VERSION); MESSAGE = ('Cannot update record % in table %. Actual version: %, provided version %', NEW.ID, TG_TABLE_NAME, OLD.VERSION, NEW.VERSION);
END IF; END IF;
NEW.VERSION = OLD.VERSION + 1; NEW.VERSION = OLD.VERSION + 1;
RETURN NEW; RETURN NEW;
END; END;
$version_check$ LANGUAGE plpgsql; $version_check$ LANGUAGE plpgsql;
-- end of version procedure -- end of version procedure
-- shortid procedure -- shortid procedure
CREATE OR REPLACE FUNCTION pseudo_encrypt(VALUE bigint) returns bigint AS $$ CREATE OR REPLACE FUNCTION pseudo_encrypt(VALUE bigint) returns bigint AS $$
DECLARE DECLARE
l1 int; l1 int;
l2 int; l2 int;
r1 int; r1 int;
r2 int; r2 int;
i int:=0; i int:=0;
BEGIN BEGIN
l1:= (VALUE >> 16) & 65535; l1:= (VALUE >> 16) & 65535;
r1:= VALUE & 65535; r1:= VALUE & 65535;
WHILE i < 3 LOOP WHILE i < 3 LOOP
l2 := r1; l2 := r1;
r2 := l1 # ((((1366 * r1 + 150889) % 714025) / 714025.0) * 32767)::int; r2 := l1 # ((((1366 * r1 + 150889) % 714025) / 714025.0) * 32767)::int;
l1 := l2; l1 := l2;
r1 := r2; r1 := r2;
i := i + 1; i := i + 1;
END LOOP; END LOOP;
RETURN ((r1 << 16) + l1); RETURN ((r1 << 16) + l1);
END; END;
$$ LANGUAGE plpgsql strict immutable; $$ LANGUAGE plpgsql strict immutable;
CREATE OR REPLACE FUNCTION shortid(n bigint) RETURNS text CREATE OR REPLACE FUNCTION shortid(n bigint) RETURNS text
LANGUAGE plpgsql IMMUTABLE STRICT AS $$ LANGUAGE plpgsql IMMUTABLE STRICT AS $$
DECLARE DECLARE
alphabet text:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; alphabet text:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
base int:=length(alphabet); base int:=length(alphabet);
_n bigint:=pseudo_encrypt(abs(n)); _n bigint:=pseudo_encrypt(abs(n));
output text:=''; output text:='';
BEGIN BEGIN
LOOP LOOP
output := output || substr(alphabet, 1+(_n%base)::int, 1); output := output || substr(alphabet, 1+(_n%base)::int, 1);
_n := _n / base; _n := _n / base;
EXIT WHEN _n=0; EXIT WHEN _n=0;
END LOOP; END LOOP;
RETURN output; RETURN output;
END $$; END $$;
-- end of shortid procedure -- end of shortid procedure
CREATE TABLE APP_USER ( CREATE TABLE APP_USER (
ID INT8 NOT NULL, ID INT8 NOT NULL,
VERSION INT8 NOT NULL DEFAULT 0, VERSION INT8 NOT NULL DEFAULT 0,
DELETED BOOLEAN DEFAULT FALSE, DELETED BOOLEAN DEFAULT FALSE,
EMAIL VARCHAR(250) NOT NULL, EMAIL VARCHAR(250) NOT NULL,
PASSWORD VARCHAR(500), PASSWORD VARCHAR(500),
PASSWORD_SALT VARCHAR(250), PASSWORD_SALT VARCHAR(250),
FIRST_NAME VARCHAR(250), FIRST_NAME VARCHAR(250),
LAST_NAME VARCHAR(250), LAST_NAME VARCHAR(250),
TIMEZONE_ID VARCHAR(50), TIMEZONE_ID VARCHAR(50),
LOCALE VARCHAR(50), LOCALE VARCHAR(50),
CONSTRAINT PK_APP_USER PRIMARY KEY(ID) CONSTRAINT PK_APP_USER PRIMARY KEY(ID)
); );
CREATE INDEX APP_USER_EMAIL_IDX ON APP_USER(lower(EMAIL)); CREATE INDEX APP_USER_EMAIL_IDX ON APP_USER(lower(EMAIL));
CREATE TABLE APP_ROLE ( CREATE TABLE APP_ROLE (
ID INT8 NOT NULL, ID INT8 NOT NULL,
NAME VARCHAR(250) NOT NULL, NAME VARCHAR(250) NOT NULL,
CONSTRAINT PK_APP_ROLE PRIMARY KEY(ID) CONSTRAINT PK_APP_ROLE PRIMARY KEY(ID)
); );
CREATE TABLE APP_USER_ROLE ( CREATE TABLE APP_USER_ROLE (
USER_ID INT8 NOT NULL, USER_ID INT8 NOT NULL,
ROLE_ID INT8 NOT NULL ROLE_ID INT8 NOT NULL
); );
CREATE INDEX APP_USER_ROLE_IDX ON APP_USER_ROLE(USER_ID, ROLE_ID); CREATE INDEX APP_USER_ROLE_IDX ON APP_USER_ROLE(USER_ID, ROLE_ID);
CREATE TABLE RESET_PASSWORD_TOKEN ( CREATE TABLE RESET_PASSWORD_TOKEN (
ID INT8 NOT NULL, ID INT8 NOT NULL,
LOGIN VARCHAR(250) NOT NULL, LOGIN VARCHAR(250) NOT NULL,
TOKEN VARCHAR(250) NOT NULL, TOKEN VARCHAR(250) NOT NULL,
USED BOOLEAN DEFAULT FALSE, USED BOOLEAN DEFAULT FALSE,
CREATED TIMESTAMP, CREATED TIMESTAMP,
CONSTRAINT PK_RESET_PASSWORD_TOKEN PRIMARY KEY(ID) CONSTRAINT PK_RESET_PASSWORD_TOKEN PRIMARY KEY(ID)
); );
CREATE INDEX RESET_PASSWORD_TOKEN_LOGIN_IDX ON RESET_PASSWORD_TOKEN(LOGIN); CREATE INDEX RESET_PASSWORD_TOKEN_LOGIN_IDX ON RESET_PASSWORD_TOKEN(LOGIN);
-- EMAILS -- EMAILS
CREATE TABLE EMAIL ( CREATE TABLE EMAIL (
ID INT8 NOT NULL, ID INT8 NOT NULL,
LOCKED BOOLEAN DEFAULT FALSE, LOCKED BOOLEAN DEFAULT FALSE,
TO_BE_SENT BOOLEAN DEFAULT FALSE, TO_BE_SENT BOOLEAN DEFAULT FALSE,
STATUS VARCHAR(10), STATUS VARCHAR(10),
SENT_DATE TIMESTAMP, SENT_DATE TIMESTAMP,
TO_BE_SENT_DATE TIMESTAMP, TO_BE_SENT_DATE TIMESTAMP,
EMAIL_FROM VARCHAR(250) NOT NULL, EMAIL_FROM VARCHAR(250) NOT NULL,
SUBJECT VARCHAR(1000), SUBJECT VARCHAR(1000),
TEXT_CONTENT TEXT, TEXT_CONTENT TEXT,
HTML_CONTENT TEXT, HTML_CONTENT TEXT,
ATTEMPTS NUMERIC(2, 0), ATTEMPTS NUMERIC(2, 0),
ERROR VARCHAR(2000), ERROR VARCHAR(2000),
RECEIPT BOOLEAN, RECEIPT BOOLEAN,
CONSTRAINT PK_EMAIL PRIMARY KEY(ID) CONSTRAINT PK_EMAIL PRIMARY KEY(ID)
); );
CREATE INDEX EMAIL_IDX ON EMAIL(TO_BE_SENT, LOCKED); CREATE INDEX EMAIL_IDX ON EMAIL(TO_BE_SENT, LOCKED);
CREATE TABLE EMAIL_RECIPIENT ( CREATE TABLE EMAIL_RECIPIENT (
ID INT8 NOT NULL, ID INT8 NOT NULL,
EMAIL_ID INT8 NOT NULL, EMAIL_ID INT8 NOT NULL,
ADDRESS VARCHAR(100), ADDRESS VARCHAR(100),
RECIPIENT_TYPE VARCHAR(10), RECIPIENT_TYPE VARCHAR(10),
CONSTRAINT PK_EMAIL_RECIPIENT PRIMARY KEY(ID), CONSTRAINT PK_EMAIL_RECIPIENT PRIMARY KEY(ID),
CONSTRAINT FK_RECIPIENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID) CONSTRAINT FK_RECIPIENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID)
); );
CREATE INDEX EMAIL_RECIPIENT_IDX ON EMAIL_RECIPIENT(EMAIL_ID); CREATE INDEX EMAIL_RECIPIENT_IDX ON EMAIL_RECIPIENT(EMAIL_ID);
CREATE TABLE EMAIL_ATTACHMENT ( CREATE TABLE EMAIL_ATTACHMENT (
ID INT8 NOT NULL, ID INT8 NOT NULL,
EMAIL_ID INT8 NOT NULL, EMAIL_ID INT8 NOT NULL,
CID VARCHAR(100), CID VARCHAR(100),
NAME VARCHAR(256), NAME VARCHAR(256),
MIME_TYPE VARCHAR(100), MIME_TYPE VARCHAR(100),
SIZE NUMERIC(19,0), SIZE NUMERIC(19,0),
DATA TEXT, DATA TEXT,
CONSTRAINT PK_EMAIL_ATTACHMENT PRIMARY KEY(ID), CONSTRAINT PK_EMAIL_ATTACHMENT PRIMARY KEY(ID),
CONSTRAINT FK_EMAIL_ATTACHMENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID) CONSTRAINT FK_EMAIL_ATTACHMENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID)
); );
CREATE INDEX EMAIL_ATTACHMENT_IDX ON EMAIL_ATTACHMENT(EMAIL_ID); CREATE INDEX EMAIL_ATTACHMENT_IDX ON EMAIL_ATTACHMENT(EMAIL_ID);
-- TEMPLATES -- TEMPLATES
CREATE TABLE TEMPLATE ( CREATE TABLE TEMPLATE (
ID INT8 NOT NULL, ID INT8 NOT NULL,
CODE VARCHAR(250), CODE VARCHAR(250),
NAME VARCHAR(100), NAME VARCHAR(100),
TEMPLATE TEXT, TEMPLATE TEXT,
CONSTRAINT PK_TEMPLATE PRIMARY KEY(ID) CONSTRAINT PK_TEMPLATE PRIMARY KEY(ID)
); );
CREATE INDEX TEMPLATE_CODE_IDX ON TEMPLATE(CODE); CREATE INDEX TEMPLATE_CODE_IDX ON TEMPLATE(CODE);
CREATE TABLE CUSTOMIZABLE_TEMPLATE_LABEL ( CREATE TABLE CUSTOMIZABLE_TEMPLATE_LABEL (
ID INT8 NOT NULL, ID INT8 NOT NULL,
TEMPLATE_ID INT8 NOT NULL, TEMPLATE_ID INT8 NOT NULL,
UNIT_ID INT8, UNIT_ID INT8,
CODE VARCHAR(1000) NOT NULL, CODE VARCHAR(1000) NOT NULL,
LANG VARCHAR(10), LANG VARCHAR(10),
LABEL VARCHAR, LABEL VARCHAR,
POSITION NUMERIC(19,0), POSITION NUMERIC(19,0),
CONSTRAINT PK_CUSTOMIZABLE_TEMPLATE_LABEL PRIMARY KEY(ID), CONSTRAINT PK_CUSTOMIZABLE_TEMPLATE_LABEL PRIMARY KEY(ID),
CONSTRAINT FK_CUSTOMIZABLE_TEMPLATE_LABEL_TEMPLATE FOREIGN KEY (TEMPLATE_ID) REFERENCES TEMPLATE(ID) CONSTRAINT FK_CUSTOMIZABLE_TEMPLATE_LABEL_TEMPLATE FOREIGN KEY (TEMPLATE_ID) REFERENCES TEMPLATE(ID)
); );
CREATE INDEX CUSTOMIZABLE_TEMPLATE_LABEL_TEMPLATE_IDX ON CUSTOMIZABLE_TEMPLATE_LABEL(TEMPLATE_ID); CREATE INDEX CUSTOMIZABLE_TEMPLATE_LABEL_TEMPLATE_IDX ON CUSTOMIZABLE_TEMPLATE_LABEL(TEMPLATE_ID);
CREATE INDEX CUSTOMIZABLE_TEMPLATE_LABEL_UNIT_IDX ON CUSTOMIZABLE_TEMPLATE_LABEL(UNIT_ID); CREATE INDEX CUSTOMIZABLE_TEMPLATE_LABEL_UNIT_IDX ON CUSTOMIZABLE_TEMPLATE_LABEL(UNIT_ID);
-- LEGAL DOCUMENTS
CREATE TABLE LEGAL_DOCUMENT (
ID INT8 NOT NULL,
CODE VARCHAR(1000) NOT NULL,
LOCALE VARCHAR(10),
CONTENT VARCHAR,
CONSTRAINT PK_LEGAL_DOCUMENT PRIMARY KEY(ID)
);
CREATE INDEX LEGAL_DOCUMENT_IDX ON LEGAL_DOCUMENT(CODE, LOCALE);
-- TODO -- TODO
\ No newline at end of file
package com.jh.boot.security.model; package com.jh.boot.document;
import com.jh.boot.jpa.AbstractIdEntity; import com.jh.boot.jpa.AbstractIdEntity;
......
package com.jh.boot.document;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;
import com.jh.boot.jpa.AbstractHibernateRepository;
@Repository
public class LegalDocumentRepository extends AbstractHibernateRepository {
public LegalDocument findByCodeAndLocale(String code, String locale) {
if (code == null) {
return null;
}
if (!StringUtils.hasText(locale)) {
locale = "en";
}
locale = locale.replace("-", "_");
Query q = entityManager.createQuery("select ld from LegalDocument ld where lower(ld.code) = :code and lower(ld.locale) = :locale");
q.setParameter("code", locale.trim().toLowerCase());
q.setParameter("locale", locale.trim().toLowerCase());
LegalDocument ld = singleResult(q);
if (ld == null) {
if (locale.indexOf('_') > -1) {
return findByCodeAndLocale(code, locale.substring(0, locale.lastIndexOf('_')));
} else if (!"en".equalsIgnoreCase(locale)) {
return findByCodeAndLocale(code, "en");
}
}
return null;
}
}
package com.jh.boot.document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class LegalDocumentService {
@Autowired
private LegalDocumentRepository repo;
@Transactional
public LegalDocument findByCodeAndLocale(String code, String locale) {
return repo.findByCodeAndLocale(code, locale);
}
}
...@@ -8,8 +8,7 @@ import java.util.ArrayList; ...@@ -8,8 +8,7 @@ import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Locale;
import java.util.logging.ErrorManager;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
...@@ -31,6 +30,8 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -31,6 +30,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import com.jh.boot.document.LegalDocument;
import com.jh.boot.document.LegalDocumentService;
import com.jh.boot.security.AppUserAuthentication; import com.jh.boot.security.AppUserAuthentication;
import com.jh.boot.security.AuthError; import com.jh.boot.security.AuthError;
import com.jh.boot.security.AuthService; import com.jh.boot.security.AuthService;
...@@ -54,6 +55,10 @@ public class AuthApiController { ...@@ -54,6 +55,10 @@ public class AuthApiController {
@Autowired @Autowired
private AuthService authService; private AuthService authService;
@Autowired
private LegalDocumentService documentService;
@Value("${auth.controller.signup.enabled:true}") @Value("${auth.controller.signup.enabled:true}")
private boolean signupEnabled; private boolean signupEnabled;
...@@ -218,20 +223,17 @@ public class AuthApiController { ...@@ -218,20 +223,17 @@ public class AuthApiController {
} }
/*
@GetMapping("/auth/terms")
public @ResponseBody AppUser user() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth instanceof AppUserAuthentication) {
return ((AppUserAuthentication) auth).getUser();
}
//TODO other auth types? @GetMapping("/auth/terms")
return null; public @ResponseBody LegalDocument terms(Locale locale) {
return documentService.findByCodeAndLocale("AUTH.TERMS", locale.toLanguageTag());
} }
@GetMapping("/auth/privacy") @GetMapping("/auth/privacy")
public @ResponseBody LegalDocument privacy(Locale locale) {
return documentService.findByCodeAndLocale("AUTH.PRIVACY", locale.toLanguageTag());
}
*/
} }
package com.jh.boot.security.repository;
import com.jh.boot.jpa.AbstractHibernateRepository;
public class LegalDocumentRepository extends AbstractHibernateRepository {
}
package com.jh.boot.security.service;
public class LegalDocumentService {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment