Exemplo n.º 1
0
 @Override
 public Value value(final QueryContext qc) throws QueryException {
   final ArrayList<User> users = qc.context.users.users(null, qc.context);
   final TokenList tl = new TokenList(users.size());
   for (final User user : users) tl.add(user.name());
   return StrSeq.get(tl);
 }
Exemplo n.º 2
0
  private User refUser(String name) {

    for (User user : users) {
      if (name.equals(user.name())) return user;
    }

    return null;
  }
Exemplo n.º 3
0
  /**
   * 사용자 정보 수정
   *
   * @return
   */
  @With(AnonymousCheckAction.class)
  @Transactional
  public static Result editUserInfo() {
    Form<User> userForm = new Form<>(User.class).bindFromRequest("name", "email");
    String newEmail = userForm.data().get("email");
    String newName = userForm.data().get("name");
    User user = UserApp.currentUser();

    if (StringUtils.isEmpty(newEmail)) {
      userForm.reject("email", "user.wrongEmail.alert");
    } else {
      if (!StringUtils.equals(user.email, newEmail) && User.isEmailExist(newEmail)) {
        userForm.reject("email", "user.email.duplicate");
      }
    }

    if (userForm.error("email") != null) {
      flash(Constants.WARNING, userForm.error("email").message());
      return badRequest(edit.render(userForm, user));
    }
    user.email = newEmail;
    user.name = newName;

    try {
      Long avatarId = Long.valueOf(userForm.data().get("avatarId"));
      if (avatarId != null) {
        Attachment attachment = Attachment.find.byId(avatarId);
        String primary = attachment.mimeType.split("/")[0].toLowerCase();

        if (attachment.size > AVATAR_FILE_LIMIT_SIZE) {
          userForm.reject("avatarId", "user.avatar.fileSizeAlert");
        }

        if (primary.equals("image")) {
          Attachment.deleteAll(currentUser().avatarAsResource());
          attachment.moveTo(currentUser().avatarAsResource());
        }
      }
    } catch (NumberFormatException ignored) {
    }

    Email.deleteOtherInvalidEmails(user.email);
    user.update();
    return redirect(
        routes.UserApp.userInfo(user.loginId, DEFAULT_GROUP, DAYS_AGO, DEFAULT_SELECTED_TAB));
  }
Exemplo n.º 4
0
  public static User create(final AuthUser authUser) {
    final User user = new User();
    user.roles =
        Collections.singletonList(SecurityRole.findByRoleName(controllers.Application.USER_ROLE));
    // user.permissions = new ArrayList<UserPermission>();
    // user.permissions.add(UserPermission.findByValue("printers.edit"));
    user.active = true;
    user.lastLogin = new Date();
    user.linkedAccounts = Collections.singletonList(LinkedAccount.create(authUser));

    if (authUser instanceof EmailIdentity) {
      final EmailIdentity identity = (EmailIdentity) authUser;
      // Remember, even when getting them from FB & Co., emails should be
      // verified within the application as a security breach there might
      // break your security as well!
      user.email = identity.getEmail();
      user.emailValidated = false;
    }

    if (authUser instanceof NameIdentity) {
      final NameIdentity identity = (NameIdentity) authUser;
      final String name = identity.getName();
      if (name != null) {
        user.name = name;
      }
    }

    if (authUser instanceof FirstLastNameIdentity) {
      final FirstLastNameIdentity identity = (FirstLastNameIdentity) authUser;
      final String firstName = identity.getFirstName();
      final String lastName = identity.getLastName();
      if (firstName != null) {
        user.firstName = firstName;
      }
      if (lastName != null) {
        user.lastName = lastName;
      }
    }

    MorphiaObject.datastore.save(user);

    // user.saveManyToManyAssociations("roles");
    // user.saveManyToManyAssociations("permissions");
    return user;
  }