PAN-54 Added call to UserService to query DB.

This commit is contained in:
BrittanyBi
2019-04-07 23:55:15 -06:00
parent 1a2715ec04
commit f86b36aa17
2 changed files with 22 additions and 1 deletions
@@ -1,12 +1,22 @@
package edu.msudenver.tsp.website;
import edu.msudenver.tsp.services.RestService;
import edu.msudenver.tsp.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@SpringBootApplication(scanBasePackages = "edu.msudenver.tsp")
public class Application {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
@Autowired
public UserService userService(final RestService restService) {
return new UserService(restService);
}
}
@@ -1,8 +1,11 @@
package edu.msudenver.tsp.website.controller;
import edu.msudenver.tsp.services.UserService;
import edu.msudenver.tsp.services.dto.Account;
import edu.msudenver.tsp.website.forms.UserCreationForm;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
@@ -16,6 +19,8 @@ import org.springframework.web.servlet.ModelAndView;
@AllArgsConstructor
@RequestMapping("/createuser")
public class UserCreationController {
@Autowired private final UserService userService;
@GetMapping({"/",""})
public ModelAndView createUserPage() {
LOG.info("Received request to display the user creation page: returning model with name 'User'");
@@ -34,6 +39,12 @@ public class UserCreationController {
model.addAttribute("referrer", userCreationForm.getReferrer());
model.addAttribute("TnCAgreement", userCreationForm.isAgreedToTerms());
final Account newUser = new Account();
newUser.setUsername(userCreationForm.getUsername());
newUser.setPassword(userCreationForm.getPassword());
userService.createAccount(newUser);
return "successfulRegistration";
}
}