Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

remote_key -> OAuth migration support.

  • Loading branch information...
commit a83c0b1846aaf8fbae6edee4844e985dadad5da6 1 parent f2847fe
Hiroshi Nakamura authored July 29, 2009
9  app/controllers/entry_controller.rb
@@ -339,7 +339,6 @@ def new
339 339
     @body = param(:body)
340 340
     @link = param(:link)
341 341
     @with_form = param(:with_form)
342  
-    @file = nil
343 342
     @title = param(:title)
344 343
     @lat = param(:lat)
345 344
     @long = param(:long)
@@ -429,7 +428,7 @@ def add
429 428
     @link = param(:link)
430 429
     @link_title = param(:link_title)
431 430
     @with_form = param(:with_form)
432  
-    @file = param(:file)
  431
+    file = param(:file)
433 432
     @reshared_from = param(:reshared_from)
434 433
     @title = param(:title)
435 434
     @lat = param(:lat)
@@ -460,7 +459,7 @@ def add
460 459
       generator = GoogleMaps::URLGenerator.new
461 460
       image_link = generator.link_url(@lat, @long, @address)
462 461
       @body += " ([map] #{@address})"
463  
-      if !@link and !@file
  462
+      if !@link and !file
464 463
         opt[:link] = image_link
465 464
       end
466 465
     end
@@ -475,8 +474,8 @@ def add
475 474
     elsif @body
476 475
       opt[:body] = @body
477 476
     end
478  
-    if @file
479  
-      (opt[:file] ||= []) << @file
  477
+    if file
  478
+      (opt[:file] ||= []) << file
480 479
     end
481 480
     unless opt[:body]
482 481
       @feedinfo = User.ff_feedinfo(auth, auth.name)
8  app/helpers/application_helper.rb
@@ -44,6 +44,7 @@ module ApplicationHelper
44 44
     'group' => 'group.png',
45 45
     'private' => 'lock.png',
46 46
     'hide' => 'sound_mute.png',
  47
+    'shield' => 'shield.png',
47 48
   }
48 49
   OAUTH_IMAGE_URL = 'http://friendfeed.com/static/images/sign-in-with-friendfeed.png'
49 50
 
@@ -169,7 +170,12 @@ def oauth_image_tag
169 170
   end
170 171
 
171 172
   def top_menu
172  
-    menu_link(menu_icon(:bottom, '8') + h('menu'), '#bottom', accesskey('8'))
  173
+    menu = menu_link(menu_icon(:bottom, '8') + h('menu'), '#bottom', accesskey('8'))
  174
+    if auth and auth.oauth?
  175
+      icon_tag(:shield) + ' ' + menu
  176
+    else
  177
+      menu
  178
+    end
173 179
   end
174 180
 
175 181
   def common_menu(*arg)
13  app/models/user.rb
@@ -15,7 +15,12 @@ def validate(name, remote_key)
15 15
         if ff_client.validate(name, remote_key)
16 16
           ActiveRecord::Base.transaction do
17 17
             if user = User.find_by_name(name)
18  
-              user.store_remote_key(remote_key)
  18
+              if user.oauth? and ff_client.oauth_validate(user.new_cred)
  19
+                # reusable OAuth access token found. just use it.
  20
+              else
  21
+                # store remote_key in DB.
  22
+                user.store_remote_key(remote_key)
  23
+              end
19 24
             else
20 25
               user = User.new
21 26
               user.name = name
@@ -89,8 +94,12 @@ def ff_client
89 94
     end
90 95
   end
91 96
 
  97
+  def oauth?
  98
+    !!self.oauth_access_token
  99
+  end
  100
+
92 101
   def new_cred
93  
-    if self.oauth_access_token
  102
+    if oauth?
94 103
       {
95 104
         :name => self.name,
96 105
         :oauth_token => self.oauth_access_token,
2  app/views/entry/new.html.erb
@@ -7,7 +7,7 @@
7 7
     Link: <%= text_field_tag('link', @link) %><br />
8 8
     <%= hidden_field_tag('with_form', @with_form) %>
9 9
     <%- if @with_form -%>
10  
-      image upload: <%= file_field_tag('file', @file) %><br />
  10
+      image upload: <%= file_field_tag('file') %><br />
11 11
     <%- else -%>
12 12
       <%= link_to(h('image upload'), :action => 'new', :with_form => '1') %><br />
13 13
     <%- end -%>
13  lib/ff.rb
@@ -579,6 +579,19 @@ def validate(name, remote_key)
579 579
       res.status == 200
580 580
     end
581 581
 
  582
+    # validate OAuth credential
  583
+    def oauth_validate(opt)
  584
+      uri = uri("feedlist")
  585
+      return false unless uri
  586
+      cred = get_credential(opt)
  587
+      return false unless cred.first == :oauth
  588
+      uri.scheme = 'http'
  589
+      uri = uri.to_s
  590
+      token = create_access_token(cred[1])
  591
+      res = token.get(uri)
  592
+      res.code.to_i == 200 # Net::HTTP returns in String
  593
+    end
  594
+
582 595
     # Reading data from FriendFeed
583 596
     def feed(fid, opt = {})
584 597
       uri = uri("feed/#{fid}")
2  lib/ff_daemon.rb
@@ -94,6 +94,7 @@ class APIV2ClientProxy
94 94
     extend ClientProxy
95 95
 
96 96
     define_proxy_method :validate
  97
+    define_proxy_method :oauth_validate
97 98
     define_proxy_method :feed
98 99
     define_proxy_method :search
99 100
     define_proxy_method :feedlist
@@ -397,6 +398,7 @@ class APIV2Daemon
397 398
     attr_reader :client
398 399
 
399 400
     define_proxy_method :validate
  401
+    define_proxy_method :oauth_validate
400 402
     define_proxy_method :feed
401 403
     define_proxy_method :search
402 404
     define_proxy_method :feedlist

0 notes on commit a83c0b1

Please sign in to comment.
Something went wrong with that request. Please try again.