- Timestamp:
- 09/04/21 11:14:25 (3 years ago)
- Branches:
- master
- Children:
- ab49338
- Parents:
- 194776a
- Location:
- src/main
- Files:
-
- 3 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/CharitableApplication.java
r194776a r5306751 4 4 import org.springframework.boot.SpringApplication; 5 5 import org.springframework.boot.autoconfigure.SpringBootApplication; 6 import org.springframework.scheduling.annotation.EnableScheduling; 6 7 7 8 @SpringBootApplication 9 @EnableScheduling 8 10 public class CharitableApplication { 9 11 -
src/main/java/it/finki/charitable/controller/DonationPostController.java
r194776a r5306751 73 73 post.setDateDue(dateDue); 74 74 post.setBankAccount(bankAccount); 75 post.setApproved(false); 75 76 76 77 List<String> phoneNumbers = Arrays.asList(telekom, a1); … … 123 124 @RequestMapping("/album") 124 125 public String album(Model model) { 125 List<DonationPost> postList = donationPostService.findAll ();126 List<DonationPost> postList = donationPostService.findAllByApproved(true); 126 127 if (postList.size() == 0) { 127 128 model.addAttribute("noPosts", true); … … 148 149 } 149 150 150 @RequestMapping("/deletePost")151 public String deletePost(@RequestParam Long postid) {152 DonationPost post = donationPostService.getById(postid);153 if (post.getUser().getUsername().equals(SecurityContextHolder.getContext().getAuthentication().getName())) {154 List<String> fileForDeletion = post.getPhotosForDeletion();155 for (String f : fileForDeletion) {156 File file = new File(f);157 file.delete();158 }159 donationPostService.delete(post);160 }161 162 return "redirect:/myPosts";163 }151 // @RequestMapping("/deletePost") 152 // public String deletePost(@RequestParam Long postid) { 153 // DonationPost post = donationPostService.getById(postid); 154 // if (post.getUser().getUsername().equals(SecurityContextHolder.getContext().getAuthentication().getName())) { 155 // List<String> fileForDeletion = post.getPhotosForDeletion(); 156 // for (String f : fileForDeletion) { 157 // File file = new File(f); 158 // file.delete(); 159 // } 160 // donationPostService.delete(post); 161 // } 162 // 163 // return "redirect:/myPosts"; 164 // } 164 165 165 166 @RequestMapping("/donate") -
src/main/java/it/finki/charitable/entities/DonationPost.java
r194776a r5306751 37 37 private LocalDate dateDue; 38 38 private String bankAccount; 39 private Boolean approved; 39 40 40 41 @ElementCollection … … 74 75 75 76 List<String> photoPaths = new ArrayList<>(); 77 76 78 for(String path: images) { 79 photoPaths.add("../../../../post-photos/" + id + "/" + path); 80 } 81 82 for(String path: moderatorImages) { 77 83 photoPaths.add("../../../../moderator-photos/" + id + "/" + path); 78 84 } … … 158 164 } 159 165 166 public Boolean getApproved() { 167 return approved; 168 } 169 170 public void setApproved(Boolean approved) { 171 this.approved = approved; 172 } 173 160 174 public List<String> getPhoneNumbers() { 161 175 return phoneNumbers; -
src/main/java/it/finki/charitable/repository/DonationPostRepository.java
r194776a r5306751 11 11 public interface DonationPostRepository extends JpaRepository<DonationPost, Long> { 12 12 List<DonationPost> findAllByUser(AppUser user); 13 List<DonationPost> findAllByApproved(Boolean approved); 13 14 } -
src/main/java/it/finki/charitable/security/SecurityConfig.java
r194776a r5306751 7 7 import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 8 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 import org.springframework.security.core.Authentication; 9 10 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 11 import org.springframework.security.web.DefaultRedirectStrategy; 12 import org.springframework.security.web.RedirectStrategy; 13 import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 10 14 import org.springframework.security.web.util.matcher.AntPathRequestMatcher; 15 16 import javax.servlet.ServletException; 17 import javax.servlet.http.HttpServletRequest; 18 import javax.servlet.http.HttpServletResponse; 19 import java.io.IOException; 11 20 12 21 @Configuration … … 40 49 .authorizeRequests() 41 50 .antMatchers(publicMatchers).permitAll() 42 .antMatchers("/moderator-photos/**" ).hasAuthority(UserRole.MODERATOR.name())43 .anyRequest(). authenticated();51 .antMatchers("/moderator-photos/**", "/moderator/**").hasAuthority(UserRole.MODERATOR.name()) 52 .anyRequest().hasAuthority(UserRole.USER.name()); 44 53 45 54 http … … 47 56 .cors().disable() 48 57 .formLogin().loginPage("/login") 49 . defaultSuccessUrl("/", true)58 .successHandler(authenticationSuccessHandler) 50 59 .and() 51 60 .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")) … … 55 64 } 56 65 66 AuthenticationSuccessHandler authenticationSuccessHandler = (httpServletRequest, httpServletResponse, authentication) -> { 67 RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); 68 if(authentication.getAuthorities().toString().contains("MODERATOR")) { 69 redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/moderator/approval"); 70 } else { 71 redirectStrategy.sendRedirect(httpServletRequest, httpServletResponse, "/"); 72 } 73 }; 74 57 75 @Override 58 76 protected void configure(AuthenticationManagerBuilder auth) throws Exception { -
src/main/java/it/finki/charitable/services/DonationPostService.java
r194776a r5306751 41 41 } 42 42 43 public List<DonationPost> findAllByApproved(Boolean approved) { 44 return donationPostRepository.findAllByApproved(approved); 45 } 46 43 47 public void delete(DonationPost donationPost) { 44 48 donationPostRepository.delete(donationPost); -
src/main/java/it/finki/charitable/services/EmailService.java
r194776a r5306751 24 24 javaMailSender.send(message); 25 25 } 26 27 public void sendApprovalEmail(String to, String subject, Long postId) { 28 SimpleMailMessage message = new SimpleMailMessage(); 29 message.setTo(to); 30 message.setSubject(subject); 31 32 String text = "Your post has been approved\n" + "http://localhost:8080/post?postid=" + postId; 33 message.setText(text); 34 javaMailSender.send(message); 35 } 36 37 public void sendNoApprovalEmail(String to, String subject, String description) { 38 SimpleMailMessage message = new SimpleMailMessage(); 39 message.setTo(to); 40 message.setSubject(subject); 41 42 String text = "Sorry, your post hasn't been approved" + "\n" + 43 "Moderator:\n" + description; 44 message.setText(text); 45 javaMailSender.send(message); 46 } 26 47 } -
src/main/resources/templates/common/navbar.html
r194776a r5306751 9 9 <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> 10 10 <div class="container-fluid"> 11 <a class="navbar-brand" href="#">12 <img th:src="@{ image/charity.png}" class="bi me-2" width="40" height="32" />11 <a class="navbar-brand" th:href="@{/}"> 12 <img th:src="@{/image/charity.png}" class="bi me-2" width="40" height="32" /> 13 13 <span class="fs-4">Charitable</span> 14 14 </a> … … 20 20 <ul class="navbar-nav me-auto mb-2 mb-md-0"> 21 21 <li class="nav-item"> 22 <a th:href="@{/}" class="nav-link px-2 text-white">Home</a>22 <a sec:authorize="isAnonymous() or hasAuthority('USER')" th:href="@{/}" class="nav-link px-2 text-white">Home</a> 23 23 </li> 24 24 <li class="nav-item"> 25 <a th:href="@{/album?page=1}" class="nav-link px-2 text-white">Posts</a> 25 <a sec:authorize="isAnonymous() or hasAuthority('USER')" th:href="@{/album?page=1}" class="nav-link px-2 text-white">Posts</a> 26 <a sec:authorize="hasAuthority('MODERATOR')" th:href="@{/moderator/approval}" class="nav-link px-2 text-white">Posts for approval</a> 26 27 </li> 27 28 <li class="nav-item"> 28 <a th:href="@{/upload}" class="nav-link px-2 text-white">Upload</a> 29 <a sec:authorize="hasAuthority('USER')" th:href="@{/upload}" class="nav-link px-2 text-white">Upload</a> 30 <a sec:authorize="hasAuthority('MODERATOR')" th:href="@{/moderator/report}" class="nav-link px-2 text-white">Reported posts</a> 29 31 </li> 30 32 </ul>
Note:
See TracChangeset
for help on using the changeset viewer.