Package gotnames.dm

Examples of gotnames.dm.User


           final boolean disableEmail = cells.size() > 4 && Boolean.valueOf(strip(cells.get(4)).toLowerCase());
           final boolean admin = cells.size() > 5 && Boolean.valueOf(strip(cells.get(5)).toLowerCase());
          
           return new KTrans<User>(pm) {
            @Override protected User call() {
               User u = QueryBuilder.begin(pm, User.class).getSingleByField("email", email);
               if (u == null) {
                 u = User.newUser(groupKey);
                 u.setEmail(email);
               }
               u.setFirstName(firstName);
               u.setLastName(lastName);
               u.setGender(gender);
               u.setDisableEmail(disableEmail);
               u.setAdmin(admin);
              
               ProfilePictureData profilePicture = profilePics.get(u.getFullName());
               if (profilePicture != null)
                 u.setProfilePictureInfo(profilePicture);
              
               pm.makePersistent(u);
              
              msg.add("User saved: " + u.getFullName());
               return u;
            }
           }.go();
        }
       });
      
       for (User u : users) {
         // Update profile picture if present
        ProfilePicture.saveProfilePicture(u, pm, profilePics.get(u.getFullName()));
       }
     
      return rawStringUtf8("OK; updated " + rows.size() + " users\n\n" + Strings.join("\n", msg));
    } catch (IOException e) {
      return rawStringUtf8("Unable to read ZIP archive: " + e.getMessage());
View Full Code Here


      final ProfilePictureData profilePicture = ProfilePictureData.getProfilePicture(image.getImageData());
      ProfilePicture.saveProfilePicture(user, pm, profilePicture);
     
      userAuthenticator.userUpdated(new KTrans<User>(pm) {
        @Override protected User call() {
           User u = QueryBuilder.begin(pm, User.class).getSingleByKey(user.getKey());
           u.setProfilePictureInfo(profilePicture);
           return u;
        }
      }.go());
     
      return redirectToTask(EditProfileTask.class);
View Full Code Here

    final List<Pair<User, ProfilePictureData>> users = Funcs.map(Arrays.asList(PEOPLE), new Func<String[], Pair<User, ProfilePictureData>>() {
      private boolean first = true;
      @Override public Pair<User, ProfilePictureData> call(final String[] person) {
        return new KTrans<Pair<User, ProfilePictureData>>(pm) {
          @Override protected Pair<User, ProfilePictureData> call() {
            User u = User.newUser(groupKey);
            u.setFirstName(person[0]);
            u.setLastName(person[1]);
            u.setEmail(person[0].toLowerCase() + "@example.com");
            u.setGender(person[2].equals("m") ? Gender.MALE : Gender.FEMALE);
           
            if (first) {
              u.setAdmin(true);
              first = false;
            }

            try {
              URL url = new URL(person[3]);
              byte[] rawProfilePictureBytes = IOUtils.toByteArray(url.openStream());

              ProfilePictureData profilePicture = ProfilePictureData.getProfilePicture(rawProfilePictureBytes);
              u.setProfilePictureInfo(profilePicture);

              pm.makePersistent(u);

              return Pair.cons(u, profilePicture);
View Full Code Here

  void action(final User user, final Params p, PersistenceManager pm, UserAuthenticator userAuthenticator) {
    final String email = p.email();
   
    final ProfilePictureData profilePicture = ProfilePictureData.getProfilePicture(p.profilePicture());
   
    User u;
    if (email != null || profilePicture != null) {
      // save picture first
      ProfilePicture.saveProfilePicture(user, pm, profilePicture);
         
      u = new KTrans<User>(pm) {
        @Override protected User call() {
          User u = QueryBuilder.begin(pm, User.class).getSingleByKey(user.getKey());
          if (email != null) {
            User.checkCanSetEmail(pm, u, email);
           
            u.setEmail(email);
            u.setFirstName(Utils.notNull(p.firstName(), "First name is required"));
            u.setLastName(Utils.notNull(p.lastName(), "Last name is required"));
            u.setGender(Utils.notNull(p.gender(), "Gender is required"));
            u.setDisableEmail(p.disableEmail());
          }
          if (profilePicture != null)
            u.setProfilePictureInfo(profilePicture);
         
          pm.makePersistent(u);
          return u;
        }
      }.go();
      userAuthenticator.userUpdated(u);
    } else {
      u = user;
    }
   
    attr(Values.GENDER_OPTIONS, DropdownElement.fromEnum(Gender.class, u.getGender()));
    attr(Values.USER, u);
  }
View Full Code Here

      if (correctUserKeyStr == null)
        // Reached the end
        break;
     
      final Long correctUserKey = Long.valueOf(correctUserKeyStr);
      final User correctUser = userByKey.get(correctUserKey);
      if (correctUser == null)
        throw new IllegalStateException("Error in form, cannot find user with key " + correctUserKey);
     
      final String guessedFullName = dynamicInput.getInput(correctUserKeyStr, String.class);
      final boolean attemptGuess = guessedFullName != null;
      final boolean correctGuess;
     
      if (guessedFullName != null) {
        correctGuess = guessedFullName.equals(correctUser.getFullName());
        final Date now = Clock.now();
       
        new KTrans.Void(pm) {
          @Override protected void run() {
            Query query = pm.newQuery(Guess.class);
            query.setFilter(String.format("userKey == %s && correctUser == %s", user.getKey(), correctUserKey));
            Guess guess = CollUtils.getOneOrNull(Utils.<Collection<Guess>>cast(query.execute()));
            if (guess == null) {
              guess = new Guess();
              guess.setUserKey(user.getKey());
              guess.setCorrectUser(correctUserKey);
            } else {
              if (!Guess.guessAllowed(now, guess))
                throw new IllegalStateException("Error, user " + user.getFullName() + " is not currently allowed to guess on " + correctUser.getFullName());
            }
           
            guess.registerGuess(now, correctGuess);
           
            pm.makePersistent(guess);
View Full Code Here

        @Override public User make() {
          HttpSession session = rh.getSession();
         
          // check if there is an auth token
          String authToken = rh.getInput("t", String.class);
          User user;
          if (authToken != null) {
            PersistenceManager pm = PM_FACTORY.getPersistenceManager();
            user = attemptLogon(pm, session, authToken);
          } else {
            user = (User) session.getAttribute(USER_SESSION_KEY);
          }
         
          if (user == null)
            throw new NoAuthException();
          return user;
        }
      })
      .register(new UserAuthenticator() {
        @Override public boolean authenticate(String token) {
          User user = attemptLogon(PM_FACTORY.getPersistenceManager(), rh.getSession(), token);
          return user != null;
        }
        @Override public void userUpdated(User user) {
          rh.getSession().setAttribute(USER_SESSION_KEY, user);
        }
View Full Code Here

      })
    ;
  }
 
  private User attemptLogon(PersistenceManager pm, HttpSession session, String authToken) {
    final User user = QueryBuilder.begin(pm, User.class).getSingleByField("authToken", authToken);
    if (user == null)
      return null;
   
    new KTrans.Void(pm) {
      @Override protected void run() {
        user.setLastLogin(Clock.now());
        pm.makePersistent(user);
      }
    }.go();
   
    session.setAttribute(USER_SESSION_KEY, user);
View Full Code Here

    final ProfilePictureData profilePicture = ProfilePictureData.getProfilePicture(p.profilePicture());

    final String email = p.email();
    if (email != null) {
      // Check if the email is already in use
      User existingUser = User.getByEmail(pm, email);
      if (existingUser != null)
        return rawStringUtf8("Email address is already in use by user '" + existingUser.getFullName() + "'");
     
      User newUser = new KTrans<User>(pm) {
        @Override protected User call() {
          User u = User.newUser(user.getGroupKey());
         
          u.setEmail(email);
          u.setFirstName(Utils.notNull(p.firstName(), "First name is required"));
          u.setLastName(Utils.notNull(p.lastName(), "Last name is required"));
          u.setGender(Utils.notNull(p.gender(), "Gender is required"));
          u.setAdmin(p.admin());
          u.setDisableEmail(p.disableEmail());
         
          if (profilePicture != null)
            u.setProfilePictureInfo(profilePicture);
         
          pm.makePersistent(u);
          return u;
        }
      }.go();
View Full Code Here

    for (final User u : users) {
      final Long key = u.getKey();

      final String email = di.getInput(key + "_email", String.class);
      if (email != null) {
        User newLoggedInUser = new KTrans<User>(pm) {
          @Override protected User call() {
            User.checkCanSetEmail(pm, u, email);
           
            u.setEmail(email);
            u.setFirstName(Utils.notNull(di.getInput(key + "_firstName", String.class), "First name is required"));
View Full Code Here

      }.go();
     
      // create first admin user
      String authToken = new KTrans<String>(pm) {
        @Override protected String call() {
          User u = User.newUser(g.getKey());
         
          u.setEmail(email);
          u.setFirstName(Utils.notNull(p.firstName(), "First name is required"));
          u.setLastName(Utils.notNull(p.lastName(), "Last name is required"));
          u.setGender(Utils.notNull(p.gender(), "Gender is required"));
         
          u.setAdmin(true);
         
          pm.makePersistent(u);
         
          return u.getAuthToken();
        }
      }.go();
     
      // authenticate admin user
      userAuthenticator.authenticate(authToken);
View Full Code Here

TOP

Related Classes of gotnames.dm.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.