Permalink
Browse files

- Removed unused twitter authorization callbacks

- Added basic facebook auth, almost working!

Broken state right now! Don't check this out.
  • Loading branch information...
1 parent a82218c commit e43d954b65d69ccfd0e7c641d4ab9bfc14ff99be Harry Brundage committed Nov 11, 2010
View
@@ -12,7 +12,9 @@ Citrus.Config = {
REMOTE_URL: "http://localhost:3000/",
SHORTENER_PREFIX: "s/",
SHORTCODE_RE: "s/([a-zA-Z0-9]+)",
- TWITTER_XAUTH: false
+ TWITTER_XAUTH: false,
+ FACEBOOK_API_KEY: "965a3c93faaea82715520e175d983b58",
+ FACEBOOK_APP_SECRET: "4b4fefb799217cdfd60ba81098291d8c"
};
// Debugging functions
@@ -26,7 +28,7 @@ var e = function() {
Titanium.API.error(arguments[i]);
}
};
-
+var er = e; // Used when e is taken in the local scope
//Ti.App.Properties.setString("CitrusAccounts","")
// Application level requires
// Underscore JS
@@ -11,16 +11,16 @@ class AccountsController extends Citrus.Controller
# Creates the window
constructor: (store) ->
@store = store
-
+
for account in @store.accounts
this.watchAccount(account)
@window = new Citrus.AccountsTableViewWindow(this, @store.accounts)
- setTimeout( ->
- root.fireEvent("synch:start", {source: "accounts controller"})
+ setTimeout( ->
+ root.fireEvent("synch:start", {source: "accounts controller"})
, 500)
-
+
# Callback called when add new account button is pressed. Creates an account, watches it, and starts it along its
# authorization path.
addNewAccount: ->
@@ -30,39 +30,45 @@ class AccountsController extends Citrus.Controller
@selectWindow ?= new Citrus.NewAccountSelectWindow this, (type) =>
this.addNewAccountOfType(type)
- @selectWindow.win.close()
-
+
Ti.API.debug(@selectWindow.win)
-
- root.tabGroup.activeTab.open @selectWindow.win, {animated:true}
-
+
+ root.tabGroup.activeTab.open @selectWindow.win, {animated:true}
+
# Calledback from the NewAccountSelectWindow
+ # Returns true or false based on the instantiation of the account,
+ # not the authorization.
addNewAccountOfType: (type) ->
if _.isFunction(type)
account = new type()
else
account = new Citrus[type]()
-
+
if account?
- this.watchAccount(account)
- account.authorize( (account) => account.synch() )
+ this.watchAccount(account)
+ account.authorize (account) =>
+ @selectWindow.win.close()
+ account.synch()
+
+ return account
else
Ti.API.error("Couldn't create a new account of type "+type)
-
- # Called on each account to set up event listeners
+ return null
+
+ # Called on each account to set up event listeners
watchAccount: (account) ->
return true if _.include(@watchedAccounts, account)
@watchedAccounts.push account
-
+
account.addEventListener "authorization:error", (e) =>
Ti.API.debug("Authorization Error!")
#Ti.API.debug(e)
alert("There was an error authorizing your account. Please try again.")
-
+
# Called when a row is loading it's information
account.addEventListener "state:updating", (e) =>
@window.showLoading()
-
+
# Called when row is first ready to show and when it updates.
account.addEventListener "state:ready", (e) =>
if account.displayed? && account.displayed
@@ -72,15 +78,15 @@ class AccountsController extends Citrus.Controller
@window.displayAccount(account)
@window.hideLoading()
-
+
# Called if row has error loading
account.addEventListener "state:error", (e) =>
@window.hideLoading()
alert("There was an error retrieving your details from Twitter. Please try again.")
-
+
account.addEventListener "state:deleted", (e) =>
@store.removeAccount(account)
delete account
delete e.row.wrapper
-
-Citrus.AccountsController = AccountsController
+
+Citrus.AccountsController = AccountsController

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,28 @@
+Ti.include("/app/views/accounts/facebook_authorization_window.js")
+
+class FacebookAuthorizationController extends Citrus.Controller
+ constructor: (onLoad, onError) ->
+ super
+ d(Titanium.Facebook.loggedIn)
+ if Titanium.Facebook.loggedIn
+ onLoad(Titanium.Facebook.session)
+ return
+ else
+ d("Not logged in to facebook yet, showing authorization window.")
+
+ @window = new Citrus.FacebookAuthorizationWindow(this)
+ @window.fbButton.addEventListener "login",(e) =>
+ if e.success
+ onLoad(Titanium.Facebook.session)
+ else
+ onError(e)
+
+ @window.fbButton.addEventListener "cancel", (e) =>
+ onError(e)
+
+ root.tabGroup.activeTab.open @window.win, {animated:true}
+
+ destroy: ->
+ @window.destroyAuthorizeUI()
+
+Citrus.FacebookAuthorizationController = FacebookAuthorizationController

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,3 +1,34 @@
+Ti.include("/app/controllers/facebook_authorization_controller.js")
+
class FacebookAccount extends Citrus.Account
type: "FacebookAccount"
-Citrus.registerAccount FacebookAccount
+ constructor: () ->
+ # Hack for only one facebook account while the titanium module is in use.
+ if _.any(root.accountStore, (a) -> a.type == "FacebookAccount")
+ d("Trying to create a second Facebook account. No can do at the moment.")
+ alert("Multiple Facebook accounts aren't supported right now, sorry!")
+ return null
+ else
+ return super
+
+ isAuthorized: () ->
+ Ti.Facebook.isLoggedIn()
+
+ authorize: (success) ->
+ d("Starting facebook authorization")
+ loggedIn = (session) ->
+ d("Successfully logged in to facebook")
+ d(session)
+ errorLoggingIn = (e) ->
+ er("Error logging in with facebook account!")
+ er(e)
+ er(Titanium.Facebook.session)
+ er(Titanium.Facebook.isLoggedIn())
+ Titanium.Facebook.publishStream("Test status! Woooohooo", null, null, (e) ->
+ d("Trying to publish stream")
+ d(e)
+ )
+
+ controller = new Citrus.FacebookAuthorizationController(loggedIn, errorLoggingIn)
+
+Citrus.registerAccount FacebookAccount

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,5 +1,5 @@
Ti.include('/app/controllers/oauthorization_controller.js')
-Ti.include('/vendor/spazcore/libs/spaztwit.js');
+Ti.include('/vendor/spazcore/libs/spaztwit.js')
class TwitterAccount extends Citrus.Account
type: "TwitterAccount"
@@ -39,16 +39,16 @@ class TwitterAccount extends Citrus.Account
isAuthorized: ->
return @consumer.isAuthorized()
- authorize: (callback) ->
+ authorize: ->
super
if Citrus.Config.TWITTER_XAUTH
- this.xAuthAuthorize(callback)
+ this.xAuthAuthorize()
else
- this.oAuthAuthorize(callback)
+ this.oAuthAuthorize()
- xAuthAuthorize: (callback) ->
+ xAuthAuthorize: () ->
- oAuthAuthorize: (callback) ->
+ oAuthAuthorize: () ->
controller = {}
d("Starting OAuth Twitter Authorization")
this.addEventListener "authorization:error", (e) =>

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,34 @@
+class FacebookAuthorizationWindow extends Citrus.GenericWindow
+ constructor: (controller) ->
+ super
+ @win = Ti.UI.createWindow {
+ title: "Add Account"
+ backgroundColor: "#FFFFFF"
+ }
+
+ @fbButton = Titanium.Facebook.createLoginButton({
+ style:'wide'
+ apikey: Citrus.Config.FACEBOOK_API_KEY
+ secret: Citrus.Config.FACEBOOK_APP_SECRET
+ # sessionProxy:'http://api.appcelerator.net/p/fbconnect/'
+ top:130
+ height:30
+ width:300
+ })
+
+ @label = Titanium.UI.createLabel {
+ color:'#000'
+ font:{fontSize:16, fontWeight:'bold'}
+ top:50
+ height:'auto'
+ width:300
+ text: "Click the Connect with Facebook button below to add your Facebook account to Citrus."
+ }
+
+ @win.add(@label)
+ @win.add(@fbButton)
+
+ destroyAuthorizeUI: () ->
+ @win.close()
+
+Citrus.FacebookAuthorizationWindow = FacebookAuthorizationWindow
Oops, something went wrong.

0 comments on commit e43d954

Please sign in to comment.