Package org.eurekaj.api.datatypes.basic

Examples of org.eurekaj.api.datatypes.basic.BasicSession


              logger.info("userList: " + userList.size());
             
              if (userList.isEmpty()) {
                //No user, request registration
               
                BasicSession newSession = new BasicSession();
                newSession.setUuid(UUID.randomUUID().toString());
                newSession.setEmail(email);
                newSession.setExpiry(expiry);
                newSession.setAccountName("__NEW__");
               
                //userHash.put(newUser.getId(), newUser);
                logger.info("Persisting new Session: " + new Gson().toJson(newSession));
                getAccountService().persistSession(newSession);
               
                jsonResponse = "{ \"uuidToken\": \"" + newSession.getUuid() + "\", \"registered\": " + "false}";
              } else if (userList.size() == 1) {
                //One user with one account, return correct uuid
                User user = userList.get(0);
                //userHash.put(user.getId(), new BasicUser(user));
                logger.info("One User: " + new Gson().toJson(user));
             
                BasicSession newSession = new BasicSession();
                newSession.setUuid(UUID.randomUUID().toString());
                newSession.setEmail(email);
                newSession.setExpiry(expiry);
                newSession.setAccountName(user.getAccountName());
                getAccountService().persistSession(newSession);
               
                logger.info("Updating Session: " + new Gson().toJson(newSession));
               
              jsonResponse = "{ \"uuidToken\": \"" + newSession.getUuid() + "\", \"registered\": " + "true}";
               
              } else if (userList.size() > 1) {
                //One user with multiple accounts, return list of accounts
                jsonResponse = "{\"error\": \"not_yet_implemented\"}";
              }
             
            } else if (isPost(e) && uri.endsWith("/auth/register") && cookieUuidToken != null) {
              logger.info("isPost /auth/register. Cookie: " + cookieUuidToken);
              Session session = null;
              if (cookieUuidToken != null) {
                session = getAccountService().getSession(cookieUuidToken);
              }
             
              if (session != null) {
                BasicSession updatedSession = new BasicSession(session);
                BasicUser httpUser = ParseJsonObjects.parseUser(jsonObject);
               
                logger.info("HTTP user: " + new Gson().toJson(httpUser));
               
                updatedSession.setAccountName(httpUser.getAccountName());
                getAccountService().persistSession(updatedSession);
               
                logger.info("persisted new session: " + new Gson().toJson(updatedSession));
               
                BasicUser newUser = new BasicUser(httpUser);
                newUser.setUserRole("admin");
                newUser.setUserName(session.getEmail());
                getAccountService().persistUser(newUser);
               
                logger.info("persisted user: " + new Gson().toJson(newUser));
               
                BasicAccount newAccount = new BasicAccount();
                newAccount.setId(httpUser.getAccountName());
                newAccount.setAccountType("new");
               
                getAccountService().persistAccount(newAccount);
               
                jsonResponse = "{ \"registered\": " + "true, \"uuidToken\": \"" + updatedSession.getUuid() + "\"}";
              } else {
                jsonResponse = "{ \"registered\": " + "false}";
              }
             
              logger.info(jsonObject);
View Full Code Here


  }
 
  @Override
  public Session getSession(String uuid) {
    String json = asString(db.get(bytes(sessionBucketKey + uuid)));
    BasicSession session = gson.fromJson(json, BasicSession.class);
    return session;
  }
View Full Code Here

    return session;
  }
 
  @Override
  public void persistSession(Session session) {
    db.put(bytes(sessionBucketKey + session.getUuid()), bytes(gson.toJson(new BasicSession(session))));   
  }
View Full Code Here

  public void persistSession(Session session) {
    logger.info("persisting session: " + session.getUuid());
    Bucket myBucket = null;
        try {
          myBucket = riakClient.fetchBucket("Session").execute();
          myBucket.store(this.encodeUri(session.getUuid()), new BasicSession(session)).execute();
        } catch (RiakRetryFailedException rrfe) {
            rrfe.printStackTrace();
        }
  }
View Full Code Here

  }
 
  @Override
  public Session getSession(String uuid) {
    logger.info("getting session: " + uuid);
    BasicSession session = null;
   
    Bucket myBucket = null;
        try {
          myBucket = riakClient.fetchBucket("Session").execute();
            session = myBucket.fetch(this.encodeUri(uuid), BasicSession.class).execute();
View Full Code Here

TOP

Related Classes of org.eurekaj.api.datatypes.basic.BasicSession

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.