summaryrefslogtreecommitdiff
path: root/src/main/java/com/mavlushechka/studentdatabase
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/mavlushechka/studentdatabase')
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/Application.java33
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/config/CustomAuthenticationSuccessHandler.java25
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/config/MvcConfig.java22
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/config/WebSecurityConfig.java62
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/AdminPanelController.java226
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/EducationalSystemController.java37
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/FamilyController.java37
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/GraduatedInstitutionController.java37
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/HealthController.java37
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/HomeController.java19
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/JobController.java37
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/MilitaryServiceController.java37
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/PassportController.java37
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/PasswordController.java41
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java41
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Certificate.java31
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/EducationalSystem.java171
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Family.java54
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/GraduatedInstitution.java54
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Health.java45
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Job.java54
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/MilitaryService.java72
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Parent.java58
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Passport.java189
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Person.java31
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Role.java34
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/Student.java95
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/domain/User.java66
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/EducationalSystemRepository.java10
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/FamilyRepository.java9
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/GraduatedInstitutionRepository.java9
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/HealthRepository.java9
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/JobRepository.java9
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/MilitaryServiceRepository.java9
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/PassportRepository.java11
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/RoleRepository.java10
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/StudentRepository.java9
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/repository/UserRepository.java10
-rwxr-xr-xsrc/main/java/com/mavlushechka/studentdatabase/service/CustomUserDetailsService.java50
39 files changed, 1827 insertions, 0 deletions
diff --git a/src/main/java/com/mavlushechka/studentdatabase/Application.java b/src/main/java/com/mavlushechka/studentdatabase/Application.java
new file mode 100755
index 0000000..275d756
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/Application.java
@@ -0,0 +1,33 @@
+package com.mavlushechka.studentdatabase;
+
+import com.mavlushechka.studentdatabase.domain.Role;
+import com.mavlushechka.studentdatabase.repository.RoleRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+
+@SpringBootApplication
+public class Application {
+ @Autowired
+ private RoleRepository roleRepository;
+
+ public static void main(String[] args) {
+ SpringApplication.run(Application.class, args);
+ }
+
+ private void saveRole(String role) {
+ if (roleRepository.findByRole(role) == null) {
+ roleRepository.save(new Role(role));
+ }
+ }
+
+ @Bean
+ CommandLineRunner init() {
+ return args -> {
+ saveRole("ADMIN");
+ saveRole("USER");
+ };
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/mavlushechka/studentdatabase/config/CustomAuthenticationSuccessHandler.java b/src/main/java/com/mavlushechka/studentdatabase/config/CustomAuthenticationSuccessHandler.java
new file mode 100755
index 0000000..2239e91
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/config/CustomAuthenticationSuccessHandler.java
@@ -0,0 +1,25 @@
+package com.mavlushechka.studentdatabase.config;
+
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@Component
+public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
+ @Override
+ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
+ response.setStatus(HttpServletResponse.SC_OK);
+
+ for (GrantedAuthority auth : authentication.getAuthorities()) {
+ switch (auth.getAuthority()) {
+ case "USER" -> response.sendRedirect("/");
+ case "ADMIN" -> response.sendRedirect("/admin-panel/information/students");
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/config/MvcConfig.java b/src/main/java/com/mavlushechka/studentdatabase/config/MvcConfig.java
new file mode 100755
index 0000000..ac7abb8
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/config/MvcConfig.java
@@ -0,0 +1,22 @@
+package com.mavlushechka.studentdatabase.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class MvcConfig implements WebMvcConfigurer {
+ @Bean
+ public BCryptPasswordEncoder bCryptPasswordEncoder() {
+ return new BCryptPasswordEncoder();
+ }
+
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/authentication/login").setViewName("authentication/login");
+ registry.addViewController("/authentication/change-password").setViewName("authentication/change-password");
+ registry.addViewController("/admin-panel/add-users").setViewName("/admin-panel/add-users");
+ registry.addViewController("/admin-panel/information/search").setViewName("/admin-panel/information/search");
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/mavlushechka/studentdatabase/config/WebSecurityConfig.java b/src/main/java/com/mavlushechka/studentdatabase/config/WebSecurityConfig.java
new file mode 100755
index 0000000..99733d6
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/config/WebSecurityConfig.java
@@ -0,0 +1,62 @@
+package com.mavlushechka.studentdatabase.config;
+
+import com.mavlushechka.studentdatabase.service.CustomUserDetailsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+
+@Configuration
+@EnableWebSecurity
+public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
+ @Autowired
+ private BCryptPasswordEncoder bCryptPasswordEncoder;
+ @Autowired
+ CustomAuthenticationSuccessHandler customAuthenticationSuccessHandler;
+
+ @Bean
+ public UserDetailsService mongoUserDetails() {
+ return new CustomUserDetailsService();
+ }
+
+ @Override
+ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+ UserDetailsService userDetailsService = mongoUserDetails();
+ auth
+ .userDetailsService(userDetailsService)
+ .passwordEncoder(bCryptPasswordEncoder);
+ }
+
+ @Override
+ protected void configure(HttpSecurity http) throws Exception {
+ http
+ .authorizeRequests()
+ .antMatchers("/admin-panel/**").hasAuthority("ADMIN")
+ .anyRequest().authenticated()
+ .and()
+ .csrf()
+ .disable()
+ .formLogin()
+ .loginPage("/authentication/login")
+ .permitAll()
+ .and()
+ .logout()
+ .logoutSuccessUrl("/")
+ .permitAll()
+ .and()
+ .exceptionHandling();
+ }
+
+ @Override
+ public void configure(WebSecurity web) {
+ web
+ .ignoring()
+ .antMatchers("/js/**", "/css/**", "/img/**", "/fonts/**");
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/AdminPanelController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/AdminPanelController.java
new file mode 100755
index 0000000..82e6fa9
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/AdminPanelController.java
@@ -0,0 +1,226 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.*;
+import com.mavlushechka.studentdatabase.repository.*;
+import com.mavlushechka.studentdatabase.service.CustomUserDetailsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.util.*;
+
+@Controller
+public class AdminPanelController {
+ @Autowired
+ private CustomUserDetailsService userDetailsService;
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private RoleRepository roleRepository;
+ @Autowired
+ private StudentRepository studentRepository;
+ @Autowired
+ private EducationalSystemRepository educationalSystemRepository;
+ @Autowired
+ private PassportRepository passportRepository;
+ @Autowired
+ private GraduatedInstitutionRepository graduatedInstitutionRepository;
+ @Autowired
+ private FamilyRepository familyRepository;
+ @Autowired
+ private HealthRepository healthRepository;
+ @Autowired
+ private JobRepository jobRepository;
+ @Autowired
+ private MilitaryServiceRepository militaryServiceRepository;
+
+ @GetMapping("/admin-panel/create-users")
+ public String createUsers(@RequestParam String group, @RequestParam int number, Map<String, Object> model) {
+ for (int i = 1; i <= number; i ++) {
+ Role userRole = roleRepository.findByRole("USER");
+ User user = new User(i + "student" + group, i + "student" + group, true, new HashSet<>(List.of(userRole)));
+ User userFromDb = userRepository.findByUsername(user.getUsername());
+
+ if (userFromDb != null) {
+ model.put("message", "User exists!");
+ return "/admin-panel/add-users";
+ }
+
+ userDetailsService.saveUser(user);
+ }
+ return "redirect:/admin-panel/all-users";
+ }
+
+ @GetMapping("/admin-panel/all-users")
+ public String getUsers(Map<String, Object> model) {
+ Iterable<User> users = userRepository.findAll();
+ model.put("users", users);
+ return "admin-panel/all-users";
+ }
+
+ @GetMapping("/admin-panel/information/all")
+ public String getAll(String id, String fullName, String group, Map<String, Object> model) {
+ Iterable<User> users = null;
+ Iterable<Student> students = null;
+ Iterable<Passport> passports = null;
+ Iterable<EducationalSystem> educationalSystems = null;
+ Iterable<GraduatedInstitution> graduatedInstitutions = null;
+ Iterable<Health> healths = null;
+ Iterable<Family> families = null;
+ Iterable<Job> jobs = null;
+ Iterable<MilitaryService> militaryServices = null;
+
+ List<User> userList = new ArrayList<>();
+ List<Student> studentList = new ArrayList<>();
+ List<Passport> passportList = new ArrayList<>();
+ List<EducationalSystem> educationalSystemList = new ArrayList<>();
+ List<GraduatedInstitution> graduatedInstitutionList = new ArrayList<>();
+ List<Health> healthList = new ArrayList<>();
+ List<Family> familyList = new ArrayList<>();
+ List<Job> jobList = new ArrayList<>();
+ List<MilitaryService> militaryServiceList = new ArrayList<>();
+
+ if (id != null) {
+ userList.add(userRepository.findById(id).orElse(new User()));
+ Student student = studentRepository.findById(id).orElse(new Student());
+ if (student.getPhoto() != null) {
+ student.setEncodedPhoto(Base64.getEncoder().encodeToString(student.getPhoto().getData()));
+ }
+ studentList.add(student);
+ passportList.add(passportRepository.findById(id).orElse(new Passport()));
+ educationalSystemList.add(educationalSystemRepository.findById(id).orElse(new EducationalSystem()));
+ graduatedInstitutionList.add(graduatedInstitutionRepository.findById(id).orElse(new GraduatedInstitution()));
+ healthList.add(healthRepository.findById(id).orElse(new Health()));
+ familyList.add(familyRepository.findById(id).orElse(new Family()));
+ jobList.add(jobRepository.findById(id).orElse(new Job()));
+ militaryServiceList.add(militaryServiceRepository.findById(id).orElse(new MilitaryService()));
+ } else if (fullName != null || group != null) {
+ ArrayList<String> ids = new ArrayList<>();
+ if (fullName != null) {
+ Iterable<Passport> passportIterable;
+ try {
+ passportIterable = passportRepository.findByFirstNameAndLastName(fullName.split(" ")[0], fullName.split(" ")[1]);
+ } catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
+ passportIterable = passportRepository.findByFirstName(fullName.split(" ")[0]);
+ }
+ for (Passport passport : passportIterable) {
+ ids.add(passport.getId());
+ }
+ } else {
+ Iterable<EducationalSystem> educationalSystemIterable;
+ educationalSystemIterable = educationalSystemRepository.findByGroup(group);
+ for (EducationalSystem educationalSystem : educationalSystemIterable) {
+ ids.add(educationalSystem.getId());
+ }
+ }
+
+ for (String eachId : ids) {
+ userList.add(userRepository.findById(eachId).orElse(new User()));
+ Student student = studentRepository.findById(eachId).orElse(new Student());
+ if (student.getPhoto() != null) {
+ student.setEncodedPhoto(Base64.getEncoder().encodeToString(student.getPhoto().getData()));
+ }
+ studentList.add(student);
+ passportList.add(passportRepository.findById(eachId).orElse(new Passport()));
+ educationalSystemList.add(educationalSystemRepository.findById(eachId).orElse(new EducationalSystem()));
+ graduatedInstitutionList.add(graduatedInstitutionRepository.findById(eachId).orElse(new GraduatedInstitution()));
+ healthList.add(healthRepository.findById(eachId).orElse(new Health()));
+ familyList.add(familyRepository.findById(eachId).orElse(new Family()));
+ jobList.add(jobRepository.findById(eachId).orElse(new Job()));
+ militaryServiceList.add(militaryServiceRepository.findById(eachId).orElse(new MilitaryService()));
+ }
+ } else {
+ users = userRepository.findAll();
+ students = studentRepository.findAll();
+ passports = passportRepository.findAll();
+ educationalSystems = educationalSystemRepository.findAll();
+ graduatedInstitutions = graduatedInstitutionRepository.findAll();
+ healths = healthRepository.findAll();
+ families = familyRepository.findAll();
+ jobs = jobRepository.findAll();
+ militaryServices = militaryServiceRepository.findAll();
+ }
+ if (id != null || fullName != null || group != null) {
+ users = userList;
+ students = studentList;
+ passports = passportList;
+ educationalSystems = educationalSystemList;
+ graduatedInstitutions = graduatedInstitutionList;
+ healths = healthList;
+ families = familyList;
+ jobs = jobList;
+ militaryServices = militaryServiceList;
+ }
+
+ model.put("users", users);
+ model.put("students", students);
+ model.put("passports", passports);
+ model.put("educationalSystems", educationalSystems);
+ model.put("graduatedInstitutions", graduatedInstitutions);
+ model.put("healths", healths);
+ model.put("families", families);
+ model.put("jobs", jobs);
+ model.put("militaryServices", militaryServices);
+ return "admin-panel/information/all";
+ }
+
+ @GetMapping("/admin-panel/information/students")
+ public String getStudents(Map<String, Object> model) {
+ Iterable<Student> students = studentRepository.findAll();
+ for (Student student : students) {
+ student.setEncodedPhoto(Base64.getEncoder().encodeToString(student.getPhoto().getData()));
+ }
+ model.put("students", students);
+ return "admin-panel/information/students";
+ }
+
+ @GetMapping("/admin-panel/information/educational-systems")
+ public String getEducationalSystems(Map<String, Object> model) {
+ Iterable<EducationalSystem> educationalSystems = educationalSystemRepository.findAll();
+ model.put("educationalSystems", educationalSystems);
+ return "admin-panel/information/educational-systems";
+ }
+
+ @GetMapping("/admin-panel/information/passports")
+ public String getPassports(Map<String, Object> model) {
+ Iterable<Passport> passports = passportRepository.findAll();
+ model.put("passports", passports);
+ return "admin-panel/information/passports";
+ }
+
+ @GetMapping("/admin-panel/information/graduated-institutions")
+ public String getGraduatedInstitutions(Map<String, Object> model) {
+ Iterable<GraduatedInstitution> graduatedInstitutions = graduatedInstitutionRepository.findAll();
+ model.put("graduatedInstitutions", graduatedInstitutions);
+ return "admin-panel/information/graduated-institutions";
+ }
+
+ @GetMapping("/admin-panel/information/families")
+ public String getFamilies(Map<String, Object> model) {
+ Iterable<Family> families = familyRepository.findAll();
+ model.put("families", families);
+ return "admin-panel/information/families";
+ }
+
+ @GetMapping("/admin-panel/information/health")
+ public String getHealth(Map<String, Object> model) {
+ Iterable<Health> health = healthRepository.findAll();
+ model.put("health", health);
+ return "admin-panel/information/health";
+ }
+
+ @GetMapping("/admin-panel/information/jobs")
+ public String getJobs(Map<String, Object> model) {
+ Iterable<Job> jobs = jobRepository.findAll();
+ model.put("jobs", jobs);
+ return "admin-panel/information/jobs";
+ }
+
+ @GetMapping("/admin-panel/information/military-services")
+ public String getMilitaryServices(Map<String, Object> model) {
+ Iterable<MilitaryService> militaryServices = militaryServiceRepository.findAll();
+ model.put("militaryServices", militaryServices);
+ return "admin-panel/information/military-services";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/EducationalSystemController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/EducationalSystemController.java
new file mode 100755
index 0000000..bbdb870
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/EducationalSystemController.java
@@ -0,0 +1,37 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.EducationalSystem;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.EducationalSystemRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Optional;
+
+@Controller
+public class EducationalSystemController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private EducationalSystemRepository educationalSystemRepository;
+
+ @GetMapping("/information/educational-system")
+ public String getUserIdAndEducationalSystem(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ EducationalSystem educationalSystem = educationalSystemRepository.findById(user.getId()).orElse(new EducationalSystem());
+ model.put("user", user);
+ model.put("educationalSystem", educationalSystem);
+ return "information/educational-system";
+ }
+
+ @PostMapping("/information/educational-system/save")
+ public String saveEducationalSystemRepository(EducationalSystem educationalSystem) {
+ educationalSystemRepository.save(educationalSystem);
+ return "redirect:/";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/FamilyController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/FamilyController.java
new file mode 100755
index 0000000..abbd36c
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/FamilyController.java
@@ -0,0 +1,37 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.Family;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.FamilyRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Optional;
+
+@Controller
+public class FamilyController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private FamilyRepository familyRepository;
+
+ @GetMapping("/information/family")
+ public String getUserAndFamily(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ Family family = familyRepository.findById(user.getId()).orElse(new Family());
+ model.put("user", user);
+ model.put("family", family);
+ return "information/family";
+ }
+
+ @PostMapping("/information/family/save")
+ public String saveFamily(Family family) {
+ familyRepository.save(family);
+ return "redirect:/";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/GraduatedInstitutionController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/GraduatedInstitutionController.java
new file mode 100755
index 0000000..c81a090
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/GraduatedInstitutionController.java
@@ -0,0 +1,37 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.GraduatedInstitution;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.GraduatedInstitutionRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Optional;
+
+@Controller
+public class GraduatedInstitutionController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private GraduatedInstitutionRepository graduatedInstitutionRepository;
+
+ @GetMapping("/information/graduated-institution")
+ public String getUserAndGraduatedInstitution(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ GraduatedInstitution graduatedInstitution = graduatedInstitutionRepository.findById(user.getId()).orElse(new GraduatedInstitution());
+ model.put("user", user);
+ model.put("graduatedInstitution", graduatedInstitution);
+ return "information/graduated-institution";
+ }
+
+ @PostMapping("/information/graduated-institution/save")
+ public String saveGraduatedInstitution(GraduatedInstitution graduatedInstitution) {
+ graduatedInstitutionRepository.save(graduatedInstitution);
+ return "redirect:/";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/HealthController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/HealthController.java
new file mode 100755
index 0000000..a09f133
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/HealthController.java
@@ -0,0 +1,37 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.Health;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.HealthRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Optional;
+
+@Controller
+public class HealthController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private HealthRepository healthRepository;
+
+ @GetMapping("/information/health")
+ public String getUserAndHealth(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ Health health = healthRepository.findById(user.getId()).orElse(new Health());
+ model.put("user", user);
+ model.put("health", health);
+ return "information/health";
+ }
+
+ @PostMapping("/information/health/save")
+ public String saveHealth(Health health) {
+ healthRepository.save(health);
+ return "redirect:/";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/HomeController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/HomeController.java
new file mode 100755
index 0000000..a21eea6
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/HomeController.java
@@ -0,0 +1,19 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import java.util.Map;
+
+@Controller
+public class HomeController {
+ @GetMapping("/")
+ public String getLoginButtonText(Authentication authentication, Map<String, Object> model) {
+ boolean authorized = authentication != null;
+ String loginButtonText = (authorized) ? authentication.getName() : "Kirish";
+ model.put("authorized", authorized);
+ model.put("loginButtonText", loginButtonText);
+ return "index";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/JobController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/JobController.java
new file mode 100755
index 0000000..a0f879c
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/JobController.java
@@ -0,0 +1,37 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.Job;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.JobRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Optional;
+
+@Controller
+public class JobController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private JobRepository jobRepository;
+
+ @GetMapping("/information/job")
+ public String getUserAndJob(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ Job job = jobRepository.findById(user.getId()).orElse(new Job());
+ model.put("user", user);
+ model.put("job", job);
+ return "information/job";
+ }
+
+ @PostMapping("/information/job/save")
+ public String saveJob(Job job) {
+ jobRepository.save(job);
+ return "redirect:/";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/MilitaryServiceController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/MilitaryServiceController.java
new file mode 100755
index 0000000..dde5635
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/MilitaryServiceController.java
@@ -0,0 +1,37 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.MilitaryService;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.MilitaryServiceRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Optional;
+
+@Controller
+public class MilitaryServiceController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private MilitaryServiceRepository militaryServiceRepository;
+
+ @GetMapping("/information/military-service")
+ public String getUserIdAndMilitaryService(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ MilitaryService militaryService = militaryServiceRepository.findById(user.getId()).orElse(new MilitaryService());
+ model.put("user", user);
+ model.put("militaryService", militaryService);
+ return "information/military-service";
+ }
+
+ @PostMapping("/information/military-service/save")
+ public String saveMilitaryService(MilitaryService militaryService) {
+ militaryServiceRepository.save(militaryService);
+ return "redirect:/";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/PassportController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/PassportController.java
new file mode 100755
index 0000000..35a8d7f
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/PassportController.java
@@ -0,0 +1,37 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.Passport;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.PassportRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Optional;
+
+@Controller
+public class PassportController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private PassportRepository passportRepository;
+
+ @GetMapping("/information/passport")
+ public String getUserIdAndPassport(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ Passport passport = passportRepository.findById(user.getId()).orElse(new Passport());
+ model.put("user", user);
+ model.put("passport", passport);
+ return "information/passport";
+ }
+
+ @PostMapping("/information/passport/save")
+ public String savePassport(Passport passport) {
+ passportRepository.save(passport);
+ return "redirect:/";
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/PasswordController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/PasswordController.java
new file mode 100755
index 0000000..d17d2f2
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/PasswordController.java
@@ -0,0 +1,41 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import com.mavlushechka.studentdatabase.service.CustomUserDetailsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+
+import java.util.Map;
+import java.util.Objects;
+
+@Controller
+public class PasswordController {
+ @Autowired
+ private CustomUserDetailsService userDetailsService;
+ @Autowired
+ UserRepository userRepository;
+ @Autowired
+ private BCryptPasswordEncoder bCryptPasswordEncoder;
+
+ @PostMapping("/authentication/update-password")
+ public String updatePassword(Authentication authentication, String password, String newPassword, String newPassword2, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ boolean incorrectPassword = !bCryptPasswordEncoder.matches(password, user.getPassword());
+ boolean incorrectNewPassword = !Objects.equals(newPassword, newPassword2);
+
+ model.put("incorrectPassword", incorrectPassword);
+ model.put("incorrectNewPassword", incorrectNewPassword);
+
+ if (!incorrectPassword && !incorrectNewPassword) {
+ user.setPassword(newPassword);
+ userDetailsService.saveUser(user);
+ return "redirect:/";
+ } else {
+ return "/authentication/change-password";
+ }
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java b/src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java
new file mode 100755
index 0000000..76bc0f2
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/controller/StudentController.java
@@ -0,0 +1,41 @@
+package com.mavlushechka.studentdatabase.controller;
+
+import com.mavlushechka.studentdatabase.domain.Student;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.StudentRepository;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.bson.BsonBinarySubType;
+import org.bson.types.Binary;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.Authentication;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
+import java.util.Map;
+
+@Controller
+public class StudentController {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private StudentRepository studentRepository;
+
+ @GetMapping("/information/student")
+ public String getUserAndStudent(Authentication authentication, Map<String, Object> model) {
+ User user = userRepository.findByUsername(authentication.getName());
+ Student student = studentRepository.findById(user.getId()).orElse(new Student());
+ model.put("user", user);
+ model.put("student", student);
+ return "information/student";
+ }
+
+ @PostMapping("/information/student/save")
+ public String saveStudent(String id, String diploma, long telephoneNumber, String religion, String car, String house, MultipartFile photo) throws IOException {
+ Student student = new Student(id, diploma, telephoneNumber, religion, car, house, new Binary(BsonBinarySubType.BINARY, photo.getBytes()));
+ studentRepository.save(student);
+ return "redirect:/";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Certificate.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Certificate.java
new file mode 100755
index 0000000..3c07425
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Certificate.java
@@ -0,0 +1,31 @@
+package com.mavlushechka.studentdatabase.domain;
+
+public class Certificate {
+ private String series;
+ private long number;
+ private String dateOfIssue;
+
+ public String getSeries() {
+ return series;
+ }
+
+ public void setSeries(String series) {
+ this.series = series;
+ }
+
+ public long getNumber() {
+ return number;
+ }
+
+ public void setNumber(long number) {
+ this.number = number;
+ }
+
+ public String getDateOfIssue() {
+ return dateOfIssue;
+ }
+
+ public void setDateOfIssue(String dateOfIssue) {
+ this.dateOfIssue = dateOfIssue;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/EducationalSystem.java b/src/main/java/com/mavlushechka/studentdatabase/domain/EducationalSystem.java
new file mode 100755
index 0000000..7215d86
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/EducationalSystem.java
@@ -0,0 +1,171 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "educationalSystems")
+public class EducationalSystem {
+ @Id
+ private String id;
+ private boolean exists;
+ private byte number;
+ private String degree;
+ private byte course;
+ private String formOfLearning;
+ private String language;
+ private short year;
+ private String faculty;
+ private int directionCode;
+ private String directionName;
+ private String group;
+ private String formOfEducation;
+ private String privilege;
+ private String typeOfPlace;
+ private String region;
+ private String city;
+ private String address;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public boolean isExists() {
+ return exists;
+ }
+
+ public void setExists(boolean exists) {
+ this.exists = exists;
+ }
+
+ public byte getNumber() {
+ return number;
+ }
+
+ public void setNumber(byte number) {
+ this.number = number;
+ }
+
+ public String getDegree() {
+ return degree;
+ }
+
+ public void setDegree(String degree) {
+ this.degree = degree;
+ }
+
+ public byte getCourse() {
+ return course;
+ }
+
+ public void setCourse(byte course) {
+ this.course = course;
+ }
+
+ public String getFormOfLearning() {
+ return formOfLearning;
+ }
+
+ public void setFormOfLearning(String formOfLearning) {
+ this.formOfLearning = formOfLearning;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ public short getYear() {
+ return year;
+ }
+
+ public void setYear(short year) {
+ this.year = year;
+ }
+
+ public String getFaculty() {
+ return faculty;
+ }
+
+ public void setFaculty(String faculty) {
+ this.faculty = faculty;
+ }
+
+ public int getDirectionCode() {
+ return directionCode;
+ }
+
+ public void setDirectionCode(int directionCode) {
+ this.directionCode = directionCode;
+ }
+
+ public String getDirectionName() {
+ return directionName;
+ }
+
+ public void setDirectionName(String directionName) {
+ this.directionName = directionName;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ public String getFormOfEducation() {
+ return formOfEducation;
+ }
+
+ public void setFormOfEducation(String formOfEducation) {
+ this.formOfEducation = formOfEducation;
+ }
+
+ public String getPrivilege() {
+ return privilege;
+ }
+
+ public void setPrivilege(String privilege) {
+ this.privilege = privilege;
+ }
+
+ public String getTypeOfPlace() {
+ return typeOfPlace;
+ }
+
+ public void setTypeOfPlace(String typeOfPlace) {
+ this.typeOfPlace = typeOfPlace;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Family.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Family.java
new file mode 100755
index 0000000..653c66f
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Family.java
@@ -0,0 +1,54 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "families")
+public class Family {
+ @Id
+ private String id;
+ private String parentsDivorced;
+ private boolean isMarried;
+ private Parent father;
+ private Parent mother;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getParentsDivorced() {
+ return parentsDivorced;
+ }
+
+ public void setParentsDivorced(String parentsDivorced) {
+ this.parentsDivorced = parentsDivorced;
+ }
+
+ public boolean isMarried() {
+ return isMarried;
+ }
+
+ public void setMarried(boolean married) {
+ isMarried = married;
+ }
+
+ public Parent getFather() {
+ return father;
+ }
+
+ public void setFather(Parent father) {
+ this.father = father;
+ }
+
+ public Parent getMother() {
+ return mother;
+ }
+
+ public void setMother(Parent mother) {
+ this.mother = mother;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/GraduatedInstitution.java b/src/main/java/com/mavlushechka/studentdatabase/domain/GraduatedInstitution.java
new file mode 100755
index 0000000..009b369
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/GraduatedInstitution.java
@@ -0,0 +1,54 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "graduatedInstitutions")
+public class GraduatedInstitution {
+ @Id
+ private String id;
+ private String name;
+ private String type;
+ private String territory;
+ private Certificate certificate;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getTerritory() {
+ return territory;
+ }
+
+ public void setTerritory(String territory) {
+ this.territory = territory;
+ }
+
+ public Certificate getCertificate() {
+ return certificate;
+ }
+
+ public void setCertificate(Certificate certificate) {
+ this.certificate = certificate;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Health.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Health.java
new file mode 100755
index 0000000..9ca3cc6
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Health.java
@@ -0,0 +1,45 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "health")
+public class Health {
+ @Id
+ private String id;
+ private boolean invalid;
+ private int invalidGroup;
+ private String invalidDiagnosis;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public boolean isInvalid() {
+ return invalid;
+ }
+
+ public void setInvalid(boolean invalid) {
+ this.invalid = invalid;
+ }
+
+ public int getInvalidGroup() {
+ return invalidGroup;
+ }
+
+ public void setInvalidGroup(int invalidGroup) {
+ this.invalidGroup = invalidGroup;
+ }
+
+ public String getInvalidDiagnosis() {
+ return invalidDiagnosis;
+ }
+
+ public void setInvalidDiagnosis(String invalidDiagnosis) {
+ this.invalidDiagnosis = invalidDiagnosis;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Job.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Job.java
new file mode 100755
index 0000000..4a4c362
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Job.java
@@ -0,0 +1,54 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "jobs")
+public class Job {
+ @Id
+ private String id;
+ private String name;
+ private String territory;
+ private long telephoneNumber;
+ private Person manager;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getTerritory() {
+ return territory;
+ }
+
+ public void setTerritory(String territory) {
+ this.territory = territory;
+ }
+
+ public long getTelephoneNumber() {
+ return telephoneNumber;
+ }
+
+ public void setTelephoneNumber(long telephoneNumber) {
+ this.telephoneNumber = telephoneNumber;
+ }
+
+ public Person getManager() {
+ return manager;
+ }
+
+ public void setManager(Person manager) {
+ this.manager = manager;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/MilitaryService.java b/src/main/java/com/mavlushechka/studentdatabase/domain/MilitaryService.java
new file mode 100755
index 0000000..40767da
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/MilitaryService.java
@@ -0,0 +1,72 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "militaryServices")
+public class MilitaryService {
+ @Id
+ private String id;
+ private long number;
+ private String type;
+ private String place;
+ private String year;
+ private String serialNumber;
+ private boolean alternative;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public long getNumber() {
+ return number;
+ }
+
+ public void setNumber(long number) {
+ this.number = number;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getPlace() {
+ return place;
+ }
+
+ public void setPlace(String place) {
+ this.place = place;
+ }
+
+ public String getYear() {
+ return year;
+ }
+
+ public void setYear(String year) {
+ this.year = year;
+ }
+
+ public String getSerialNumber() {
+ return serialNumber;
+ }
+
+ public void setSerialNumber(String serialNumber) {
+ this.serialNumber = serialNumber;
+ }
+
+ public boolean isAlternative() {
+ return alternative;
+ }
+
+ public void setAlternative(boolean alternative) {
+ this.alternative = alternative;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Parent.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Parent.java
new file mode 100755
index 0000000..2e37cb5
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Parent.java
@@ -0,0 +1,58 @@
+package com.mavlushechka.studentdatabase.domain;
+
+public class Parent {
+ private String firstName;
+ private String lastName;
+ private String middleName;
+ private String birthday;
+ private String placeOfWork;
+ private long telephoneNumber;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getBirthday() {
+ return birthday;
+ }
+
+ public void setBirthday(String birthday) {
+ this.birthday = birthday;
+ }
+
+ public String getPlaceOfWork() {
+ return placeOfWork;
+ }
+
+ public void setPlaceOfWork(String placeOfWork) {
+ this.placeOfWork = placeOfWork;
+ }
+
+ public long getTelephoneNumber() {
+ return telephoneNumber;
+ }
+
+ public void setTelephoneNumber(long telephoneNumber) {
+ this.telephoneNumber = telephoneNumber;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Passport.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Passport.java
new file mode 100755
index 0000000..b54b68a
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Passport.java
@@ -0,0 +1,189 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "passports")
+public class Passport {
+ @Id
+ private String id;
+ private String number;
+ private String firstName;
+ private String lastName;
+ private String middleName;
+ private String PINFL;
+ private String INN;
+ private String serialNumber;
+ private String dateOfIssue;
+ private String birthday;
+ private int age;
+ private String nationality;
+ private String gender;
+ private String republic;
+ private String region;
+ private String city;
+ private String organization;
+ private String village;
+ private String district;
+ private String address;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getNumber() {
+ return number;
+ }
+
+ public void setNumber(String number) {
+ this.number = number;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getPINFL() {
+ return PINFL;
+ }
+
+ public void setPINFL(String PINFL) {
+ this.PINFL = PINFL;
+ }
+
+ public String getINN() {
+ return INN;
+ }
+
+ public void setINN(String INN) {
+ this.INN = INN;
+ }
+
+ public String getSerialNumber() {
+ return serialNumber;
+ }
+
+ public void setSerialNumber(String serialNumber) {
+ this.serialNumber = serialNumber;
+ }
+
+ public String getDateOfIssue() {
+ return dateOfIssue;
+ }
+
+ public void setDateOfIssue(String dateOfIssue) {
+ this.dateOfIssue = dateOfIssue;
+ }
+
+ public String getBirthday() {
+ return birthday;
+ }
+
+ public void setBirthday(String birthday) {
+ this.birthday = birthday;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getNationality() {
+ return nationality;
+ }
+
+ public void setNationality(String nationality) {
+ this.nationality = nationality;
+ }
+
+ public String getGender() {
+ return gender;
+ }
+
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+
+ public String getRepublic() {
+ return republic;
+ }
+
+ public void setRepublic(String republic) {
+ this.republic = republic;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getOrganization() {
+ return organization;
+ }
+
+ public void setOrganization(String organization) {
+ this.organization = organization;
+ }
+
+ public String getVillage() {
+ return village;
+ }
+
+ public void setVillage(String village) {
+ this.village = village;
+ }
+
+ public String getDistrict() {
+ return district;
+ }
+
+ public void setDistrict(String district) {
+ this.district = district;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Person.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Person.java
new file mode 100755
index 0000000..9b47065
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Person.java
@@ -0,0 +1,31 @@
+package com.mavlushechka.studentdatabase.domain;
+
+public class Person {
+ private String firstName;
+ private String middleName;
+ private String lastName;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ public void setMiddleName(String middleName) {
+ this.middleName = middleName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Role.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Role.java
new file mode 100755
index 0000000..f35f7e7
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Role.java
@@ -0,0 +1,34 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "roles")
+public class Role {
+ @Id
+ private String id;
+ private String role;
+
+ public Role() {
+ }
+
+ public Role(String role) {
+ this.role = role;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getRole() {
+ return role;
+ }
+
+ public void setRole(String role) {
+ this.role = role;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/Student.java b/src/main/java/com/mavlushechka/studentdatabase/domain/Student.java
new file mode 100755
index 0000000..b4ab4d7
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/Student.java
@@ -0,0 +1,95 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.bson.types.Binary;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "students")
+public class Student {
+ @Id
+ private String id;
+ private String diploma;
+ private long telephoneNumber;
+ private String religion;
+ private String car;
+ private String house;
+ private Binary photo;
+ private String encodedPhoto;
+
+ public Student() {
+ }
+
+ public Student(String id, String diploma, long telephoneNumber, String religion, String car, String house, Binary photo) {
+ this.id = id;
+ this.diploma = diploma;
+ this.telephoneNumber = telephoneNumber;
+ this.religion = religion;
+ this.car = car;
+ this.house = house;
+ this.photo = photo;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getDiploma() {
+ return diploma;
+ }
+
+ public void setDiploma(String diploma) {
+ this.diploma = diploma;
+ }
+
+ public long getTelephoneNumber() {
+ return telephoneNumber;
+ }
+
+ public void setTelephoneNumber(long telephoneNumber) {
+ this.telephoneNumber = telephoneNumber;
+ }
+
+ public String getReligion() {
+ return religion;
+ }
+
+ public void setReligion(String religion) {
+ this.religion = religion;
+ }
+
+ public String getCar() {
+ return car;
+ }
+
+ public void setCar(String car) {
+ this.car = car;
+ }
+
+ public String getHouse() {
+ return house;
+ }
+
+ public void setHouse(String house) {
+ this.house = house;
+ }
+
+ public Binary getPhoto() {
+ return photo;
+ }
+
+ public void setPhoto(Binary photo) {
+ this.photo = photo;
+ }
+
+ public String getEncodedPhoto() {
+ return encodedPhoto;
+ }
+
+ public void setEncodedPhoto(String encodedPhoto) {
+ this.encodedPhoto = encodedPhoto;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/domain/User.java b/src/main/java/com/mavlushechka/studentdatabase/domain/User.java
new file mode 100755
index 0000000..39c3ac9
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/domain/User.java
@@ -0,0 +1,66 @@
+package com.mavlushechka.studentdatabase.domain;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.Set;
+
+@Document(collection = "users")
+public class User {
+ @Id
+ private String id;
+ private String username;
+ private String password;
+ private boolean active;
+ private Set<Role> roles;
+
+ public User() {
+ }
+
+ public User(String username, String password, boolean active, Set<Role> roles) {
+ this.username = username;
+ this.password = password;
+ this.active = active;
+ this.roles = roles;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public Set<Role> getRoles() {
+ return roles;
+ }
+
+ public void setRoles(Set<Role> roles) {
+ this.roles = roles;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/EducationalSystemRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/EducationalSystemRepository.java
new file mode 100755
index 0000000..5f90b82
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/EducationalSystemRepository.java
@@ -0,0 +1,10 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.EducationalSystem;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface EducationalSystemRepository extends MongoRepository<EducationalSystem, String> {
+ Iterable<EducationalSystem> findByGroup(String group);
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/FamilyRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/FamilyRepository.java
new file mode 100755
index 0000000..5dd05c6
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/FamilyRepository.java
@@ -0,0 +1,9 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.Family;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface FamilyRepository extends MongoRepository<Family, String> {
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/GraduatedInstitutionRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/GraduatedInstitutionRepository.java
new file mode 100755
index 0000000..92ad118
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/GraduatedInstitutionRepository.java
@@ -0,0 +1,9 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.GraduatedInstitution;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface GraduatedInstitutionRepository extends MongoRepository<GraduatedInstitution, String> {
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/HealthRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/HealthRepository.java
new file mode 100755
index 0000000..3407141
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/HealthRepository.java
@@ -0,0 +1,9 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.Health;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface HealthRepository extends MongoRepository<Health, String> {
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/JobRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/JobRepository.java
new file mode 100755
index 0000000..e6a2034
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/JobRepository.java
@@ -0,0 +1,9 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.Job;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface JobRepository extends MongoRepository<Job, String> {
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/MilitaryServiceRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/MilitaryServiceRepository.java
new file mode 100755
index 0000000..4eeece3
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/MilitaryServiceRepository.java
@@ -0,0 +1,9 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.MilitaryService;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MilitaryServiceRepository extends MongoRepository<MilitaryService, String> {
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/PassportRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/PassportRepository.java
new file mode 100755
index 0000000..319847b
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/PassportRepository.java
@@ -0,0 +1,11 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.Passport;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface PassportRepository extends MongoRepository<Passport, String> {
+ Iterable<Passport> findByFirstName(String firstName);
+ Iterable<Passport> findByFirstNameAndLastName(String firstName, String lastName);
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/RoleRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/RoleRepository.java
new file mode 100755
index 0000000..e82fdf9
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/RoleRepository.java
@@ -0,0 +1,10 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.Role;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface RoleRepository extends MongoRepository<Role, String> {
+ Role findByRole(String role);
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/StudentRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/StudentRepository.java
new file mode 100755
index 0000000..1b09e5f
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/StudentRepository.java
@@ -0,0 +1,9 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.Student;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface StudentRepository extends MongoRepository<Student, String> {
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/repository/UserRepository.java b/src/main/java/com/mavlushechka/studentdatabase/repository/UserRepository.java
new file mode 100755
index 0000000..ec7368d
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/repository/UserRepository.java
@@ -0,0 +1,10 @@
+package com.mavlushechka.studentdatabase.repository;
+
+import com.mavlushechka.studentdatabase.domain.User;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface UserRepository extends MongoRepository<User, String> {
+ User findByUsername(String login);
+}
diff --git a/src/main/java/com/mavlushechka/studentdatabase/service/CustomUserDetailsService.java b/src/main/java/com/mavlushechka/studentdatabase/service/CustomUserDetailsService.java
new file mode 100755
index 0000000..b238c98
--- /dev/null
+++ b/src/main/java/com/mavlushechka/studentdatabase/service/CustomUserDetailsService.java
@@ -0,0 +1,50 @@
+package com.mavlushechka.studentdatabase.service;
+
+import com.mavlushechka.studentdatabase.domain.Role;
+import com.mavlushechka.studentdatabase.domain.User;
+import com.mavlushechka.studentdatabase.repository.UserRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+@Service
+public class CustomUserDetailsService implements UserDetailsService {
+ @Autowired
+ private UserRepository userRepository;
+ @Autowired
+ private BCryptPasswordEncoder bCryptPasswordEncoder;
+
+ public void saveUser(User user) {
+ user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
+ userRepository.save(user);
+ }
+
+ @Override
+ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
+ User user = userRepository.findByUsername(username);
+
+ if (user != null) {
+ List<GrantedAuthority> authorities = getUserAuthority(user.getRoles());
+ return buildUserForAuthentication(user, authorities);
+ } else {
+ throw new UsernameNotFoundException("Username not found");
+ }
+ }
+
+ private List<GrantedAuthority> getUserAuthority(Set<Role> userRoles) {
+ Set<GrantedAuthority> roles = new HashSet<>();
+ userRoles.forEach((role) -> roles.add(new SimpleGrantedAuthority(role.getRole())));
+ return new ArrayList<>(roles);
+ }
+
+ private UserDetails buildUserForAuthentication(User user, List<GrantedAuthority> authorities) {
+ return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), authorities);
+ }
+}