コード例 #1
0
  private void customRoomLogin(ISFSEvent event) throws SFSLoginException {
    trace("Game Login by session");

    DBCollection users = AuthorizeExtension.users;

    BasicDBObject query = new BasicDBObject();
    query.put("session", generateSession);

    DBCursor cursor = users.find(query);

    if (!cursor.hasNext()) {
      trace("Game Login User not found!", generateSession);
      SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
      data.addParameter(userName);

      throw new SFSLoginException("Login failed for user: "******"Game Login User logged in!", generateSession);
      document = cursor.next();

      ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
      outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, document.get("nickname").toString());

      Boolean isGuest = (Boolean) document.get("is_guest");
      if (isGuest == null) {
        isRegistered = true;
      } else {
        isRegistered = false;
      }
    }
  }
コード例 #2
0
  private void handleUser(ISFSEvent event) {
    trace("Registered user logged in", userName);

    DBCollection users = AuthorizeExtension.users;

    BasicDBObject query = new BasicDBObject();
    query.put("email", userName);

    DBCursor cursor = users.find(query);

    if (!cursor.hasNext()) {
      trace("user not found");
      return;
    }

    document = cursor.next();

    String password_digest = (String) document.get("password_digest");

    if (!getApi().checkSecurePassword(session, password_digest, cryptedPass)) {
      trace("password wrong");
      return;
    }

    document.put("session", generateSession);
    users.update(query, document);

    isRegistered = true;
  }
コード例 #3
0
  private void handleGuest(ISFSEvent event) throws NoSuchElementException {
    trace("Guest is loggin in", userName);

    DBCollection users = AuthorizeExtension.users;

    // Create random num 0..99
    Random randomGenerator = new Random();
    userName = userName + randomGenerator.nextInt(100);

    // Set new Name
    ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
    outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, userName);

    // Insert DB
    BasicDBObject newUser = new BasicDBObject();
    newUser.put("nickname", userName);
    newUser.put("session", generateSession);
    newUser.put("is_guest", true);

    users.insert(newUser);

    isRegistered = false;
  }