Browse Source

Переконфигурация файлов. Обработка ошибок при регистрации студента

Кинетик 5 years ago
parent
commit
7202a0c7de

+ 9 - 0
src/EntitiesDao/StudentDao.java

@@ -32,4 +32,13 @@ public class StudentDao {
         session.getTransaction().commit();
         session.close();
     }
+    public static boolean checkIsStudent(StudentsEntity student){
+        Session session = getSession();
+        Query query = session.createQuery("FROM StudentsEntity Where stFamily="+student.getStFamily()+" and stFirstName="+student.getStFirstName()+" and stSecName="+student.getStSecName()+" and stGroup="+student.getStGroup());
+        List<StudentsEntity> res = query.list();
+        if(res.size()==0){
+            return false;
+        }
+        return true;
+    }
 }

+ 4 - 4
src/controller/controller.java

@@ -30,10 +30,10 @@ public class controller {
     ModelAndView mvUsers = new ModelAndView();
     {
         //Блок инициализации всех view, которые используются при авторизации
-        mvAdmin.setViewName("adminBar");
-        mvClient.setViewName("ownerBar");
-        mvStudent.setViewName("studentBar");
-        mvUsers.setViewName("index");
+        mvAdmin.setViewName("loginViews/adminBar");
+        mvClient.setViewName("loginViews/ownerBar");
+        mvStudent.setViewName("loginViews/studentBar");
+        mvUsers.setViewName("loginViews/index");
     }
     //Мапит запрос на вход на сайт, возвращает страницу index и грузит в нее объект, чтобы записывать данные в него
     @RequestMapping(value = "/", method = RequestMethod.GET)

+ 42 - 12
src/controller/registrationController.java

@@ -14,6 +14,7 @@ import java.util.List;
 
 import static EntitiesDao.AdminDao.createNewAdmin;
 import static EntitiesDao.GroupDao.getGroupList;
+import static EntitiesDao.StudentDao.checkIsStudent;
 import static EntitiesDao.StudentDao.createNewStudent;
 import static EntitiesDao.ClientsDao.createNewClient;
 
@@ -23,37 +24,66 @@ import static EntitiesDao.ClientsDao.createNewClient;
 @Controller
 public class registrationController {
     ModelAndView mvUsers = new ModelAndView();
+    ModelAndView mvRegAdmin = new ModelAndView("registrationViews/regAdminPage");
+    ModelAndView mvRegClient = new ModelAndView("registrationViews/regClientPage");
+    ModelAndView mvRegStudent = new ModelAndView("registrationViews/regStudentPage");
     {
-        mvUsers.setViewName("index");
+        mvUsers.setViewName("loginViews/index");
         mvUsers.addObject("userJSP", new LoginUser());
     }
     @RequestMapping(value="/registrate")
     public ModelAndView registrationUser(){
-        return new ModelAndView("registration");
+        return new ModelAndView("registrationViews/registration");
     }
     @RequestMapping(value="/regStudent")
     public ModelAndView regStudentLink(){
-        ModelAndView mv = new ModelAndView("regStudentPage");
         List<GroupsEntity> groupList = getGroupList();
-        mv.addObject("groupList",groupList);
-        mv.addObject("student", new StudentsEntity());
-        return mv;
+        mvRegStudent.addObject("groupList",groupList);
+        mvRegStudent.addObject("student", new StudentsEntity());
+        return mvRegStudent;
     }
     @RequestMapping(value="/regClient")
     public ModelAndView regClientLink(){
-        ModelAndView mv = new ModelAndView("regCLientPage");
-        mv.addObject("client", new ClientsEntity());
-        return mv;
+        mvRegClient.addObject("client", new ClientsEntity());
+        return mvRegClient;
     }
     @RequestMapping(value="/regAdmin")
     public ModelAndView regAdminLink(){
-        ModelAndView mv = new ModelAndView("regAdminPage");
-        mv.addObject("admin",new ModeratorsEntity());
-        return mv;
+        mvRegAdmin.addObject("admin",new ModeratorsEntity());
+        return mvRegAdmin;
     }
     @RequestMapping(value="/regStudentAction")
     public ModelAndView regStudentAction(@ModelAttribute("student") StudentsEntity student){
+        student.setStFamily(student.getStFamily().trim());
+        student.setStFirstName(student.getStFirstName().trim());
+        student.setStSecName(student.getStSecName().trim());
+        student.setStPkNumber(student.getStPkNumber().trim());
+        boolean errors = false;
+        if(student.getStFirstName().equals("")){
+            mvRegStudent.addObject("nameMessage","Это поле обязательно для заполнения");
+            errors = true;
+        }
+        if(student.getStFamily().equals("")){
+            mvRegStudent.addObject("famMessage","Это поле обязательно для заполнения");
+            errors = true;
+        }
+        if(student.getStSecName().equals("")){
+            mvRegStudent.addObject("secNameMessage","Это поле обязательно для заполнения");
+            errors = true;
+        }
+        if(student.getStPkNumber().equals("")){
+            mvRegStudent.addObject("passMessage","Это поле обязательно для заполнения");
+            errors = true;
+        }
+        if(!errors && checkIsStudent(student)){
+            mvRegStudent.addObject("errMessage","Студент с такими данными уже зарегистрирован в системе");
+            errors = true;
+        }
+        if(errors){
+            return mvRegStudent;
+        }
         createNewStudent(student);
+        mvRegStudent = new ModelAndView("registrationViews/regStudentPage");
         mvUsers.addObject("message","registration of student done");
         return mvUsers;
     }

web/WEB-INF/views/adminBar.jsp → web/WEB-INF/views/loginViews/adminBar.jsp


+ 3 - 3
web/WEB-INF/views/index.jsp

@@ -8,15 +8,15 @@
 <%@ taglib prefix="spring" uri="http://www.springframework.org/tags/form" %>
 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
-<link href="bootstrap.min.css" rel="stylesheet">
+<link href="../bootstrap.min.css" rel="stylesheet">
 
 <html>
 
 <head>
   <title>Login Page</title>
   <style type="text/css">
-    <%@include file="cssforpr.css" %>
-    <%@include file="bootstrap.min.css" %>
+    <%@include file="../cssforpr.css" %>
+    <%@include file="../bootstrap.min.css" %>
   </style>
 </head>
 

web/WEB-INF/views/ownerBar.jsp → web/WEB-INF/views/loginViews/ownerBar.jsp


+ 2 - 2
web/WEB-INF/views/studentBar.jsp

@@ -30,8 +30,8 @@
                     var html = '<option value="">Первый элемент</option>';
                     var len = data.length;
                     for ( var i = 0; i < len; i++) {
-                        html += '<option value="' + data[i].studentsId + '">'
-                            + data[i].stFamily + '</option>';
+                        html += '<option value="' + data[i].name + '">'
+                            + data[i].name + '</option>';
                     }
                     html += '</option>';
                     $('#studentId').html(html);

web/WEB-INF/views/regAdminPage.jsp → web/WEB-INF/views/registrationViews/regAdminPage.jsp


web/WEB-INF/views/regClientPage.jsp → web/WEB-INF/views/registrationViews/regClientPage.jsp


web/WEB-INF/views/regStudentPage.jsp → web/WEB-INF/views/registrationViews/regStudentPage.jsp


web/WEB-INF/views/registration.jsp → web/WEB-INF/views/registrationViews/registration.jsp