Skip to content

Commit

Permalink
Merge pull request #44 from RamonMR95/feature/37
Browse files Browse the repository at this point in the history
37- EmailController.
  • Loading branch information
TikyParkinson committed Jun 9, 2020
2 parents 3fa7db8 + da0609a commit 4295801
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.ramonmr95.tiky.olc.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ramonmr95.tiky.olc.entities.ContactMessage;
import com.ramonmr95.tiky.olc.services.EmailService;

@RestController
@RequestMapping("/api/email")
public class EmailController {

@Autowired
private EmailService emailService;

@Autowired
private Environment env;

@PostMapping("/contact-us")
public ResponseEntity<?> contactUs(@RequestBody ContactMessage contactMessage) {
this.emailService.sendEmail(env.getProperty("spring.mail.username"), contactMessage.getSubject(), "Name: "
+ contactMessage.getName() + ", email: " + contactMessage.getEmail() + "\n" + contactMessage.getBody());
return new ResponseEntity<>(HttpStatus.OK);
}

}
46 changes: 46 additions & 0 deletions src/main/java/com/ramonmr95/tiky/olc/entities/ContactMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.ramonmr95.tiky.olc.entities;

import java.io.Serializable;

public class ContactMessage implements Serializable {

private static final long serialVersionUID = -1595672012284907193L;

private String subject;
private String body;
private String name;
private String email;

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ protected void configure(HttpSecurity http) throws Exception {
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
.antMatchers("/api/users/create").permitAll()
.antMatchers("/api/login").permitAll()
.antMatchers("/api/news/latest").permitAll().anyRequest().authenticated();
.antMatchers("/api/news/latest").permitAll()
.antMatchers("/api/email/contact-us").permitAll()
.anyRequest().authenticated();

http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
}
Expand Down

0 comments on commit 4295801

Please sign in to comment.