Package org.beangle.ems.security

Examples of org.beangle.ems.security.User


public class HomeAction extends SecurityActionSupport {

  private MenuService menuService;
 
  public String index() {
    User user = entityDao.get(User.class, getUserId());
    Long categoryId = getUserCategoryId();
    put("categoryId", categoryId);
    MenuProfile profile = getMenuProfile(categoryId);
    if (null != profile) {
      put("menus", HierarchyEntityUtil.getRoots(menuService.getMenus(profile, user)));
View Full Code Here


    if (StringUtils.isEmpty(name) || StringUtils.isEmpty(email)) {
      addActionError("error.parameters.needed");
      return (ERROR);
    }
    List<User> userList = entityDao.get(User.class, "name", name);
    User user = null;
    if (userList.isEmpty()) {
      return goErrorWithMessage("error.user.notExist");
    } else {
      user = userList.get(0);
    }
    if (!StringUtils.equals(email, user.getMail())) {
      return goErrorWithMessage("error.email.notEqualToOrign");
    } else {
      String longinName = user.getName();
      String password = RandomStringUtils.randomNumeric(6);
      user.setRemark(password);
      user.setPassword(EncryptUtil.encode(password));
      String title = getText("user.password.sendmail.title");

      List<Object> values = CollectUtils.newArrayList();
      values.add(longinName);
      values.add(password);
      String body = getText("user.password.sendmail.body", values);
      try {
        SimpleMailMessage msg = new SimpleMailMessage(message);
        msg.setTo(user.getMail());
        msg.setSubject(title);
        msg.setText(body.toString());
        mailSender.send(msg);
      } catch (Exception e) {
        e.printStackTrace();
        logger.info("reset password error for user:" + user.getName() + " with email :"
            + user.getMail());
        return goErrorWithMessage("error.email.sendError");
      }
    }
    entityDao.saveOrUpdate(user);
    return forward("sendResult");
View Full Code Here

  public UserPropertyExtractor(TextResource textResource) {
    super(textResource);
  }

  public Object getPropertyValue(Object target, String property) throws Exception {
    User user = (User) target;
    if ("enabled".equals(property)) {
      boolean enabled = user.isEnabled();
      if (enabled) return getText("action.activate");
      else return getText("action.freeze");
    }
    if ("groups".equals(property)) {
      return getPropertyIn(user.getGroups(), "group.name");
    } else {
      return super.getPropertyValue(target, property);
    }
  }
View Full Code Here

    put("categories", entityDao.getAll(Category.class));
  }

  public String dashboard() {
    Long userId = getLong("user.id");
    User managed = null;
    if (null != userId) {
      managed = entityDao.get(User.class, userId);
    } else {
      String username = get("user.name");
      if (null != username) managed = userService.get(username);
    }
    User me = entityDao.get(User.class, getUserId());
    if (null != managed) {
      if (me.equals(managed) || userService.isManagedBy(me, managed)) {
        userDashboardHelper.buildDashboard(managed);
        return forward();
      } else {
        return forward(ERROR);
      }
View Full Code Here

    }
    return forward();
  }

  protected OqlBuilder<User> getQueryBuilder() {
    User manager = entityDao.get(User.class, getUserId());
    OqlBuilder<User> userQuery = OqlBuilder.from(getEntityName(), "user");
    // 查询用户组
    StringBuilder sb = new StringBuilder("exists(from user.groups ug where ");
    List<Object> params = CollectUtils.newArrayList();
    boolean queryGroup = false;
View Full Code Here

  /**
   * 保存用户信息
   */
  protected String saveAndForward(Entity<?> entity) {
    User user = (User) entity;
    if (entityDao.duplicate(User.class, user.getId(), "name", user.getName())) {
      addFlashMessageNow("security.error.usernameNotAvaliable", user.getName());
      return forward(new Action(this, "edit"));
    }
    String errorMsg = "";
    // // 收集用户身份
    String[] categories = StringUtils.split(get("categoryIds"), ",");
    user.getCategories().clear();
    for (int i = 0; i < categories.length; i++) {
      errorMsg = checkCategory(user, Long.valueOf(categories[i]));
      if (StringUtils.isNotEmpty(errorMsg)) { return forward(new Action("edit"), errorMsg); }
    }
    // 检验用户合法性
    errorMsg = checkUser(user);
    if (StringUtils.isNotEmpty(errorMsg)) { return forward(new Action("edit"), errorMsg); }
    processPassword(user);
    if (!user.isPersisted()) {
      User creator = userService.get(getUserId());
      userService.createUser(creator, user);
    } else {
      userService.saveOrUpdate(user);
    }
    updateUserGroup(user);
View Full Code Here

    for (GroupMember gm : userMembers) {
      memberMap.put(gm.getGroup(), gm);
    }
    Set<GroupMember> newMembers = CollectUtils.newHashSet();
    Set<GroupMember> removedMembers = CollectUtils.newHashSet();
    User manager = entityDao.get(User.class, getUserId());
    Collection<GroupMember> members = userService.getGroupMembers(manager, GroupMember.Ship.GRANTER);
    for (GroupMember member : members) {
      GroupMember myMember = memberMap.get(member.getGroup());
      boolean isMember = getBool("member" + member.getGroup().getId());
      boolean isGranter = getBool("granter" + member.getGroup().getId());
View Full Code Here

    }
    entityDao.execute(Operation.saveOrUpdate(newMembers).remove(removedMembers));
  }

  protected void editSetting(Entity<?> entity) {
    User user = (User) entity;
    User manager = entityDao.get(User.class, getUserId());
    Collection<GroupMember> members = userService.getGroupMembers(manager, GroupMember.Ship.GRANTER);
    Set<GroupMember> userMembers = user.getGroups();
    Map<Group, GroupMember> memberMap = CollectUtils.newHashMap();
    for (GroupMember gm : userMembers) {
      memberMap.put(gm.getGroup(), gm);
View Full Code Here

   *
   * @return
   */
  public String remove() {
    Long[] userIds = getEntityIds();
    User creator = userService.get(getUserId());
    List<User> toBeRemoved = userService.getUsers(userIds);
    StringBuilder sb = new StringBuilder();
    User removed = null;
    int success = 0;
    int expected = toBeRemoved.size();
    try {
      for (User one : toBeRemoved) {
        removed = one;
        // 不能删除自己
        if (!one.getId().equals(getUserId())) {
          userService.removeUser(creator, one);
          success++;
        } else {
          addFlashError("security.info.cannotRemoveSelf");
          expected--;
        }
      }
    } catch (Exception e) {
      sb.append(',').append(removed.getName());
    }
    if (sb.length() > 0) {
      sb.deleteCharAt(0);
      addFlashMessage("security.info.userRemovePartial", success, sb);
    } else if (expected == success && success > 0) {
View Full Code Here

   */
  public String activate() {
    Long[] userIds = getEntityIds();
    String isActivate = get("isActivate");
    int successCnt;
    User manager = userService.get(getUserId());
    String msg = "security.info.freeze.success";
    if (StringUtils.isNotEmpty(isActivate) && "false".equals(isActivate)) {
      successCnt = userService.updateState(manager, userIds, false);
    } else {
      msg = "security.info.activate.success";
View Full Code Here

TOP

Related Classes of org.beangle.ems.security.User

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.