コード例 #1
0
  /** To view edit my account */
  @Override
  public String execute() throws DataException {
    firstName = user.getFirstName();
    lastName = user.getLastName();
    email = user.getEmail();

    return SUCCESS;
  }
コード例 #2
0
  /**
   * Save user account information
   *
   * @return
   */
  public String saveMyAccount() {

    log.debug(EditMyAccount.class + ":" + "saveMyAccount()");

    try {
      User userWithEmail = getUserService().getUserByEmail(email, user.getServer());
      if (userWithEmail == null || userWithEmail.getId() == user.getId()) {
        user.setFirstName(firstName);
        user.setLastName(lastName);
        user.setEmail(email);

        getUserService().updateUser(user);
        errorType = "info";
        message = "Account information saved.";
      } else {
        addFieldError("emailExist", "Email already exists - " + email);
        errorType = "error";
        return INPUT;
      }
    } catch (Exception e) {
      log.error("Exception occured while saving user account information", e);
      addFieldError("dataError", e.getMessage());
      errorType = "error";
      return INPUT;
    }
    return SUCCESS;
  }
コード例 #3
0
  /**
   * Method that edits the details of the LDAP user
   *
   * @return {@link #SUCCESS}
   */
  public String editLDAPUser() {
    try {
      User user = getUserService().getUserById(userId);
      if (user == null) {
        this.addFieldError(
            "editLDAPUserError",
            "Error in editing LDAP user. An email has been sent to the administrator");
        getUserService().sendEmailErrorReport();
        errorType = "error";
        return ERROR;
      }
      user.setEmail(email);
      user.setFirstName(firstName);
      user.setLastName(lastName);
      user.setPassword(null);
      user.setAccountCreated(new Date());
      user.setFailedLoginAttempts(0);

      List<Server> serverList = getServerService().getAll();
      boolean serverExists = false;
      Server tempServer = null;
      Iterator<Server> iter = serverList.iterator();
      while (iter.hasNext()) {
        tempServer = (Server) iter.next();
        if (tempServer.getType() != Server.ServerType.LOCAL) {
          serverExists = true;
          break;
        }
      }

      if (serverExists == false) {
        this.addFieldError("addLDAPUserError", "NO LDAP Server has been configured");
        errorType = "error";
        return ERROR;
      }
      user.setServer(tempServer);
      user.setLastLogin(new Date());

      // Check if user has permissions
      boolean hasPermission = false;
      if (user.getGroups() != null && user.getGroups().size() > 0) {
        hasPermission = true;
      }

      user.removeAllGroups();
      for (int i = 0; i < groupsSelected.length; i++) {
        Group group = getGroupService().getGroupById(Integer.parseInt(groupsSelected[i]));
        user.addGroup(group);
      }

      User similarEmail = getUserService().getUserByEmail(email, tempServer);
      if (similarEmail != null) {
        if (similarEmail.getId() != userId) {
          if (!similarEmail.getServer().getName().equalsIgnoreCase("Local")) {
            this.addFieldError("editLDAPUserError", "Email ID already exists");
            errorType = "error";
            setGroupList(getGroupService().getAllGroups());
            setTemporaryUser(user);
            setSelectedGroups(groupsSelected);
            return INPUT;
          }
        }
      }
      getUserService().updateUser(user);

      // Email user that permissions has been added.
      if (!hasPermission) {
        getUserService().sendEmailToUserWithPermissions(user);
      }

      return SUCCESS;
    } catch (DatabaseConfigException dce) {
      log.error(dce.getMessage(), dce);
      this.addFieldError(
          "editLDAPUserError",
          "Unable to connect to the database. Database Configuration may be incorrect");
      errorType = "error";
      return ERROR;
    } catch (DataException de) {
      log.error(de.getMessage(), de);
      this.addFieldError(
          "editLDAPUserError",
          "Error in editing LDAP user. An email has been sent to the administrator");
      getUserService().sendEmailErrorReport();
      errorType = "error";
      return ERROR;
    }
  }