<file_sep>package cn.edu.nju.onlineexam.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * Created by user on 2017/11/20.
 *
 */
@Entity
public class Relation_PaperAndProblem {
    @Id
    @GeneratedValue
    private long id;

    @Column
    private long paperId;

    @Column
    private long studentId;

    @Column
    private long problemId;

    @Column
    private String stAnswer;

    public Relation_PaperAndProblem(){}

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getPaperId() {
        return paperId;
    }

    public void setPaperId(long paperId) {
        this.paperId = paperId;
    }

    public long getProblemId() {
        return problemId;
    }

    public void setProblemId(long problemId) {
        this.problemId = problemId;
    }

    public String getStAnswer() {
        return stAnswer;
    }

    public void setStAnswer(String stAnswer) {
        this.stAnswer = stAnswer;
    }

    public long getStudentId() {
        return studentId;
    }

    public void setStudentId(long studentId) {
        this.studentId = studentId;
    }
}
<file_sep>package cn.edu.nju.onlineexam.Util;
import java.util.List;
import java.util.Properties;

import javax.mail.*;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;
/**
 * Created by mac on 2017/12/13.
 */
public class MailUtil {

    public static void send(String txt,String sub,String receiver) throws Exception{
        Properties props = new Properties();
        props.setProperty("mail.debug", "false");
        props.setProperty("mail.smtp.ssl.enable", "true");
        props.setProperty("mail.smtp.auth", "true");
        props.setProperty("mail.host", "smtp.163.com");
        props.setProperty("mail.transport.protocol", "smtp");
        Session session = Session.getInstance(props);
        Message msg = new MimeMessage(session);
        msg.setSubject(sub);
        msg.setText(txt);
        msg.setFrom(new InternetAddress("<EMAIL>"));
        Transport transport = session.getTransport();
        transport.connect("<EMAIL>", "zhouyao123");
        transport.sendMessage(msg, new Address[] {new InternetAddress(receiver)});
        transport.close();
    }

    public static void main(String[] args) throws Exception{
        send("1","1","<EMAIL>");
    }

}
<file_sep>import Vue from 'vue'
import Router from 'vue-router'
import Maps from './map'

Vue.use(Router)
// 实际路由设置
const router = new Router(Maps)
// 验证登录
router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requiresAuth)) {
    // this route requires auth, check if logged in
    // TODO
    console.log('requires auth')
    // 向后端获取是否登录的信息来设置 loggedIn 这里先默认为 true
    let loggedIn = true
    // if not, redirect to login page.
    if (!loggedIn) {
      next({
        path: '/teacher/login'
        // query: { redirect: to.fullPath }
      })
    } else {
      next()
    }
  } else {
    next() // 确保一定要调用 next()
  }
})

export default router
<file_sep>package cn.edu.nju.onlineexam.service;

import cn.edu.nju.onlineexam.Exception.LoginInvalidException;
import cn.edu.nju.onlineexam.Repository.TeacherRepository;
import cn.edu.nju.onlineexam.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.ws.Action;

@Service
public class TeacherServiceImpl implements TeacherService{

    @Autowired
    private TeacherRepository teacherRepository;

    @Override
    public Teacher register(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    @Override
    public void delete(Long id) {
        teacherRepository.delete(id);
    }

    @Override
    public Teacher update(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

    @Override
    public Teacher findTeacherById(Long id) {
        return teacherRepository.findOne(id);
    }

    @Override
    public Teacher findTeacherByAccount(String account) {
        return teacherRepository.findByAccount(account);
    }

    @Override
    public Teacher login(String account, String password) throws LoginInvalidException {
        Teacher teacher = teacherRepository.findByAccount(account);
        if(teacher == null)
            throw new LoginInvalidException("email is not valid");
        if(!password.equals(teacher.getPassword()))
            throw new LoginInvalidException("password is not valid");
        return teacher;
    }
}
<file_sep>package cn.edu.nju.onlineexam.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * Created by user on 2017/11/20.
 *
 */
@Entity
public class Problem {
    @Id
    @GeneratedValue
    private long id;

    @Column
    private String content;

    @Column
    private String A;

    @Column
    private String B;

    @Column
    private String C;

    @Column
    private String D;

    @Column
    private String answer;

    public Problem(){}

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }


    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getA() {
        return A;
    }

    public void setA(String a) {
        A = a;
    }

    public String getB() {
        return B;
    }

    public void setB(String b) {
        B = b;
    }

    public String getC() {
        return C;
    }

    public void setC(String c) {
        C = c;
    }

    public String getD() {
        return D;
    }

    public void setD(String d) {
        D = d;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }
}
<file_sep>package cn.edu.nju.onlineexam.service;


import cn.edu.nju.onlineexam.Exception.LoginInvalidException;
import cn.edu.nju.onlineexam.Repository.StudentRepository;
import cn.edu.nju.onlineexam.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by user on 2017/11/20.
 *
 */
@Service
public class StudentServiceImpl implements StudentService{
    @Autowired
    private StudentRepository studentRepository;

    @Override
    public Student register(Student st) {
        return studentRepository.save(st);
    }

    @Override
    public void delete(Long id) {
        studentRepository.delete(id);
    }

    @Override
    public Student update(Student st) {
        return studentRepository.save(st);
    }

    @Override
    public Student findStudentById(long id) {
        return studentRepository.findOne(id);
    }

    @Override
    public Student findStudentByEmail(String email) {
        return studentRepository.findByEmail(email);
    }

    @Override
    public List<Student> findStudentByGrade(int s_grade) {
        return studentRepository.findByGrade(s_grade);
    }

    @Override
    public List<Student> findStudentByGradeAndClass(int s_grade, int s_class) {
        return studentRepository.findByGradeAndStudentClass(s_grade,s_class);
    }

    @Override
    public Student login(String email, String password) throws LoginInvalidException{
        Student student = studentRepository.findByEmail(email);
        if(student == null)
            throw new LoginInvalidException("email is not valid");
        if(!password.equals(student.getPassword()))
            throw new LoginInvalidException("password is not valid");
        return student;
    }
}
<file_sep>package cn.edu.nju.onlineexam.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Relation_ExamAndProblem {
    @Id
    @GeneratedValue
    private long id;

    /**
     * 某场考试的id
     */
    @Column
    private long examId;

    /**
     * 该场考试的题目id
     */
    @Column
    private long problemId;

    public Relation_ExamAndProblem(){}

    public long getExamId() {
        return examId;
    }

    public void setExamId(long examId) {
        this.examId = examId;
    }

    public long getProblemId() {
        return problemId;
    }

    public void setProblemId(long problemId) {
        this.problemId = problemId;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}
<file_sep>package cn.edu.nju.onlineexam.Repository;

import cn.edu.nju.onlineexam.entity.Relation_StudentAndExam;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface Relation_StudentAndExamRepository extends JpaRepository<Relation_StudentAndExam,Long>{

    public List<Relation_StudentAndExam> findByStId(long studentId);

    public List<Relation_StudentAndExam> findByExamineId(long examId);

    public Relation_StudentAndExam findByStIdAndExamineId(long studentId, long examId);
}
<file_sep>package cn.edu.nju.onlineexam.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Teacher {
    @Id
    @GeneratedValue
    private long id;

    /**
     * 教师工号
     */
    @Column
    private String account;

    /**
     * 教师登录密码
     */
    @Column
    private String password;

    /**
     * 教师所教课程
     */
    @Column
    private String courses;

    public Teacher(){}

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = <PASSWORD>;
    }

    public String getCourses() {
        return courses;
    }

    public void setCourses(String courses) {
        this.courses = courses;
    }
}
<file_sep>package cn.edu.nju.onlineexam.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * Created by user on 2017/11/20.
 *
 */
@Entity
public class Exam {
    @Id
    @GeneratedValue
    private long id;

    /**
     * 考试名称
     */
    @Column
    private String name;

    /**
     * 试题数目
     */
    @Column
    private int number;

    /**
     * 每题分值
     */
    @Column
    private int value;

    /**
     * 考试开始时间
     */
    @Column
    private String start_time;

    /**
     * 考试结束时间
     */
    @Column
    private String end_time;

    /**
     * 发起这场考试的老师id
     */
    @Column
    private long teacherId;

    /**
     * 考试状态
     * 0表示未开始
     * 1表示进行中
     * 2表示已结束
     * 3表示已弃考
     */
    @Column
    private int status;

    public Exam() {
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getStart_time() {
        return start_time;
    }

    public void setStart_time(String start_time) {
        this.start_time = start_time;
    }

    public String getEnd_time() {
        return end_time;
    }

    public void setEnd_time(String end_time) {
        this.end_time = end_time;
    }

    public long getTeacherId() {
        return teacherId;
    }

    public void setTeacherId(long teacherId) {
        this.teacherId = teacherId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}
<file_sep>package cn.edu.nju.onlineexam.service;

import cn.edu.nju.onlineexam.Exception.LoginInvalidException;
import cn.edu.nju.onlineexam.entity.Teacher;

public interface TeacherService {
    public Teacher register(Teacher teacher);
    public void delete(Long id);
    public Teacher update(Teacher teacher);
    public Teacher findTeacherById(Long id);
    public Teacher findTeacherByAccount(String account);
    public Teacher login(String email, String passWord) throws LoginInvalidException;
}
<file_sep>package cn.edu.nju.onlineexam.Repository;

import cn.edu.nju.onlineexam.entity.Relation_PaperAndProblem;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface Relation_PaperAndProblemRepository extends JpaRepository<Relation_PaperAndProblem,Long>{
    public List<Relation_PaperAndProblem> findByPaperIdAndStudentId(long paperId, long stId);
    public List<Relation_PaperAndProblem> findByPaperId(long paperId);
    public Relation_PaperAndProblem findByProblemId(long problemId);
}
<file_sep>package cn.edu.nju.onlineexam.Repository;

import cn.edu.nju.onlineexam.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface StudentRepository extends JpaRepository<Student,Long> {
    public Student findByEmail(String email);

    public List<Student> findByGrade(int grade);

    public List<Student> findByGradeAndStudentClass(int grade, int studentClass);
}
<file_sep>package cn.edu.nju.onlineexam.Repository;

import cn.edu.nju.onlineexam.entity.Paper;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PaperRepository extends JpaRepository<Paper,Long>{
    public Paper findByExamIdAndStId(long examId, long studentId);
}
<file_sep>package cn.edu.nju.onlineexam.DTO;

import cn.edu.nju.onlineexam.entity.Problem;

import java.util.List;

public class PaperDTO {
    private String examName;

    private String studentName;

    private String studentNo;

    private List<Problem> problems;

    private String studentAnswers;

    private int mark;

    private int value;


    public List<Problem> getProblems() {
        return problems;
    }

    public void setProblems(List<Problem> problems) {
        this.problems = problems;
    }

    public String getExamName() {
        return examName;
    }

    public void setExamName(String name) {
        this.examName = name;
    }

    public String getStudentAnswers() {
        return studentAnswers;
    }

    public void setStudentAnswers(String studentAnswers) {
        this.studentAnswers = studentAnswers;
    }

    public int getMark() {
        return mark;
    }

    public void setMark(int mark) {
        this.mark = mark;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public String getStudentNo() {
        return studentNo;
    }

    public void setStudentNo(String studentNo) {
        this.studentNo = studentNo;
    }
}
<file_sep>package cn.edu.nju.onlineexam.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * Created by user on 2017/11/20
 * .
 */
@Entity
public class Relation_StudentAndExam {
    @Id
    @GeneratedValue
    private long id;

    @Column
    private long stId;

    @Column
    private long examineId;

    /**
     * 考试状态
     * 0表示未开始
     * 1表示进行中
     * 2表示已结束
     * 3表示已弃考
     */
    @Column
    private int status;

    public Relation_StudentAndExam(){}

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getStId() {
        return stId;
    }

    public void setStId(long stId) {
        this.stId = stId;
    }

    public long getExamineId() {
        return examineId;
    }

    public void setExamineId(long examineId) {
        this.examineId = examineId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}
<file_sep>const Dist = {
  template: '<router-view></router-view>'
}

export default {
  mode: 'history',
  routes: [
    {
      path: 'login',
      name: 'LoginPage',
      component (resolve) {
        require(['@/page/auth/LoginPage'], resolve)
      },
      meta: { requiresAuth: false }
    },
    {
      path: '/teacher',
      component: Dist,
      children: [
        {
          path: 'login',
          name: 'teacherLoginPage',
          component (resolve) {
            require(['@/page/auth/LoginPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'register',
          name: 'RegisterTeacherPage',
          component (resolve) {
            require(['@/page/auth/RegisterTeacherPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'question/:teacherId',
          name: 'QuestionListPage',
          component (resolve) {
            require(['@/page/teacher/QuestionListPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'question/detail/:teacherId/:examId',
          name: 'QuestionListDetailPage',
          component (resolve) {
            require(['@/page/teacher/QuestionListDetailPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'question/upload/:teacherId/:examId',
          name: 'QuestionUploadPage',
          component (resolve) {
            require(['@/page/teacher/QuestionUploadPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'exam/generate/:teacherId',
          name: 'ExamGenerate',
          component (resolve) {
            require(['@/page/teacher/ExamGeneratePage'], resolve)
          },
          meta: { requiresAuth: false }
        }
      ]
    },
    {
      path: '/student',
      component: Dist,
      children: [
        {
          path: 'login',
          name: 'studentLoginPage',
          component (resolve) {
            require(['@/page/auth/LoginPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'register',
          name: 'RegisterStudentPage',
          component (resolve) {
            require(['@/page/auth/RegisterStudentPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'exam/list/:studentId',
          name: 'ExamList',
          component (resolve) {
            require(['@/page/student/ExamListPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'exam/:studentId/:examId/question/:questionId/:first',
          name: 'ExamQuestion',
          props: true,
          component (resolve) {
            require(['@/page/student/ExamQuestionPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'exam/:examId/check/:answer/:mark',
          name: 'ExamCheck',
          props: true,
          component (resolve) {
            require(['@/page/student/ExamCheckPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'exam/:studentId/list/:examId/info',
          name: 'ExamInfo',
          props: true,
          component (resolve) {
            require(['@/page/student/ExamInfoPage'], resolve)
          },
          meta: { requiresAuth: false }
        },
        {
          path: 'exam/:studentId/:examId/paper',
          name: 'ExamPaper',
          props: true,
          component (resolve) {
            require(['@/page/student/ExamPaperPage'], resolve)
          },
          meta: { requiresAuth: false }
        }
      ]
    }
  ]
}
