Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
changed some api headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Bernhardt committed Apr 3, 2022
1 parent 694602a commit a5d6223
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.MessageSource;
import org.springframework.data.repository.query.Param;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.GrantedAuthority;
Expand Down Expand Up @@ -94,84 +95,6 @@ public class UserController {
* USER API
*/

//no verification -> this works and is tested
// @PostMapping(path = "/")
// public ResponseEntity<String>
// createUser(@RequestBody @Valid CreateUserDTO u) {
// try {
// userService.createUser(u);
// log.info("Successful creation of user");
// return ResponseEntity.ok("Created user");
// } catch (Exception e) {
// log.warn("Unable to create user\n" + e.getMessage());
// return ResponseEntity.internalServerError().body(
// "Unable to create user\n" + e.getMessage());
// }
// }


//register user is in auth controller!!


// @PostMapping(path = "/register")
// public ResponseEntity<String>
// createUser(@RequestBody @Valid CreateUserDTO u, HttpServletRequest request) {
// // Ensure email is unique
// log.info("attempting user create");
// if(userService.getUserByEmail(u.getEmail()) != null) {
// log.info("already exists user" + u.getEmail());
// return ResponseEntity.badRequest().body("Account already exists");
// }
// try {
// //Create user
// User registered = userService.registerNewUserAccount(u);
// log.info("Successful creation of user");
//
// //Send Verification Email To that user
// String siteURL = Utility.getSiteURL(request); //get site for verification email
// userService.sendVerificationEmail(registered,siteURL);
// log.info("Sent email to "+u.getEmail());
//
// return ResponseEntity.ok("Created user");
// } catch (Exception e) {
// log.warn("Unable to create user\n" + e.getMessage());
// return ResponseEntity.internalServerError().body(
// "Unable to create user\n" + e.getMessage());
// }
// }

// //account verification of user
// @PostMapping("/user/registration")
// public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid CreateUserDTO userDto) {
//
// try {
//// if(userService.getUserByEmail(userDto.getEmail()) != null) {
//// log.info("already exists user" + userDto.getEmail());
//// return new ModelAndView("registration","user",userDto);
//// }
// //This creates a new user, but the user's attribute "enabled" is set to false.
// //This must be set to true in order to sign in
// User registered = userService.registerNewUserAccount(userDto);
// log.info("Registered New Account");
//
//// String appUrl = request.getContextPath();
//// eventPublisher.publishEvent(new OnRegistrationCompleteEvent(registered,
//// request.getLocale(), appUrl));
// } catch (UserAlreadyExistException uaeEx) {
// ModelAndView mav = new ModelAndView("registration", "user", userDto);
// mav.addObject("message", "An account for that username/email already exists.");
// log.info("1st catch");
// return mav;
//
// } catch (RuntimeException ex) {
// log.info("2nd catch");
// return new ModelAndView("emailError", "user", userDto);
//
// }
//
// return new ModelAndView("successRegister", "user", userDto);
// }

@GetMapping("/registrationConfirm")
public String confirmRegistration
(WebRequest request, Model model, @RequestParam("token") String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface UserService {
public User getUser(Long id);
public void updateUser(Long id, UpdateUserDTO u) throws Exception;
public boolean emailExistsPub(String email);
public boolean isEnabled(String email);
public Iterable<User> getUsersByIdAndEmail(Long id, String email);
public Iterable<User> getUsers(Long userId);
public void testSendEmail(CreateUserDTO dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ public User registerNewUserAccount(CreateUserDTO dto, HttpServletRequest request
log.info("RegisterNewAccountRAN!");

//Send Verification Email To that user
String siteURL = Utility.getSiteURL(request); //get site for verification email
//String siteURL = Utility.getSiteURL(request); //get site for verification email
//createVerificationToken(u, UUID.randomUUID().toString());
//TODO CHANGE BEFORE GOING LIVE
String siteURL="https://fridger.recipes";
sendVerificationEmail(u,siteURL);
log.info("Sent email to "+u.getEmail());

Expand All @@ -117,7 +119,6 @@ public User registerNewUserAccount(CreateUserDTO dto, HttpServletRequest request

public void sendVerificationEmail(User user, String siteURL)
throws MessagingException, UnsupportedEncodingException {
SimpleMailMessage email = new SimpleMailMessage();

String subject = "Fridger: Email Verification";
String senderName = "Fridger team";
Expand All @@ -126,10 +127,10 @@ public void sendVerificationEmail(User user, String siteURL)
"for signing up with us! But before you can do that, we need you to " +
"confirm your email for us! Go ahead and click the link below!";

String verifyURL = siteURL + "/verify?token=" + user.getVerificationCode(); //pass verification token for user
String verifyURL = siteURL + "/verify?code=" + user.getVerificationCode(); //pass verification token for user

mailContent += "<h3><a href=\"" + verifyURL + "\">VERIFY</a></h3>";
mailContent += "<p>Thank you<br>The Fridger Team</p>";
mailContent += "<p>Thank you,<br>The Fridger Team</p>";

MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
Expand Down Expand Up @@ -158,6 +159,14 @@ public boolean verify(String verificationCode) {

}

//This method will see if the user is enabled yet
public boolean isEnabled(String email) {
Optional<User> u = users.findByEmail(email);
if(!u.isPresent())
return false;
return u.get().isEnabled();
}

public void testSendEmail(CreateUserDTO dto) {
SimpleMailMessage email = new SimpleMailMessage();
email.setFrom("[email protected]");
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import AddComplaint from './pages/AddComplaint';
import Complaint from './pages/Complaint';
import Favorite from './pages/Favorite';
import Loading from './pages/Loading';

import Verify from './pages/Verify';
//import Recipe from './pages/Recipe';
/* Core CSS required for Ionic components to work properly */
import '@ionic/react/css/core.css';
Expand Down Expand Up @@ -103,6 +105,7 @@ import myReviews from './pages/myReviews';
<UserRoute path="/profile/:id?" component={Profile} />
<UserRoute path="/editprofile" component={EditProfile} />

<Route path="/verify" component={Verify} />
<Route path="/recipe/:id" component={Recipe} />
<Route path="/recipe" component={Recipes} />
<Route path="/recipes" component={Recipes} />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const RegistrationForm: React.FC = () => {
};
const body = JSON.stringify(getValues());
axios.post(
`https://api.fridger.recipes/v1/auth/register`,
// `https://api.fridger.recipes/v1/auth/register`,
// `https://api.fridger.recipes/v1/auth/register`,

//sending test
// 'http://localhost:8080/v1/user/user/registration',
'http://localhost:8080/v1/auth/register',
body,
config
).then( res => {
Expand Down

0 comments on commit a5d6223

Please sign in to comment.