appoxy_rails 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appoxy_sessions.rb +2 -0
- data/lib/sessions/oauth_token.rb +12 -0
- data/lib/sessions/sessions_controller.rb +90 -13
- data/lib/sessions/user.rb +5 -3
- data/lib/ui/binding_hack.rb +13 -13
- data/lib/ui/test.rb +7 -7
- metadata +21 -7
data/lib/appoxy_sessions.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'simple_record'
|
2
|
+
require 'oauth'
|
2
3
|
require_relative "sessions/user"
|
4
|
+
require_relative "sessions/oauth_token"
|
3
5
|
require_relative "sessions/application_controller"
|
4
6
|
require_relative "sessions/sessions_controller"
|
5
7
|
require_relative "sessions/users_controller"
|
@@ -33,7 +33,7 @@ module Appoxy
|
|
33
33
|
|
34
34
|
logout_keeping_session!
|
35
35
|
|
36
|
-
@email
|
36
|
+
@email = params[:email]
|
37
37
|
if @email.blank?
|
38
38
|
flash[:error] = "You must enter a valid email address."
|
39
39
|
render :action=>"new"
|
@@ -62,17 +62,10 @@ module Appoxy
|
|
62
62
|
# user = User.authenticate(@email, params[:password])
|
63
63
|
if user && user.authenticate(params[:password])
|
64
64
|
self.current_user = user
|
65
|
-
|
66
|
-
orig_url = session[:return_to]
|
67
|
-
puts 'orig_url = ' + orig_url.to_s
|
68
|
-
session[:return_to] = nil
|
69
|
-
if !orig_url.nil?
|
70
|
-
redirect_to orig_url # if entered via a different url
|
71
|
-
else
|
72
|
-
after_create
|
73
|
-
end
|
74
|
-
user.last_login = Time.now
|
65
|
+
user.last_login = Time.now
|
75
66
|
user.save(:dirty=>true)
|
67
|
+
flash[:info] = "Logged in successfully."
|
68
|
+
|
76
69
|
else
|
77
70
|
flash[:error] = "Invalid email or password. Please try again."
|
78
71
|
render :action => 'new'
|
@@ -85,7 +78,12 @@ module Appoxy
|
|
85
78
|
end
|
86
79
|
|
87
80
|
def after_create
|
88
|
-
|
81
|
+
orig_url = session[:return_to]
|
82
|
+
puts 'orig_url = ' + orig_url.to_s
|
83
|
+
session[:return_to] = nil
|
84
|
+
if !orig_url.nil?
|
85
|
+
redirect_to orig_url # if entered via a different url
|
86
|
+
end
|
89
87
|
end
|
90
88
|
|
91
89
|
def reset_password
|
@@ -187,12 +185,91 @@ module Appoxy
|
|
187
185
|
# @user.fake = false
|
188
186
|
@user.save(:dirty=>true)
|
189
187
|
end
|
190
|
-
|
188
|
+
|
189
|
+
set_current_user @user
|
191
190
|
@user
|
192
191
|
|
193
192
|
end
|
194
193
|
end
|
195
194
|
|
195
|
+
def twitter_auth
|
196
|
+
callback_url = "#{base_url}/sessions/create_twitter"
|
197
|
+
@request_token = twitter_oauth_consumer(:signin=>true).get_request_token(:oauth_callback => callback_url)
|
198
|
+
session[:request_token] = @request_token
|
199
|
+
ru = @request_token.authorize_url(:oauth_callback => callback_url)
|
200
|
+
puts ru.inspect
|
201
|
+
redirect_to ru
|
202
|
+
end
|
203
|
+
|
204
|
+
# OAUTH VERSION
|
205
|
+
def create_twitter_oauth
|
206
|
+
puts 'params=' + params.inspect
|
207
|
+
@request_token = session[:request_token]
|
208
|
+
@access_token = @request_token.get_access_token(:oauth_verifier => params[:oauth_verifier])
|
209
|
+
puts 'access_token = ' + @access_token.inspect
|
210
|
+
|
211
|
+
token = OauthToken.find_by_user_id_and_site_and_type(current_user.id, @access_token.consumer(:signin=>true).site, "access")
|
212
|
+
puts 'found token? ' + token.inspect
|
213
|
+
unless token
|
214
|
+
token = OauthToken.new(:type =>"access",
|
215
|
+
:user =>current_user,
|
216
|
+
:site =>@access_token.consumer.site,
|
217
|
+
:token =>@access_token.token,
|
218
|
+
:secret=>@access_token.secret)
|
219
|
+
token.save!
|
220
|
+
else
|
221
|
+
token.token = @access_token.token
|
222
|
+
token.secret = @access_token.secret
|
223
|
+
token.save(:dirty=>true)
|
224
|
+
end
|
225
|
+
@token = token
|
226
|
+
|
227
|
+
flash[:success] = "Authorized with Twitter."
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
def create_twitter
|
232
|
+
before_create
|
233
|
+
puts 'params=' + params.inspect
|
234
|
+
@request_token = session[:request_token]
|
235
|
+
@access_token = @request_token.get_access_token(:oauth_verifier => params[:oauth_verifier])
|
236
|
+
puts 'access_token = ' + @access_token.inspect
|
237
|
+
p @access_token.params
|
238
|
+
|
239
|
+
@user = User.find_by_twitter_id(@access_token.params[:user_id])
|
240
|
+
unless @user
|
241
|
+
@user = User.new(:username =>@access_token.params[:screen_name],
|
242
|
+
:twitter_screen_name=>@access_token.params[:screen_name],
|
243
|
+
:twitter_id =>@access_token.params[:user_id])
|
244
|
+
@user.save!
|
245
|
+
puts '@user=' + @user.inspect
|
246
|
+
else
|
247
|
+
@user.username = @access_token.params[:screen_name]
|
248
|
+
@user.save(:dirty=>true)
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
set_current_user @user
|
253
|
+
|
254
|
+
flash[:success] = "Authorized with Twitter."
|
255
|
+
|
256
|
+
after_create
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
private
|
261
|
+
def twitter_oauth_consumer(options={})
|
262
|
+
auth_path = options[:signin] ? "authenticate" : "authorize"
|
263
|
+
@consumer = OAuth::Consumer.new(Rails.application.config.twitter_consumer_key,
|
264
|
+
Rails.application.config.twitter_consumer_secret,
|
265
|
+
:site => "https://api.twitter.com",
|
266
|
+
:oauth_callback => "#{base_url}/sessions/#{(options[:signin] ? "create_twitter" : "create_twitter_oauth")}",
|
267
|
+
:request_token_path => "/oauth/request_token",
|
268
|
+
:authorize_path => "/oauth/#{auth_path}",
|
269
|
+
:access_token_path => "/oauth/access_token")
|
270
|
+
p @consumer
|
271
|
+
end
|
272
|
+
|
196
273
|
|
197
274
|
end
|
198
275
|
end
|
data/lib/sessions/user.rb
CHANGED
@@ -9,8 +9,10 @@ module Appoxy
|
|
9
9
|
end
|
10
10
|
|
11
11
|
has_strings :email,
|
12
|
+
:username,
|
12
13
|
:open_id,
|
13
|
-
:
|
14
|
+
:twitter_id, :twitter_screen_name,
|
15
|
+
:fb_id, :fb_access_token,
|
14
16
|
{:name => :password, :hashed=>true},
|
15
17
|
:first_name,
|
16
18
|
:last_name,
|
@@ -22,8 +24,8 @@ module Appoxy
|
|
22
24
|
:time_zone,
|
23
25
|
:lat, :lng
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
+
has_dates :last_login,
|
28
|
+
:remember_me_expires
|
27
29
|
|
28
30
|
|
29
31
|
def validate
|
data/lib/ui/binding_hack.rb
CHANGED
@@ -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
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 17
|
9
|
+
version: 0.0.17
|
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-02-
|
17
|
+
date: 2011-02-04 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: oauth
|
35
35
|
prerelease: false
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
type: :runtime
|
45
45
|
version_requirements: *id002
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: ruby-openid
|
48
48
|
prerelease: false
|
49
49
|
requirement: &id003 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
type: :runtime
|
58
58
|
version_requirements: *id003
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: appoxy_api
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id004 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
@@ -70,7 +70,7 @@ dependencies:
|
|
70
70
|
type: :runtime
|
71
71
|
version_requirements: *id004
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
73
|
+
name: mini_fb
|
74
74
|
prerelease: false
|
75
75
|
requirement: &id005 !ruby/object:Gem::Requirement
|
76
76
|
none: false
|
@@ -82,6 +82,19 @@ dependencies:
|
|
82
82
|
version: "0"
|
83
83
|
type: :runtime
|
84
84
|
version_requirements: *id005
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: simple_record
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
type: :runtime
|
97
|
+
version_requirements: *id006
|
85
98
|
description: Appoxy API Helper gem description...
|
86
99
|
email: travis@appoxy.com
|
87
100
|
executables: []
|
@@ -101,6 +114,7 @@ files:
|
|
101
114
|
- lib/appoxy_ui.rb
|
102
115
|
- lib/railtie.rb
|
103
116
|
- lib/sessions/application_controller.rb
|
117
|
+
- lib/sessions/oauth_token.rb
|
104
118
|
- lib/sessions/sessions_controller.rb
|
105
119
|
- lib/sessions/shareable.rb
|
106
120
|
- lib/sessions/user.rb
|