示例#1
0
  public String saveLecturer() {
    HttpServletRequest req =
        (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

    if (!lecturer.getEmail().equals(reemail)) {
      MessageUtils.addErrorMessage("E-mails mismatch");
      return null;
    }

    if (!lecturer.getPassword().equals(repassword)) {
      MessageUtils.addErrorMessage("Passwords mismatch");
      return null;
    }

    boolean existing = lecturerDao.findUserByName(lecturer.getUsername());
    if (existing) {
      MessageUtils.addErrorMessage("There is already user with this username!");
      return null;
    }

    String plainPassword = lecturer.getPassword();
    String encryptedPassword = GeneralUtils.encodeSha256Password(plainPassword);
    lecturer.setPassword(encryptedPassword);
    lecturer.setEmail(lecturer.getEmail().toLowerCase());

    UserModel user = new UserModel();
    user.setType(UserType.LECTURER);
    user.setLecturer(lecturer);
    user.setUsername(lecturer.getUsername());
    user.setPassword(lecturer.getPassword());

    Set<String> permissions = new HashSet<String>();
    permissions.add("PERMISSIONS_LECTURER");
    user.setPermissions(permissions);

    userDAO.addUser(user);

    req.getSession().setAttribute("_loggedUser", user);

    return "home?faces-redirect=true";
  }
示例#2
0
  @PostConstruct
  public void init() {
    if (lecturer == null) {
      lecturer = new LecturerModel();

      HttpServletRequest req =
          (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

      String email = (String) req.getSession().getAttribute("_identityEmail");

      lecturer.setEmail(email);
      setReemail(email);
    }

    if (StringUtils.isBlank(operationType)) {
      setOperationType("create");
    }
  }