public void updateProfile(String key, Account pAccount)
      throws SQLException, ConnectionException, MissingDataException, NullAccountException,
          ProfileException, PasswordException, EmailException {
    try (Connection connect = DBConnection.getConnection()) {
      pAccount = testAccount(pAccount);

      String sql =
          "UPDATE account"
              + "set name = '"
              + Utility.Replace(testProfileData(pAccount.getName()))
              + "', surname = '"
              + Utility.Replace(testProfileData(pAccount.getSurname()))
              + "', password = '******', secondaryEmail = '"
              + testEmail(pAccount.getSecondaryEmail())
              + "WHERE email = '"
              + key
              + "'";

      String sql2 = "UPDATE " + pAccount.getTypeAccount();

      if (pAccount instanceof PhdStudent) {
        sql2 +=
            " set telephone = '"
                + testProfileData(((PhdStudent) pAccount).getTelephone())
                + "', link =  '"
                + testProfileData(((PhdStudent) pAccount).getLink())
                + "', deparment = '"
                + testProfileData(((PhdStudent) pAccount).getDepartment())
                + "', researchInterest = '"
                + testProfileData(((PhdStudent) pAccount).getResearchInterest())
                + "' WHERE fkAccount = '"
                + testProfileData(((PhdStudent) pAccount).getSecondaryEmail());
      }

      if (pAccount instanceof Professor) {
        sql2 +=
            " set link = '"
                + ((Professor) pAccount).getLink()
                + "', set department = '"
                + ((Professor) pAccount).getDepartment()
                + "' WHERE fkAccount = '"
                + ((Professor) pAccount).getSecondaryEmail()
                + "'";
      }

      if (pAccount.getTypeAccount().equals("basic")) // aggiorna solo info base
      Utility.executeOperation(connect, sql);
      else {
        Utility.executeOperation(connect, sql);
        Utility.executeOperation(connect, sql2);
      }

      connect.commit();
    }
  }
Пример #2
0
 private User buildUserForAuthentication(Account account, List<GrantedAuthority> authorities) {
   return new User(
       account.getUsername(),
       account.getPassword(),
       account.isEnabled(),
       account.isAccountNonExpired(),
       account.isCredentialsNonExpired(),
       account.isAccountNonLocked(),
       authorities);
 }