Esempio n. 1
0
  public static void verify(final User unverified) {
    // You might want to wrap this into a transaction
    unverified.emailValidated = true;
    MorphiaObject.datastore.save(unverified);

    TokenAction.deleteByUser(unverified, Type.EMAIL_VERIFICATION);
  }
Esempio n. 2
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;
  }