Commit ac125b9b by Jan Hrabal

terms

parent 756ea1b4
......@@ -206,4 +206,18 @@ CREATE TABLE CUSTOMIZABLE_TEMPLATE_LABEL (
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();
public @ResponseBody LegalDocument terms(Locale locale) {
return documentService.findByCodeAndLocale("AUTH.TERMS", locale.toLanguageTag());
}
//TODO other auth types?
return null;
}
@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