From fb878b8c5071dce98d9e297b74d7a3f6be9c690b Mon Sep 17 00:00:00 2001 From: doychin Date: Sun, 1 Mar 2020 12:50:04 +0200 Subject: [PATCH 01/12] Use latest quarkus --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f6ae7b1..e8fd12e 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ v8.9.1 UTF-8 UTF-8 - 1.0.0.Final + 1.2.1.Final 3.4.1.Final 2.22.0 v1.3.2 From 79988b0e7eb145c926f36801dd17c5d5a902ffe5 Mon Sep 17 00:00:00 2001 From: doychin Date: Sun, 1 Mar 2020 12:50:42 +0200 Subject: [PATCH 02/12] Use byte[] instead of String for User.password field --- .../bg/jug/website/core/util/CryptUtils.java | 9 +++++---- .../java/bg/jug/website/user/model/User.java | 16 +++++++--------- .../bg/jug/website/user/service/UserService.java | 11 ++++++++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/bg/jug/website/core/util/CryptUtils.java b/src/main/java/bg/jug/website/core/util/CryptUtils.java index 7629ede..17e0abd 100644 --- a/src/main/java/bg/jug/website/core/util/CryptUtils.java +++ b/src/main/java/bg/jug/website/core/util/CryptUtils.java @@ -2,21 +2,22 @@ import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.Key; public class CryptUtils { private static final String KEY = "lkjq9q91jaq*9!l#"; - public static String encryptPassword(String password) { + public static byte[] encryptPassword(String password) { Key aesKey = new SecretKeySpec(KEY.getBytes(), "AES"); try { Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, aesKey); - byte[] encrypted = cipher.doFinal(password.getBytes()); - return new String(encrypted); + return cipher.doFinal(password.getBytes()); } catch (Exception e) { - return password; + return password.getBytes(StandardCharsets.UTF_8); } } diff --git a/src/main/java/bg/jug/website/user/model/User.java b/src/main/java/bg/jug/website/user/model/User.java index 4b63888..8ed6035 100644 --- a/src/main/java/bg/jug/website/user/model/User.java +++ b/src/main/java/bg/jug/website/user/model/User.java @@ -6,9 +6,7 @@ import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.Lob; -import java.util.Collections; -import java.util.List; - +import java.util.*; @Entity public class User extends AbstractEntity { @@ -30,7 +28,7 @@ public class User extends AbstractEntity { private String bio; @JsonbTransient - private String password; + private byte[] password; @JsonbTransient private String salt; @@ -42,13 +40,13 @@ public class User extends AbstractEntity { public User() { } - public User(String email, String password, String salt) { + public User(String email, byte[] password, String salt) { this(null, null, email, null, null, password, salt, - Collections.singletonList(DEFAULT_ROLE)); + new ArrayList<>(Collections.singletonList(DEFAULT_ROLE))); } public User(String nickname, String fullname, String email, byte[] photo, - String bio, String password, String salt, List roles) { + String bio, byte[] password, String salt, List roles) { this.nickname = nickname; this.fullname = fullname; this.email = email; @@ -89,10 +87,10 @@ public String getBio() { public void setBio(String bio) { this.bio = bio; } - public String getPassword() { + public byte[] getPassword() { return password; } - public void setPassword(String password) { + public void setPassword(byte[] password) { this.password = password; } public String getSalt() { diff --git a/src/main/java/bg/jug/website/user/service/UserService.java b/src/main/java/bg/jug/website/user/service/UserService.java index 9058bcd..9115e94 100644 --- a/src/main/java/bg/jug/website/user/service/UserService.java +++ b/src/main/java/bg/jug/website/user/service/UserService.java @@ -18,6 +18,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.Arrays; @RequestScoped @Path("/user") @@ -33,9 +34,13 @@ public class UserService { @Transactional public Response registerUser(@Valid LoginDetails registrationDetails) { // TODO Check if email is already registered + String salt = RandomStringUtils.randomAlphanumeric(20); - String encrypted = CryptUtils.encryptPassword(registrationDetails.getPassword() + salt); + byte[] encrypted = CryptUtils.encryptPassword(registrationDetails.getPassword() + salt); User newUser = new User(registrationDetails.getEmail(), encrypted, salt); + if (User.findAll().count() == 0) { + newUser.getRoles().add("admin"); + } newUser.persist(); return Response.ok().header("Authorization", getJwt(newUser)).build(); @@ -51,8 +56,8 @@ public Response loginUser(LoginDetails loginDetails) { return Response.status(Response.Status.UNAUTHORIZED).build(); } - String encrypted = CryptUtils.encryptPassword(loginDetails.getPassword() + user.getSalt()); - if (!user.getPassword().equals(encrypted)) { + byte[] encrypted = CryptUtils.encryptPassword(loginDetails.getPassword() + user.getSalt()); + if (!Arrays.equals(user.getPassword(), encrypted)) { return Response.status(Response.Status.UNAUTHORIZED).build(); } From e1e02f3f8050c63cf9bc694b705ff982f45678f2 Mon Sep 17 00:00:00 2001 From: doychin Date: Sun, 1 Mar 2020 13:02:31 +0200 Subject: [PATCH 03/12] refactor code --- .../jug/website/cms/service/EventService.java | 12 +++---- .../website/cms/service/TagAwareService.java | 34 +++++++++++-------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/main/java/bg/jug/website/cms/service/EventService.java b/src/main/java/bg/jug/website/cms/service/EventService.java index 17d9786..543333c 100644 --- a/src/main/java/bg/jug/website/cms/service/EventService.java +++ b/src/main/java/bg/jug/website/cms/service/EventService.java @@ -53,13 +53,13 @@ public Response updateEvent(@Valid Event event) { if (persisted == null) { return Response.status(Response.Status.NOT_FOUND).build(); - } else { - EntityUtils.updateEntity(persisted, event); - replaceTagsWithExistingOnes(event); - //Eager fetching. Otherwise page will not serialize - persisted.getTags().size(); - return Response.ok(persisted).build(); } + + EntityUtils.updateEntity(persisted, event); + replaceTagsWithExistingOnes(event); + //Eager fetching. Otherwise page will not serialize + persisted.getTags().size(); + return Response.ok(persisted).build(); } @DELETE diff --git a/src/main/java/bg/jug/website/cms/service/TagAwareService.java b/src/main/java/bg/jug/website/cms/service/TagAwareService.java index 430b95e..3401a82 100644 --- a/src/main/java/bg/jug/website/cms/service/TagAwareService.java +++ b/src/main/java/bg/jug/website/cms/service/TagAwareService.java @@ -13,22 +13,26 @@ * Base class for services dealing with tag relations */ public class TagAwareService { + protected void replaceTagsWithExistingOnes(Article article) { - if (article.getTags() != null && !article.getTags().isEmpty()) { - Set tagsToPersist = new HashSet<>(); - article.getTags() - .forEach(possiblyNewTag -> - { - List existingTags = Tag.find(Tag.FIND_BY_NAME, possiblyNewTag.getName()).page( - Page.of(0, 1)).list(); - if(existingTags != null && !existingTags.isEmpty()) { - Tag existingTag = existingTags.get(0); - tagsToPersist.add(existingTag); - } else { - tagsToPersist.add(possiblyNewTag); - } - }); - article.setTags(tagsToPersist); + if (article.getTags() == null || article.getTags().isEmpty()) { + return; + } + + Set tagsToPersist = new HashSet<>(); + article.getTags().forEach(possiblyNewTag -> replaceTag(tagsToPersist, possiblyNewTag)); + article.setTags(tagsToPersist); + } + + private void replaceTag(Set tagsToPersist, Tag possiblyNewTag) { + List existingTags = + Tag.find(Tag.FIND_BY_NAME, possiblyNewTag.getName()).page(Page.of(0, 1)).list(); + + if (existingTags != null && !existingTags.isEmpty()) { + Tag existingTag = existingTags.get(0); + tagsToPersist.add(existingTag); + } else { + tagsToPersist.add(possiblyNewTag); } } } From 2895fbe5acb13a5fde9c65769e13ce30ef2bd592 Mon Sep 17 00:00:00 2001 From: doychin Date: Sun, 1 Mar 2020 13:02:55 +0200 Subject: [PATCH 04/12] add /config to ignored folders. You can keep custom config file there --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e3307f4..a468cff 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .classpath .settings/ bin/ +config/ # IntelliJ .idea From aa3b527339cf11b43c859db0993bf897b0ce1962 Mon Sep 17 00:00:00 2001 From: doychin Date: Thu, 5 Mar 2020 17:28:39 +0200 Subject: [PATCH 05/12] Show events properties if events is specified as tag --- src/main/frontend/src/app/components/article-edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/src/app/components/article-edit.js b/src/main/frontend/src/app/components/article-edit.js index 4197edb..cbe1f48 100644 --- a/src/main/frontend/src/app/components/article-edit.js +++ b/src/main/frontend/src/app/components/article-edit.js @@ -200,7 +200,7 @@ export default class ArticleEdit extends Component { } //if it is an event let eventInputs = ""; - if(this.state.location) { + if(this.state.tag === "events") { eventInputs = (
From a28eadd2352c7f0f0fce17a178b5c73816bbce4f Mon Sep 17 00:00:00 2001 From: doychin Date: Thu, 5 Mar 2020 17:29:20 +0200 Subject: [PATCH 06/12] Fix mobile menu to show our tags --- .../frontend/src/app/components/mobiletags.js | 17 + src/main/frontend/src/app/components/tags.js | 2 +- src/main/frontend/src/index.js | 4 + .../resources/META-INF/resources/index.html | 477 ++++++++++-------- 4 files changed, 277 insertions(+), 223 deletions(-) create mode 100644 src/main/frontend/src/app/components/mobiletags.js diff --git a/src/main/frontend/src/app/components/mobiletags.js b/src/main/frontend/src/app/components/mobiletags.js new file mode 100644 index 0000000..8d27c59 --- /dev/null +++ b/src/main/frontend/src/app/components/mobiletags.js @@ -0,0 +1,17 @@ +import React, {Component} from "react"; +import ApiCall from "../services/api-call"; +import Tags from "./tags"; + +export default class MobileTags extends Tags { + render() { + return ( + this.state.tags.map((tag, i) => { + let link = "/" + tag.name; + return
  • this.handleLinkClick(e, link)}>{tag.name} +
  • + }) + ); + } +} + diff --git a/src/main/frontend/src/app/components/tags.js b/src/main/frontend/src/app/components/tags.js index 078d05d..fa4a85c 100644 --- a/src/main/frontend/src/app/components/tags.js +++ b/src/main/frontend/src/app/components/tags.js @@ -13,7 +13,7 @@ export default class Tags extends Component { // })}; } - componentWillMount() { + componentDidMount() { let self = this; let articles = ApiCall.get("/api/tag") .then((response) => this.setState({tags: response.data})) diff --git a/src/main/frontend/src/index.js b/src/main/frontend/src/index.js index 69b3cd6..457eb21 100644 --- a/src/main/frontend/src/index.js +++ b/src/main/frontend/src/index.js @@ -2,6 +2,7 @@ import React from "react"; import ReactDOM from "react-dom"; import Articles from "./app/components/articles"; import Tags from "./app/components/tags"; +import MobileTags from "./app/components/mobiletags"; import {hashHistory, Route, Router} from 'react-router' import TagsFooter from "./app/components/tags-footer"; import CfpSubmit from "./app/components/cfp"; @@ -15,6 +16,9 @@ ReactDOM.render( , document.querySelector('#tags')); +ReactDOM.render( + + , document.querySelector('.slicknav_nav')); const Routing = () => ( diff --git a/src/main/resources/META-INF/resources/index.html b/src/main/resources/META-INF/resources/index.html index 54f0954..7d7fe3f 100755 --- a/src/main/resources/META-INF/resources/index.html +++ b/src/main/resources/META-INF/resources/index.html @@ -38,11 +38,12 @@ - - - - - - - - - - - - + + + + + + + + + + + + + @@ -281,7 +283,7 @@

    Margaret Gould

    -
    @@ -495,199 +497,230 @@

    Main Sponsors

    -
    -
    -

    Platinum Sponsors

    -
    -
    -
    -
    -