Esempio n. 1
0
 public static void sendModeration(String name, float point) {
   Task t = new Task(name, point);
   t.status = TaskStatus.PENDING;
   t.suggestedBy = SUser.findByEmail(Auth.connected());
   t.save();
   thanks();
 }
Esempio n. 2
0
  private void handleSocketClosed(SockJSSocket sock, Map<String, Handler<Message>> handlers) {
    // On close unregister any handlers that haven't been unregistered
    for (Map.Entry<String, Handler<Message>> entry : handlers.entrySet()) {
      // call hook
      handleUnregister(sock, entry.getKey());
      eb.unregisterHandler(entry.getKey(), entry.getValue());
    }

    // Close any cached authorisations for this connection
    Set<String> auths = sockAuths.remove(sock);
    if (auths != null) {
      for (String sessionID : auths) {
        Auth auth = authCache.remove(sessionID);
        if (auth != null) {
          auth.cancel();
        }
      }
    }
    handleSocketClosed(sock);
  }
  public void setup() {
    Auth.setupTable(PERMISSIONS_CF, PERMISSIONS_CF_SCHEMA);

    try {
      String query =
          String.format(
              "SELECT permissions FROM %s.%s WHERE username = ? AND resource = ?",
              Auth.AUTH_KS, PERMISSIONS_CF);
      authorizeStatement =
          (SelectStatement) QueryProcessor.parseStatement(query).prepare().statement;
    } catch (RequestValidationException e) {
      throw new AssertionError(e); // not supposed to happen
    }
  }
Esempio n. 4
0
  // FLICKR AUTHENTICATION HELPER FUNCTIONS
  // Attempts to authneticate with a given token
  public void authenticateWithToken(String _token) {
    AuthInterface authInterface = flickr.getAuthInterface();

    // make sure the token is legit
    try {
      authInterface.checkToken(_token);
    } catch (Exception e) {
      println("Token is bad, getting a new one");
      getAuthentication();
      return;
    }

    auth = new Auth();

    RequestContext requestContext = RequestContext.getRequestContext();
    requestContext.setSharedSecret(secretKey);
    requestContext.setAuth(auth);

    auth.setToken(_token);
    auth.setPermission(Permission.WRITE);
    flickr.setAuth(auth);
    println("Authentication success");
  }
Esempio n. 5
0
 public static void fbLogin() {
   String token = params.get("token");
   if (null != token && !token.isEmpty()) {
     FacebookClient fb = new DefaultFacebookClient(token);
     User fbUser = fb.fetchObject("me", User.class);
     Logger.info("Facebook User:"******"Such a user does not exists. Create/Register one...");
       // Register a new...
       // Email uniqueness is controlled by Facebook I suppose, so no need to check on our side...
       sesUser = new SUser(fbUser.getName(), fbUser.getEmail());
       sesUser.fbId = fbUser.getId();
       sesUser.save();
     }
     Auth.fbLogin(token, sesUser);
   } else {
     redirect("/");
   }
 }
Esempio n. 6
0
  // Goes online to get user authentication from Flickr.
  public void getAuthentication() {
    AuthInterface authInterface = flickr.getAuthInterface();

    try {
      frob = authInterface.getFrob();
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob);

      // open the authentication URL in a browser
      open(authURL.toExternalForm());
    } catch (Exception e) {
      e.printStackTrace();
    }

    println("You have 15 seconds to approve the app!");
    int startedWaiting = millis();
    int waitDuration = 15 * 1000; // wait 10 seconds
    while ((millis() - startedWaiting) < waitDuration) {
      // just wait
    }
    println("Done waiting");

    try {
      auth = authInterface.getToken(frob);
      println("Authentication success");
      // This token can be used until the user revokes it.
      token = auth.getToken();
      // save it for future use
      saveToken(token);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // complete authentication
    authenticateWithToken(token);
  }