Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit e43d954b65d69ccfd0e7c641d4ab9bfc14ff99be 1 parent a82218c
Harry Brundage authored
View
6 Resources/app.js
@@ -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
View
48 Resources/app/controllers/accounts_controller.coffee
@@ -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
View
10 Resources/app/controllers/accounts_controller.js
@@ -39,8 +39,7 @@
return false;
}
this.selectWindow = (typeof this.selectWindow !== "undefined" && this.selectWindow !== null) ? this.selectWindow : new Citrus.NewAccountSelectWindow(this, __bind(function(type) {
- this.addNewAccountOfType(type);
- return this.selectWindow.win.close();
+ return this.addNewAccountOfType(type);
}, this));
Ti.API.debug(this.selectWindow.win);
return root.tabGroup.activeTab.open(this.selectWindow.win, {
@@ -56,11 +55,14 @@
}
if (typeof account !== "undefined" && account !== null) {
this.watchAccount(account);
- return account.authorize(__bind(function(account) {
+ account.authorize(__bind(function(account) {
+ this.selectWindow.win.close();
return account.synch();
}, this));
+ return account;
} else {
- return Ti.API.error("Couldn't create a new account of type " + type);
+ Ti.API.error("Couldn't create a new account of type " + type);
+ return null;
}
};
AccountsController.prototype.watchAccount = function(account) {
View
28 Resources/app/controllers/facebook_authorization_controller.coffee
@@ -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
View
40 Resources/app/controllers/facebook_authorization_controller.js
@@ -0,0 +1,40 @@
+(function() {
+ var FacebookAuthorizationController;
+ var __bind = function(func, context) {
+ return function(){ return func.apply(context, arguments); };
+ }, __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ Ti.include("/app/views/accounts/facebook_authorization_window.js");
+ FacebookAuthorizationController = function(onLoad, onError) {
+ FacebookAuthorizationController.__super__.constructor.apply(this, arguments);
+ d(Titanium.Facebook.loggedIn);
+ if (Titanium.Facebook.loggedIn) {
+ onLoad(Titanium.Facebook.session);
+ return null;
+ } else {
+ d("Not logged in to facebook yet, showing authorization window.");
+ }
+ this.window = new Citrus.FacebookAuthorizationWindow(this);
+ this.window.fbButton.addEventListener("login", __bind(function(e) {
+ return e.success ? onLoad(Titanium.Facebook.session) : onError(e);
+ }, this));
+ this.window.fbButton.addEventListener("cancel", __bind(function(e) {
+ return onError(e);
+ }, this));
+ root.tabGroup.activeTab.open(this.window.win, {
+ animated: true
+ });
+ return this;
+ };
+ __extends(FacebookAuthorizationController, Citrus.Controller);
+ FacebookAuthorizationController.prototype.destroy = function() {
+ return this.window.destroyAuthorizeUI();
+ };
+ Citrus.FacebookAuthorizationController = FacebookAuthorizationController;
+}).call(this);
View
33 Resources/app/models/accounts/facebook/facebook_account.coffee
@@ -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
View
34 Resources/app/models/accounts/facebook/facebook_account.js
@@ -8,10 +8,42 @@
if (typeof parent.extended === "function") parent.extended(child);
child.__super__ = parent.prototype;
};
+ Ti.include("/app/controllers/facebook_authorization_controller.js");
FacebookAccount = function() {
- return Citrus.Account.apply(this, arguments);
+ if (_.any(root.accountStore, function(a) {
+ return 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 FacebookAccount.__super__.constructor.apply(this, arguments);
+ }
+ return this;
};
__extends(FacebookAccount, Citrus.Account);
FacebookAccount.prototype.type = "FacebookAccount";
+ FacebookAccount.prototype.isAuthorized = function() {
+ return Ti.Facebook.isLoggedIn();
+ };
+ FacebookAccount.prototype.authorize = function(success) {
+ var controller, errorLoggingIn, loggedIn;
+ d("Starting facebook authorization");
+ loggedIn = function(session) {
+ d("Successfully logged in to facebook");
+ return d(session);
+ };
+ errorLoggingIn = function(e) {
+ er("Error logging in with facebook account!");
+ er(e);
+ er(Titanium.Facebook.session);
+ er(Titanium.Facebook.isLoggedIn());
+ return Titanium.Facebook.publishStream("Test status! Woooohooo", null, null, function(e) {
+ d("Trying to publish stream");
+ return d(e);
+ });
+ };
+ return (controller = new Citrus.FacebookAuthorizationController(loggedIn, errorLoggingIn));
+ };
Citrus.registerAccount(FacebookAccount);
}).call(this);
View
12 Resources/app/models/accounts/twitter/twitter_account.coffee
@@ -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) =>
View
8 Resources/app/models/accounts/twitter/twitter_account.js
@@ -51,12 +51,12 @@
TwitterAccount.prototype.isAuthorized = function() {
return this.consumer.isAuthorized();
};
- TwitterAccount.prototype.authorize = function(callback) {
+ TwitterAccount.prototype.authorize = function() {
TwitterAccount.__super__.authorize.apply(this, arguments);
- return Citrus.Config.TWITTER_XAUTH ? this.xAuthAuthorize(callback) : this.oAuthAuthorize(callback);
+ return Citrus.Config.TWITTER_XAUTH ? this.xAuthAuthorize() : this.oAuthAuthorize();
};
- TwitterAccount.prototype.xAuthAuthorize = function(callback) {};
- TwitterAccount.prototype.oAuthAuthorize = function(callback) {
+ TwitterAccount.prototype.xAuthAuthorize = function() {};
+ TwitterAccount.prototype.oAuthAuthorize = function() {
var controller, errorFindingPin, findPin, tokenError, tokenSuccess;
controller = {};
d("Starting OAuth Twitter Authorization");
View
34 Resources/app/views/accounts/facebook_authorization_window.coffee
@@ -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
View
45 Resources/app/views/accounts/facebook_authorization_window.js
@@ -0,0 +1,45 @@
+(function() {
+ var FacebookAuthorizationWindow;
+ var __extends = function(child, parent) {
+ var ctor = function(){};
+ ctor.prototype = parent.prototype;
+ child.prototype = new ctor();
+ child.prototype.constructor = child;
+ if (typeof parent.extended === "function") parent.extended(child);
+ child.__super__ = parent.prototype;
+ };
+ FacebookAuthorizationWindow = function(controller) {
+ FacebookAuthorizationWindow.__super__.constructor.apply(this, arguments);
+ this.win = Ti.UI.createWindow({
+ title: "Add Account",
+ backgroundColor: "#FFFFFF"
+ });
+ this.fbButton = Titanium.Facebook.createLoginButton({
+ style: 'wide',
+ apikey: Citrus.Config.FACEBOOK_API_KEY,
+ secret: Citrus.Config.FACEBOOK_APP_SECRET,
+ top: 130,
+ height: 30,
+ width: 300
+ });
+ this.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."
+ });
+ this.win.add(this.label);
+ this.win.add(this.fbButton);
+ return this;
+ };
+ __extends(FacebookAuthorizationWindow, Citrus.GenericWindow);
+ FacebookAuthorizationWindow.prototype.destroyAuthorizeUI = function() {
+ return this.win.close();
+ };
+ Citrus.FacebookAuthorizationWindow = FacebookAuthorizationWindow;
+}).call(this);
View
2  Resources/app/views/accounts/new_account_select_window.coffee
@@ -33,4 +33,4 @@ class NewAccountSelectWindow extends Citrus.GenericWindow
@win.add(@dashboard)
Ti.API.debug("Done creating select window")
-Citrus.NewAccountSelectWindow = NewAccountSelectWindow
+Citrus.NewAccountSelectWindow = NewAccountSelectWindow
View
13 Resources/app/views/splash/splash_window.coffee
@@ -89,26 +89,25 @@ class SplashWindow extends Citrus.GenericWindow
}
@win.add(@noticeLabel)
- unless @dataLabel?
- @dataLabel = Ti.UI.createLabel {
+ unless @dataView?
+ @dataView = Ti.UI.createWebView {
color:'#000'
- font:{fontSize:20, fontWeight:'bold'}
top:200
height:'auto'
width:300
- text: data
+ html: data
}
- @win.add(@dataLabel)
+ @win.add(@dataView)
@noticeLabel.show()
- @dataLabel.show()
+ @dataView.show()
# Hides the error label and retry button.
hideError: () ->
@win.remove @errorLabel if @errorLabel?
@win.remove @noticeLabel if @noticeLabel?
- @win.remove @dataLabel if @dataLabel?
+ @win.remove @dataView if @dataView?
@win.remove @goButton if @goButton?
@win.remove @retryButton if @retryButton?
View
18 Resources/app/views/splash/splash_window.js
@@ -112,22 +112,18 @@
});
this.win.add(this.noticeLabel);
}
- if (!(typeof (_ref = this.dataLabel) !== "undefined" && _ref !== null)) {
- this.dataLabel = Ti.UI.createLabel({
+ if (!(typeof (_ref = this.dataView) !== "undefined" && _ref !== null)) {
+ this.dataView = Ti.UI.createWebView({
color: '#000',
- font: {
- fontSize: 20,
- fontWeight: 'bold'
- },
top: 200,
height: 'auto',
width: 300,
- text: data
+ html: data
});
- this.win.add(this.dataLabel);
+ this.win.add(this.dataView);
}
this.noticeLabel.show();
- return this.dataLabel.show();
+ return this.dataView.show();
};
SplashWindow.prototype.hideError = function() {
var _ref;
@@ -137,8 +133,8 @@
if (typeof (_ref = this.noticeLabel) !== "undefined" && _ref !== null) {
this.win.remove(this.noticeLabel);
}
- if (typeof (_ref = this.dataLabel) !== "undefined" && _ref !== null) {
- this.win.remove(this.dataLabel);
+ if (typeof (_ref = this.dataView) !== "undefined" && _ref !== null) {
+ this.win.remove(this.dataView);
}
if (typeof (_ref = this.goButton) !== "undefined" && _ref !== null) {
this.win.remove(this.goButton);
Please sign in to comment.
Something went wrong with that request. Please try again.