Commit ac125b9b by Jan Hrabal

terms

parent 756ea1b4
CREATE DATABASE suite
WITH
OWNER = postgres
ENCODING = 'utf8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;
--
CREATE SEQUENCE ID_GENERATOR;
-- version procedure
CREATE OR REPLACE FUNCTION process_version_check() RETURNS TRIGGER AS $version_check$
BEGIN
IF (OLD.VERSION > NEW.VERSION) THEN
RAISE EXCEPTION 'row_version_conflict' using
ERRCODE = 99001,
MESSAGE = ('Cannot update record % in table %. Actual version: %, provided version %', NEW.ID, TG_TABLE_NAME, OLD.VERSION, NEW.VERSION);
END IF;
NEW.VERSION = OLD.VERSION + 1;
RETURN NEW;
END;
$version_check$ LANGUAGE plpgsql;
-- end of version procedure
-- shortid procedure
CREATE OR REPLACE FUNCTION pseudo_encrypt(VALUE bigint) returns bigint AS $$
DECLARE
l1 int;
l2 int;
r1 int;
r2 int;
i int:=0;
BEGIN
l1:= (VALUE >> 16) & 65535;
r1:= VALUE & 65535;
WHILE i < 3 LOOP
l2 := r1;
r2 := l1 # ((((1366 * r1 + 150889) % 714025) / 714025.0) * 32767)::int;
l1 := l2;
r1 := r2;
i := i + 1;
END LOOP;
RETURN ((r1 << 16) + l1);
END;
$$ LANGUAGE plpgsql strict immutable;
CREATE OR REPLACE FUNCTION shortid(n bigint) RETURNS text
LANGUAGE plpgsql IMMUTABLE STRICT AS $$
DECLARE
alphabet text:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
base int:=length(alphabet);
_n bigint:=pseudo_encrypt(abs(n));
output text:='';
BEGIN
LOOP
output := output || substr(alphabet, 1+(_n%base)::int, 1);
_n := _n / base;
EXIT WHEN _n=0;
END LOOP;
RETURN output;
END $$;
-- end of shortid procedure
CREATE TABLE APP_USER (
ID INT8 NOT NULL,
VERSION INT8 NOT NULL DEFAULT 0,
DELETED BOOLEAN DEFAULT FALSE,
EMAIL VARCHAR(250) NOT NULL,
PASSWORD VARCHAR(500),
PASSWORD_SALT VARCHAR(250),
FIRST_NAME VARCHAR(250),
LAST_NAME VARCHAR(250),
TIMEZONE_ID VARCHAR(50),
LOCALE VARCHAR(50),
CONSTRAINT PK_APP_USER PRIMARY KEY(ID)
);
CREATE INDEX APP_USER_EMAIL_IDX ON APP_USER(lower(EMAIL));
CREATE TABLE APP_ROLE (
ID INT8 NOT NULL,
NAME VARCHAR(250) NOT NULL,
CONSTRAINT PK_APP_ROLE PRIMARY KEY(ID)
);
CREATE TABLE APP_USER_ROLE (
USER_ID INT8 NOT NULL,
ROLE_ID INT8 NOT NULL
);
CREATE INDEX APP_USER_ROLE_IDX ON APP_USER_ROLE(USER_ID, ROLE_ID);
CREATE TABLE RESET_PASSWORD_TOKEN (
ID INT8 NOT NULL,
LOGIN VARCHAR(250) NOT NULL,
TOKEN VARCHAR(250) NOT NULL,
USED BOOLEAN DEFAULT FALSE,
CREATED TIMESTAMP,
CONSTRAINT PK_RESET_PASSWORD_TOKEN PRIMARY KEY(ID)
);
CREATE INDEX RESET_PASSWORD_TOKEN_LOGIN_IDX ON RESET_PASSWORD_TOKEN(LOGIN);
-- EMAILS
CREATE TABLE EMAIL (
ID INT8 NOT NULL,
LOCKED BOOLEAN DEFAULT FALSE,
TO_BE_SENT BOOLEAN DEFAULT FALSE,
STATUS VARCHAR(10),
SENT_DATE TIMESTAMP,
TO_BE_SENT_DATE TIMESTAMP,
EMAIL_FROM VARCHAR(250) NOT NULL,
SUBJECT VARCHAR(1000),
TEXT_CONTENT TEXT,
HTML_CONTENT TEXT,
ATTEMPTS NUMERIC(2, 0),
ERROR VARCHAR(2000),
RECEIPT BOOLEAN,
CONSTRAINT PK_EMAIL PRIMARY KEY(ID)
);
CREATE INDEX EMAIL_IDX ON EMAIL(TO_BE_SENT, LOCKED);
CREATE TABLE EMAIL_RECIPIENT (
ID INT8 NOT NULL,
EMAIL_ID INT8 NOT NULL,
ADDRESS VARCHAR(100),
RECIPIENT_TYPE VARCHAR(10),
CONSTRAINT PK_EMAIL_RECIPIENT PRIMARY KEY(ID),
CONSTRAINT FK_RECIPIENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID)
);
CREATE INDEX EMAIL_RECIPIENT_IDX ON EMAIL_RECIPIENT(EMAIL_ID);
CREATE TABLE EMAIL_ATTACHMENT (
ID INT8 NOT NULL,
EMAIL_ID INT8 NOT NULL,
CID VARCHAR(100),
NAME VARCHAR(256),
MIME_TYPE VARCHAR(100),
SIZE NUMERIC(19,0),
DATA TEXT,
CONSTRAINT PK_EMAIL_ATTACHMENT PRIMARY KEY(ID),
CONSTRAINT FK_EMAIL_ATTACHMENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID)
);
CREATE INDEX EMAIL_ATTACHMENT_IDX ON EMAIL_ATTACHMENT(EMAIL_ID);
-- TEMPLATES
CREATE TABLE TEMPLATE (
ID INT8 NOT NULL,
CODE VARCHAR(250),
NAME VARCHAR(100),
TEMPLATE TEXT,
CONSTRAINT PK_TEMPLATE PRIMARY KEY(ID)
);
CREATE INDEX TEMPLATE_CODE_IDX ON TEMPLATE(CODE);
CREATE TABLE CUSTOMIZABLE_TEMPLATE_LABEL (
ID INT8 NOT NULL,
TEMPLATE_ID INT8 NOT NULL,
UNIT_ID INT8,
CODE VARCHAR(1000) NOT NULL,
LANG VARCHAR(10),
LABEL VARCHAR,
POSITION NUMERIC(19,0),
CONSTRAINT PK_CUSTOMIZABLE_TEMPLATE_LABEL PRIMARY KEY(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_UNIT_IDX ON CUSTOMIZABLE_TEMPLATE_LABEL(UNIT_ID);
CREATE DATABASE suite
WITH
OWNER = postgres
ENCODING = 'utf8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;
--
CREATE SEQUENCE ID_GENERATOR;
-- version procedure
CREATE OR REPLACE FUNCTION process_version_check() RETURNS TRIGGER AS $version_check$
BEGIN
IF (OLD.VERSION > NEW.VERSION) THEN
RAISE EXCEPTION 'row_version_conflict' using
ERRCODE = 99001,
MESSAGE = ('Cannot update record % in table %. Actual version: %, provided version %', NEW.ID, TG_TABLE_NAME, OLD.VERSION, NEW.VERSION);
END IF;
NEW.VERSION = OLD.VERSION + 1;
RETURN NEW;
END;
$version_check$ LANGUAGE plpgsql;
-- end of version procedure
-- shortid procedure
CREATE OR REPLACE FUNCTION pseudo_encrypt(VALUE bigint) returns bigint AS $$
DECLARE
l1 int;
l2 int;
r1 int;
r2 int;
i int:=0;
BEGIN
l1:= (VALUE >> 16) & 65535;
r1:= VALUE & 65535;
WHILE i < 3 LOOP
l2 := r1;
r2 := l1 # ((((1366 * r1 + 150889) % 714025) / 714025.0) * 32767)::int;
l1 := l2;
r1 := r2;
i := i + 1;
END LOOP;
RETURN ((r1 << 16) + l1);
END;
$$ LANGUAGE plpgsql strict immutable;
CREATE OR REPLACE FUNCTION shortid(n bigint) RETURNS text
LANGUAGE plpgsql IMMUTABLE STRICT AS $$
DECLARE
alphabet text:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
base int:=length(alphabet);
_n bigint:=pseudo_encrypt(abs(n));
output text:='';
BEGIN
LOOP
output := output || substr(alphabet, 1+(_n%base)::int, 1);
_n := _n / base;
EXIT WHEN _n=0;
END LOOP;
RETURN output;
END $$;
-- end of shortid procedure
CREATE TABLE APP_USER (
ID INT8 NOT NULL,
VERSION INT8 NOT NULL DEFAULT 0,
DELETED BOOLEAN DEFAULT FALSE,
EMAIL VARCHAR(250) NOT NULL,
PASSWORD VARCHAR(500),
PASSWORD_SALT VARCHAR(250),
FIRST_NAME VARCHAR(250),
LAST_NAME VARCHAR(250),
TIMEZONE_ID VARCHAR(50),
LOCALE VARCHAR(50),
CONSTRAINT PK_APP_USER PRIMARY KEY(ID)
);
CREATE INDEX APP_USER_EMAIL_IDX ON APP_USER(lower(EMAIL));
CREATE TABLE APP_ROLE (
ID INT8 NOT NULL,
NAME VARCHAR(250) NOT NULL,
CONSTRAINT PK_APP_ROLE PRIMARY KEY(ID)
);
CREATE TABLE APP_USER_ROLE (
USER_ID INT8 NOT NULL,
ROLE_ID INT8 NOT NULL
);
CREATE INDEX APP_USER_ROLE_IDX ON APP_USER_ROLE(USER_ID, ROLE_ID);
CREATE TABLE RESET_PASSWORD_TOKEN (
ID INT8 NOT NULL,
LOGIN VARCHAR(250) NOT NULL,
TOKEN VARCHAR(250) NOT NULL,
USED BOOLEAN DEFAULT FALSE,
CREATED TIMESTAMP,
CONSTRAINT PK_RESET_PASSWORD_TOKEN PRIMARY KEY(ID)
);
CREATE INDEX RESET_PASSWORD_TOKEN_LOGIN_IDX ON RESET_PASSWORD_TOKEN(LOGIN);
-- EMAILS
CREATE TABLE EMAIL (
ID INT8 NOT NULL,
LOCKED BOOLEAN DEFAULT FALSE,
TO_BE_SENT BOOLEAN DEFAULT FALSE,
STATUS VARCHAR(10),
SENT_DATE TIMESTAMP,
TO_BE_SENT_DATE TIMESTAMP,
EMAIL_FROM VARCHAR(250) NOT NULL,
SUBJECT VARCHAR(1000),
TEXT_CONTENT TEXT,
HTML_CONTENT TEXT,
ATTEMPTS NUMERIC(2, 0),
ERROR VARCHAR(2000),
RECEIPT BOOLEAN,
CONSTRAINT PK_EMAIL PRIMARY KEY(ID)
);
CREATE INDEX EMAIL_IDX ON EMAIL(TO_BE_SENT, LOCKED);
CREATE TABLE EMAIL_RECIPIENT (
ID INT8 NOT NULL,
EMAIL_ID INT8 NOT NULL,
ADDRESS VARCHAR(100),
RECIPIENT_TYPE VARCHAR(10),
CONSTRAINT PK_EMAIL_RECIPIENT PRIMARY KEY(ID),
CONSTRAINT FK_RECIPIENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID)
);
CREATE INDEX EMAIL_RECIPIENT_IDX ON EMAIL_RECIPIENT(EMAIL_ID);
CREATE TABLE EMAIL_ATTACHMENT (
ID INT8 NOT NULL,
EMAIL_ID INT8 NOT NULL,
CID VARCHAR(100),
NAME VARCHAR(256),
MIME_TYPE VARCHAR(100),
SIZE NUMERIC(19,0),
DATA TEXT,
CONSTRAINT PK_EMAIL_ATTACHMENT PRIMARY KEY(ID),
CONSTRAINT FK_EMAIL_ATTACHMENT_EMAIL FOREIGN KEY (EMAIL_ID) REFERENCES EMAIL(ID)
);
CREATE INDEX EMAIL_ATTACHMENT_IDX ON EMAIL_ATTACHMENT(EMAIL_ID);
-- TEMPLATES
CREATE TABLE TEMPLATE (
ID INT8 NOT NULL,
CODE VARCHAR(250),
NAME VARCHAR(100),
TEMPLATE TEXT,
CONSTRAINT PK_TEMPLATE PRIMARY KEY(ID)
);
CREATE INDEX TEMPLATE_CODE_IDX ON TEMPLATE(CODE);
CREATE TABLE CUSTOMIZABLE_TEMPLATE_LABEL (
ID INT8 NOT NULL,
TEMPLATE_ID INT8 NOT NULL,
UNIT_ID INT8,
CODE VARCHAR(1000) NOT NULL,
LANG VARCHAR(10),
LABEL VARCHAR,
POSITION NUMERIC(19,0),
CONSTRAINT PK_CUSTOMIZABLE_TEMPLATE_LABEL PRIMARY KEY(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_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
\ No newline at end of file
package com.jh.boot.security.model;
package com.jh.boot.document;
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;
import java.util.Base64;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.logging.ErrorManager;
import java.util.Locale;
import javax.servlet.http.HttpSession;
......@@ -31,6 +30,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
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.AuthError;
import com.jh.boot.security.AuthService;
......@@ -54,6 +55,10 @@ public class AuthApiController {
@Autowired
private AuthService authService;
@Autowired
private LegalDocumentService documentService;
@Value("${auth.controller.signup.enabled:true}")
private boolean signupEnabled;
......@@ -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?
return null;
@GetMapping("/auth/terms")
public @ResponseBody LegalDocument terms(Locale locale) {
return documentService.findByCodeAndLocale("AUTH.TERMS", locale.toLanguageTag());
}
@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