Package org.opentides.bean.user

Examples of org.opentides.bean.user.BaseUser


    UserDAO userDAO = (UserDAO) getDao();
    if (userDAO.countAll() > 0)
      exist = true;
    else {
      // if none, let's create admin user
      BaseUser user = new BaseUser();
      UserCredential cred = new UserCredential();
      cred.setUsername("admin");
      cred.setPassword("ideyatech");
      cred.setEnabled(true);
      cred.setUser(user);
      user.setCredential(cred);
      user.setEmailAddress("admin@ideyatech.com");
      user.setFirstName("SuperAdmin");
      user.setLastName("User");

      // create usergroup for user
      UserGroup userGroup = new UserGroup();
      userGroup.setName("Super User");
      userGroup.setDescription("With all roles");

      // Let's super user role
      List<String> roleNames = new ArrayList<String>();
      roleNames.add("SUPER_USER");
      roleNames.add("ACCESS_ALL");
      userGroup.setRoleNames(roleNames);
      userGroupDAO.saveEntityModel(userGroup);

      user.addGroup(userGroup);
      userDAO.saveEntityModel(user);
      _log.info("New installation detected, inserted admin/ideyatech user to database.");
    }
    return !exist;
  }
View Full Code Here


  @Override
  public void updateLogin(
      AuthenticationSuccessEvent authenticationSuccessEvent) {
    UserDAO userDAO = (UserDAO) getDao();
    String username = authenticationSuccessEvent.getAuthentication().getName();
    BaseUser user = userDAO.loadByUsername(username);
    WebAuthenticationDetails details = (WebAuthenticationDetails) authenticationSuccessEvent.getAuthentication().getDetails();
    String address = details.getRemoteAddress();
    if (user.getTotalLoginCount()== null)
      user.setTotalLoginCount(1l);
    else
      user.setTotalLoginCount(user.getTotalLoginCount()+1);
    user.setPrevLoginIP(user.getLastLoginIP());
    user.setLastLoginIP(address);
    user.setLastLogin(new Date());
    user.setSkipAudit(true);   
    userDAO.saveEntityModel(user);
    // userDAO.updateLastLogin(username);

    // force the audit user details
    String completeName = user.getCompleteName() + " [" + username + "] ";
    user.setAuditUserId(user.getId());
    if (user.getOffice() != null)
      user.setAuditOfficeName(user.getOffice().getValue());
    user.setAuditUsername(username);
    user.setSkipAudit(false);
    String message = completeName + " has logged-in with IP: " + address;
    AuditLogDAOImpl.logEvent(message, message, user);

  }
View Full Code Here

      String username = sessionUser.getUsername();
      String completeName = sessionUser.getCompleteName() + " ["
          + username + "] ";
      UserDAO userDAO = (UserDAO) getDao();
      // also add log to audit history log
      BaseUser user = userDAO.loadByUsername(username);
      // force the audit user details
      user.setAuditUserId(user.getId());
      if (user.getOffice() != null)
        user.setAuditOfficeName(user.getOffice().getValue());
      user.setAuditUsername(username);
      String message = completeName + " has logged-out.";
      AuditLogDAOImpl.logEvent(message, message, user);
    }
  }
View Full Code Here

  public boolean supports(Class clazz) {
    return BaseUser.class.isAssignableFrom(clazz);
  }

  public void validate(Object object, Errors e) {
    BaseUser user = (BaseUser) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(e, "firstName",
        "error.required", new Object[]{"First Name"},"First name is required.");

    ValidationUtils.rejectIfEmptyOrWhitespace(e, "lastName",
        "error.required", new Object[]{"Last Name"},"Last name is required.");

    ValidationUtils.rejectIfEmptyOrWhitespace(e, "credential.username",
        "error.required", new Object[]{"Username"},"Username is required.");
    if (isDuplicateUsername(user)) {
      e.reject("error.duplicate-field", new Object[]{user.getCredential().getUsername(), "username"}, "User name already exists.");
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(e, "emailAddress",
        "error.required", new Object[]{"Email Address"},"Email address is required.");
    if (!ValidatorUtil.isEmail(user.getEmailAddress())) {
      e.rejectValue("emailAddress", "error.invalid-email-address",new Object[]{user.getEmailAddress()},"Email Address is invalid.");
    }
    if (isDuplicateEmail(user)) {
      e.reject("error.duplicate-field", new Object[]{user.getEmailAddress(),"email"}, "Email address already exists.");
    }

    if (user.getIsNew()) {
      ValidationUtils.rejectIfEmptyOrWhitespace(e, "credential.newPassword",
        "error.required", new Object[]{"Password"},"Password is required.");
      ValidationUtils.rejectIfEmptyOrWhitespace(e, "credential.confirmPassword",
        "error.required", new Object[]{"Confirm Password"},"Confirm password is required.");
    }
   
    if (!StringUtil.isEmpty(user.getCredential().getNewPassword()) &&
        !StringUtil.isEmpty(user.getCredential().getConfirmPassword()) &&
        !user.getCredential().getNewPassword().equals(user.getCredential().getConfirmPassword())) {
      e.reject("error.password-confirmation-did-not-match", "Password confirmation did not match.");
    }
  }
View Full Code Here

   * @return boolean return true if duplicate username was found, false otherwise.
   */
  private boolean isDuplicateUsername(BaseUser user) {
    String userName = user.getCredential().getUsername();
    if (userName != null && !StringUtil.isEmpty(userName)){
      BaseUser userCheck = userDAO.loadByUsername(userName);
      if (userCheck != null && user.isNew())
        return true;   
      if (userCheck != null && !userCheck.getId().equals(user.getId()))
        return true;
    }
    return false;
  }
View Full Code Here

   * @return boolean returns true if duplicate email was found, false otherwise.
   */
  private boolean isDuplicateEmail(BaseUser user) {
    String email = user.getEmailAddress();
    if (email != null && !StringUtil.isEmpty(email)){
      BaseUser userCheck = userDAO.loadByEmailAddress(email);
      if (userCheck != null && user.isNew())
        return true;     
      if (userCheck != null && !userCheck.getId().equals(user.getId()))
        return true;
    }
    return false;
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.opentides.service.UserWidgetsService#addUserWidgets(long, java.lang.String)
   */
  public void addUserWidgets(long userId, String selectedWidgets) {
    String[] widgetIds = selectedWidgets.split(",");
    BaseUser user = userService.load(SecurityUtil.getSessionUser().getRealId());
    for (String widgetId:widgetIds) {
     
      int[] pos = getColumnRowOfUserWidget(userId);
     
      Widget widget = widgetService.load(widgetId);
View Full Code Here

  public void addUserWidgets(long userId, Widget widget) {
    /* Steps in adding user widget on dashboard
     * 1. Find the column and row where we're going to add the widget
     * 2. Add the widget
     */
    BaseUser user = userService.load(userId);
   
    int[] pos = getColumnRowOfUserWidget(userId);
   
    UserWidgets userWidget = new UserWidgets();
    userWidget.setUser(user);
View Full Code Here

      }
    }
  }
 
  public static void main(String[] args) {
    BaseUser bu = new BaseUser();
    CrudUtil.setObjectValue(bu, "credential.username", "username");
    System.out.println(bu.getCredential().getUsername());
  }
View Full Code Here

TOP

Related Classes of org.opentides.bean.user.BaseUser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.