appoxy_rails 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,12 +5,16 @@ module Appoxy
5
5
 
6
6
  def self.included(base)
7
7
  # Initialize module.
8
+ puts 'ApplicationController included.'
8
9
  base.helper_method :logged_in?
9
10
  base.helper_method :current_user
10
11
  base.helper_method :base_url
11
12
 
12
13
  base.after_filter :close_sdb_connection
13
14
  base.before_filter :clear_sdb_stats
15
+
16
+ base.helper_method :facebook_oauth_url
17
+
14
18
  end
15
19
 
16
20
 
@@ -106,6 +110,19 @@ module Appoxy
106
110
 
107
111
  end
108
112
 
113
+
114
+
115
+ def facebook_oauth_url(options={})
116
+ puts 'appconfig==' + Rails.application.config.inspect
117
+ raise "Scope must be specified." unless options[:scope]
118
+ app_id = Rails.application.config.facebook_app_id
119
+ if app_id
120
+ @facebook_oauth_url = MiniFB.oauth_url(app_id,
121
+ "#{base_url}/sessions/create_facebook", # redirect url
122
+ :scope=>options[:scope].join(","))
123
+ end
124
+ end
125
+
109
126
  MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
110
127
  'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
111
128
  'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
@@ -2,10 +2,21 @@ module Appoxy
2
2
 
3
3
  module Sessions
4
4
 
5
+ #
6
+ # logout_session_path
5
7
  module SessionsController
6
8
 
7
- # Todo: have a configuration block for this so user can set things like facebook_api_key and facebook_secret
9
+ require 'openid/store/filesystem'
10
+ require 'openid/extensions/ax'
11
+
8
12
 
13
+ def self.included(base)
14
+ puts 'SessionsController included'
15
+ # base.helper_method :facebook_oauth_url
16
+
17
+ end
18
+
19
+ # Todo: have a configuration block for this so user can set things like facebook_api_key and facebook_secret
9
20
  def new
10
21
 
11
22
  end
@@ -105,14 +116,70 @@ module Appoxy
105
116
  end
106
117
 
107
118
  def destroy
108
- logout
109
- end
110
-
111
- def logout
112
119
  @current_user = nil
113
120
  reset_session
114
121
  flash[:info] = "You have been logged out."
115
- redirect_to('/')
122
+ redirect_to root_url
123
+ end
124
+
125
+ def logout
126
+ destroy
127
+ end
128
+
129
+
130
+ def create_facebook
131
+ if facebook_auth(Rails.application.config.facebook_app_id,
132
+ Rails.application.config.facebook_secret)
133
+ after_create
134
+
135
+ end
136
+ end
137
+
138
+ def facebook_auth(app_id, app_secret, options={})
139
+ p params
140
+ redirect_uri = options[:redirect_uri] || "#{base_url}/sessions/create_facebook"
141
+ code = params['code'] # Facebooks verification string
142
+ if code
143
+ access_token_hash = MiniFB.oauth_access_token(app_id,
144
+ redirect_uri,
145
+ app_secret,
146
+ code)
147
+ # p access_token_hash
148
+ @access_token = access_token_hash["access_token"]
149
+ unless @access_token
150
+ flash[:warning] = "Authentication did not work, no access_token"
151
+ redirect_to :action=>"new"
152
+ return
153
+ end
154
+
155
+ session[:access_token] = @access_token
156
+
157
+ me = MiniFB.get(@access_token, "me")
158
+ puts 'me=' + me.inspect
159
+ @user = User.find_by_fb_id(me.id)
160
+ new_user = @user.nil?
161
+ if new_user
162
+ @user = User.create(:fb_id =>me.id,
163
+ :email =>me.email,
164
+ :first_name =>me.first_name,
165
+ :last_name =>me.last_name,
166
+ :fb_access_token=>@access_token,
167
+ :status =>"active")
168
+
169
+
170
+ else
171
+ @user.email = me.email
172
+ @user.fb_access_token = @access_token
173
+ @user.first_name = me.first_name
174
+ @user.last_name = me.last_name
175
+ @user.status = "active"
176
+ # @user.fake = false
177
+ @user.save(:dirty=>true)
178
+ end
179
+ session[:user_id] = @user.id
180
+ @user
181
+
182
+ end
116
183
  end
117
184
 
118
185
 
@@ -60,8 +60,12 @@ module Appoxy
60
60
  end
61
61
 
62
62
  if defined?(RELEASE_INFO)
63
- ret += '<div style="clear:both; margin-top:15px;" class="instance_info_div"><%= INSTANCE_INFO["instance_id"] %>: Revision <%= RELEASE_INFO["scm"]["revision"][0..5] %> built on <%= RELEASE_INFO["deploy_date"] %></div>'
63
+ ret += '<div style="clear:both; margin-top:15px;"
64
+ class="instance_info_div">' + INSTANCE_INFO["instance_id"] + ':
65
+ Revision ' + RELEASE_INFO["scm"]["revision"][0..5] + ' built on ' +
66
+ RELEASE_INFO["deploy_date"] + '</div>'
64
67
  end
68
+
65
69
  if Rails.env == "development"
66
70
  ret += '<div style="margin-top: 10px;">' + ERB::Util.html_escape(SimpleRecord.stats.inspect) + '</div>'
67
71
  end
@@ -1,14 +1,14 @@
1
- module Appoxy
2
- module UI
3
- class BindingHack
4
-
5
- def initialize(hash)
6
- @options = hash
7
- end
8
-
9
- def get_binding
10
- binding
11
- end
12
- end
13
- end
1
+ module Appoxy
2
+ module UI
3
+ class BindingHack
4
+
5
+ def initialize(hash)
6
+ @options = hash
7
+ end
8
+
9
+ def get_binding
10
+ binding
11
+ end
12
+ end
13
+ end
14
14
  end
data/lib/ui/test.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'erb'
2
- require_relative 'binding_hack'
3
-
4
- options = Appoxy::UI::BindingHack.new(:x=>"hi")
5
- template = ERB.new(File.read(File.join(File.dirname(__FILE__), '_geo_location_finder.html.erb')))
6
- ret = template.result(options.get_binding)
7
- p ret
1
+ require 'erb'
2
+ require_relative 'binding_hack'
3
+
4
+ options = Appoxy::UI::BindingHack.new(:x=>"hi")
5
+ template = ERB.new(File.read(File.join(File.dirname(__FILE__), '_geo_location_finder.html.erb')))
6
+ ret = template.result(options.get_binding)
7
+ p ret
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 12
9
- version: 0.0.12
8
+ - 13
9
+ version: 0.0.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Travis Reeder
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-27 00:00:00 -08:00
17
+ date: 2011-01-29 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency