Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Skeleton of Dropbox connectivity.

  • Loading branch information...
commit adcaa5f6549012875a4aff4951d4548b960b1787 1 parent 32ee766
@akoprow akoprow authored
View
2  Makefile
@@ -1,6 +1,6 @@
NAME = webshell.exe
-SRC = parser.opa editor.opa webshell.opa login.opa fb_login.opa search.opa
+SRC = parser.opa editor.opa webshell.opa login.opa facebook.opa serach.opa dropbox.opa
SRCS = $(SRC:%=src/%)
all: $(NAME)
View
63 src/dropbox.opa
@@ -0,0 +1,63 @@
+// license: AGPL
+// (c) MLstate, 2012
+// author: Adam Koprowski
+
+import stdlib.apis.dropbox
+import stdlib.web.client
+
+database Dropbox.conf /dropbox_config
+
+module DropboxConnect {
+
+ private server config =
+ _ = CommandLine.filter(
+ { init: void
+ , parsers: [{ CommandLine.default_parser with
+ names: ["--dropbox-config"],
+ param_doc: "APP_KEY,APP_SECRET",
+ description: "Sets the application data for the associated Dropbox application",
+ function on_param(state) {
+ parser app_key=Rule.alphanum_string [,] app_secret=Rule.alphanum_string ->
+ {
+ /dropbox_config <- ~{app_key, app_secret}
+ {no_params: state}
+ }
+ }
+ }]
+ , anonymous: []
+ , title: "Dropbox configuration"
+ }
+ )
+ match (?/dropbox_config) {
+ case {some: config}: config
+ default:
+ Log.error("webshell[config]", "Cannot read Dropbox configuration (application key and/or secret key)
+Please re-run your application with: --dropbox-config option")
+ System.exit(1)
+ }
+
+ private DropboxOAuth = Dropbox(config).OAuth
+
+ private redirect = "http://localhost:8080"
+
+ exposed function connect() {
+ token = DropboxOAuth.get_request_token(redirect)
+ match (token) {
+ case {success: token}:
+ auth_url = DropboxOAuth.build_authorize_url(token.token, redirect)
+ Client.goto(auth_url)
+ default:
+ Log.error("Dropbox", "authorization failed")
+ }
+ }
+
+ xhtml =
+ WBootstrap.Button.make(
+ { button:
+ <span>Dropbox</>
+ , callback: function(_) { connect() }
+ },
+ []
+ )
+
+}
View
10 src/fb_login.opa → src/facebook.opa
@@ -6,14 +6,14 @@ import stdlib.apis.{facebook, facebook.auth, facebook.graph}
import stdlib.{web.client, system}
// FIXME should be abstract...
-type FbLogin.user =
+type FacebookConnect.user =
{ FbAuth.token token
, string name
}
database Facebook.config /facebook_config
-module FbLogin
+module FacebookConnect
{
server config =
@@ -32,14 +32,14 @@ module FbLogin
}
}]
, anonymous: []
- , title: "Webshell: Facebook configuration"
+ , title: "Facebook configuration"
}
)
match (?/facebook_config) {
case {some: config}: config
default:
Log.error("webshell[config]", "Cannot read Facebook configuration (application id and/or secret key)
-Please re-run your application with: --fb-config APP_ID,APP_SECRET")
+Please re-run your application with: --fb-config option")
System.exit(1)
}
@@ -72,7 +72,7 @@ Please re-run your application with: --fb-config APP_ID,APP_SECRET")
[]
)
- function User.t login(token) {
+ function Login.user login(token) {
match (FBA.get_token_raw(token, redirect)) {
case {~token}:
fb_user = { ~token, name: get_fb_name(token) }
View
4 src/login.opa
@@ -2,7 +2,7 @@
// (c) MLstate, 2011, 2012
// author: Adam Koprowski
-@abstract type Login.user = {guest} or {FbLogin.user fb_user}
+@abstract type Login.user = {guest} or {FacebookConnect.user fb_user}
module Login {
@@ -19,7 +19,7 @@ module Login {
function get_current_user_name() {
match (get_current_user()) {
case {guest}: "anonymous"
- case {~fb_user}: FbLogin.get_name(fb_user)
+ case {~fb_user}: FacebookConnect.get_name(fb_user)
}
}
View
6 src/webshell.opa
@@ -6,8 +6,6 @@
import stdlib.themes.bootstrap
import stdlib.widgets.bootstrap
-type User.t = {guest} or {FbLogin.user fb_user}
-
WB = WBootstrap
function focus(set) {
@@ -71,7 +69,7 @@ function login_box() {
}
login =
prompt = <a>You can sign in with:</>
- block(<>{prompt}{FbLogin.xhtml}</>)
+ block(<>{prompt}{FacebookConnect.xhtml}{DropboxConnect.xhtml}</>)
logout =
function do_logout(_) {
Login.set_current_user({guest})
@@ -115,7 +113,7 @@ function page() {
dispatcher = parser
| "/connect?" data=(.*) ->
{
- FbLogin.login(Text.to_string(data)) |> Login.set_current_user
+ FacebookConnect.login(Text.to_string(data)) |> Login.set_current_user
Resource.default_redirection_page("/")
}
| .* ->
Please sign in to comment.
Something went wrong with that request. Please try again.