コード例 #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);
  }
コード例 #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;
  }
コード例 #3
0
  public void merge(final User otherUser) {
    for (final LinkedAccount acc : otherUser.linkedAccounts) {
      this.linkedAccounts.add(LinkedAccount.create(acc));
    }
    // do all other merging stuff here - like resources, etc.

    // deactivate the merged user that got added to this one
    otherUser.active = false;
    MorphiaObject.datastore.save(otherUser);
    MorphiaObject.datastore.save(this);
  }
コード例 #4
0
 public static void setLastLoginDate(final AuthUser knownUser) {
   final User u = User.findByAuthUserIdentity(knownUser);
   u.lastLogin = new Date();
   MorphiaObject.datastore.save(u);
 }
コード例 #5
0
 public static void addLinkedAccount(final AuthUser oldUser, final AuthUser newUser) {
   final User u = User.findByAuthUserIdentity(oldUser);
   u.linkedAccounts.add(LinkedAccount.create(newUser));
   MorphiaObject.datastore.save(u);
 }
コード例 #6
0
 public static void merge(final AuthUser oldUser, final AuthUser newUser) {
   User.findByAuthUserIdentity(oldUser).merge(User.findByAuthUserIdentity(newUser));
 }