github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

mbleigh / twitter-auth

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 323
    • 30
  • Source
  • Commits
  • Network (30)
  • Issues (13)
  • Downloads (20)
  • Wiki (3)
  • Graphs
  • Tree: b64af96

click here to add a description

click here to add a homepage

  • Branches (5)
    • 1.0_dev
    • gh-pages
    • legacy
    • master
    • twitterdispatch
  • Tags (20)
    • v0.1.22
    • v0.1.21
    • v0.1.20
    • v0.1.18
    • v0.1.17
    • v0.1.16
    • v0.1.15
    • v0.1.14
    • v0.1.13
    • v0.1.12
    • v0.1.11
    • v0.1.10
    • v0.1.9
    • v0.1.8
    • v0.1.7
    • v0.1.5
    • v0.1.3
    • v0.1.1
    • v0.0.2
    • v0.0.1
Sending Request…
Click here to lend your support to: twitter-auth and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Standard authentication stack for Rails using Twitter to log in. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Allow overriding of default validations of GenericUser. 
mbleigh (author)
Fri May 29 09:20:14 -0700 2009
commit  b64af9689ea4a5c0d1695f5ef15131cdcb69fb64
tree    27abc7b59524fe97acb10602fa69d3e1c885f553
parent  40cd6896371575e9ce5171fdd4692e169d9cdd53
twitter-auth / app / models / twitter_auth / generic_user.rb app/models/twitter_auth/generic_user.rb
100644 104 lines (84 sloc) 2.83 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module TwitterAuth
  class GenericUser < ActiveRecord::Base
    attr_protected :twitter_id, :remember_token, :remember_token_expires_at
    
    TWITTER_ATTRIBUTES = [
      :name,
      :location,
      :description,
      :profile_image_url,
      :url,
      :protected,
      :profile_background_color,
      :profile_sidebar_fill_color,
      :profile_link_color,
      :profile_sidebar_border_color,
      :profile_text_color,
      :profile_background_image_url,
      :profile_background_tile,
      :friends_count,
      :statuses_count,
      :followers_count,
      :favourites_count,
      :time_zone,
      :utc_offset
    ]
    
    with_options :if => :utilize_default_validations do |v|
      v.validates_presence_of :login, :twitter_id
      v.validates_format_of :login, :with => /\A[a-z0-9_]+\z/i
      v.validates_length_of :login, :in => 1..15
      v.validates_uniqueness_of :login, :case_sensitive => false
      v.validates_uniqueness_of :twitter_id, :message => "ID has already been taken."
      v.validates_uniqueness_of :remember_token, :allow_blank => true
    end
    
    def self.table_name; 'users' end
 
    def self.new_from_twitter_hash(hash)
      raise ArgumentError, 'Invalid hash: must include screen_name.' unless hash.key?('screen_name')
 
      raise ArgumentError, 'Invalid hash: must include id.' unless hash.key?('id')
 
      user = User.new
      user.twitter_id = hash['id'].to_s
      user.login = hash['screen_name']
 
      TWITTER_ATTRIBUTES.each do |att|
        user.send("#{att}=", hash[att.to_s]) if user.respond_to?("#{att}=")
      end
 
      user
    end
 
    def self.from_remember_token(token)
      first(:conditions => ["remember_token = ? AND remember_token_expires_at > ?", token, Time.now])
    end
      
    def assign_twitter_attributes(hash)
      TWITTER_ATTRIBUTES.each do |att|
        send("#{att}=", hash[att.to_s]) if respond_to?("#{att}=")
      end
    end
 
    def update_twitter_attributes(hash)
      assign_twitter_attributes(hash)
      save
    end
 
    if TwitterAuth.oauth?
      include TwitterAuth::OauthUser
    else
      include TwitterAuth::BasicUser
    end
 
    def utilize_default_validations
      true
    end
 
    def twitter
      if TwitterAuth.oauth?
        TwitterAuth::Dispatcher::Oauth.new(self)
      else
        TwitterAuth::Dispatcher::Basic.new(self)
      end
    end
 
    def remember_me
      return false unless respond_to?(:remember_token)
 
      self.remember_token = ActiveSupport::SecureRandom.hex(10)
      self.remember_token_expires_at = Time.now + TwitterAuth.remember_for.days
      
      save
 
      {:value => self.remember_token, :expires => self.remember_token_expires_at}
    end
 
    def forget_me
      self.remember_token = self.remember_token_expires_at = nil
      self.save
    end
  end
end
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server