Commit 650fc19c authored by sapn1s's avatar sapn1s
Browse files

Fixed master branch

parent 00d0480d
......@@ -40,9 +40,8 @@ public class CalendarController {
@Autowired
private CalendarValidator calendarValidator;
@GetMapping("/test")
public String testGet() {
public User findCurrentUser()
{
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
......@@ -53,6 +52,15 @@ public class CalendarController {
}
User currUser = userRepo.findByUsername(username);
return currUser;
}
@GetMapping("/test")
public String testGet() {
User currUser = findCurrentUser();
ArrayList<Calendar> c1 = calendarRepo.findAllByUser(currUser); //TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
System.out.println(currUser);
......@@ -67,19 +75,7 @@ public class CalendarController {
public String calendarGet(Model models)
{
//Get currently logged in user
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
User currUser = findCurrentUser();
//If user doesnt have calendar - redirected to create
......@@ -132,18 +128,7 @@ public class CalendarController {
}
//Get currently logged in user
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
User currUser = findCurrentUser();
calendar.setUser(currUser);
calendarRepo.save(calendar);
......@@ -156,16 +141,7 @@ public class CalendarController {
{
//This view will be for first time registered users.
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
User currUser = findCurrentUser();
ArrayList<Calendar> calList = calendarRepo.findAllByUser(currUser);
......@@ -184,18 +160,8 @@ public class CalendarController {
return "addNewCalendar";
}
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
User currUser = findCurrentUser();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
calendar.setUser(currUser);
calendarRepo.save(calendar);
......
......@@ -43,12 +43,8 @@ public class EventController {
@Autowired
private EventValidator eventValidator;
@GetMapping(value = "/add-new-event")
public String addNewEventGet(Model models, Event event)
public User findCurrentUser()
{
List<EventType> allEventTypes = Arrays.asList(EventType.values());
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
......@@ -57,8 +53,19 @@ public class EventController {
} else {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
return currUser;
}
@GetMapping(value = "/add-new-event")
public String addNewEventGet(Model models, Event event)
{
List<EventType> allEventTypes = Arrays.asList(EventType.values());
User currUser = findCurrentUser();
//If user doesnt have calendar - redirected to create
......@@ -87,15 +94,7 @@ public class EventController {
return "addNewEvent";
}
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
User currUser = findCurrentUser();
Calendar c1 = calendarRepo.findAllByUser(currUser).get(0); //TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
event.setCalendar(c1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment