Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

basic migrations, for demo purposes. and installation

  • Loading branch information...
commit 437ca0667624d9e1c09a2ba7d590a52683cb172d 1 parent 209d64a
@lancejpollard authored
View
2  .gitignore
@@ -1,5 +1,5 @@
.DS_Store
-pkg/**/*
+pkg
doc/**/*
*.tgz
*.gem
View
26 README.markdown
@@ -50,33 +50,13 @@ Now add the gem dependencies in your config:
config.gem "authlogic"
config.gem "oauth"
config.gem "oauth2"
- config.gem "authlogic-connect"
+ config.gem "authlogic-connect", :lib => "authlogic_connect"
### 3. Add the Migrations
-If you are starting from scratch (and you don't even have a User model yet), create these migrations.
+If you are starting from scratch (and you don't even have a User model yet), create the migrations using this command.
- class CreateAuthlogicConnectMigration < ActiveRecord::Migration
- def self.up
- add_column :users, :oauth_token, :string
- add_column :users, :oauth_secret, :string
- add_index :users, :oauth_token
-
- change_column :users, :login, :string, :default => nil, :null => true
- change_column :users, :crypted_password, :string, :default => nil, :null => true
- change_column :users, :password_salt, :string, :default => nil, :null => true
- end
-
- def self.down
- remove_column :users, :oauth_token
- remove_column :users, :oauth_secret
-
- [:login, :crypted_password, :password_salt].each do |field|
- User.all(:conditions => "#{field} is NULL").each { |user| user.update_attribute(field, "") if user.send(field).nil? }
- change_column :users, field, :string, :default => "", :null => false
- end
- end
- end
+ script/generate authlogic_connect_migration
Otherwise, add this migration
View
4 Rakefile
@@ -16,8 +16,8 @@ spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.files = %w(README.markdown Rakefile init.rb MIT-LICENSE) + Dir["{lib,rails,test}/**/*"] - Dir["test/tmp"]
s.require_path = "lib"
- s.add_dependency("activesupport", ">= 2.3.5")
- s.add_dependency("activerecord", ">= 2.3.5")
+ s.add_dependency("activesupport", ">= 2.1.2")
+ s.add_dependency("activerecord", ">= 2.1.2")
s.add_dependency("authlogic")
s.add_dependency("oauth")
s.add_dependency("json")
View
9 generators/authlogic_connect_migration/authlogic_connect_migration.rb
@@ -0,0 +1,9 @@
+class AuthlogicConnectMigrationGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.migration_template 'migration.rb', 'db/create_users', :migration_file_name => "create_users"
+ m.migration_template 'migration.rb', 'db/create_sessions', :migration_file_name => "create_sessions"
+ m.migration_template 'migration.rb', 'db/create_tokens', :migration_file_name => "create_tokens"
+ end
+ end
+end
View
16 generators/authlogic_connect_migration/templates/create_sessions.rb
@@ -0,0 +1,16 @@
+class CreateSessions < ActiveRecord::Migration
+ def self.up
+ create_table :sessions do |t|
+ t.string :session_id, :null => false
+ t.text :data
+ t.timestamps
+ end
+
+ add_index :sessions, :session_id
+ add_index :sessions, :updated_at
+ end
+
+ def self.down
+ drop_table :sessions
+ end
+end
View
18 generators/authlogic_connect_migration/templates/create_tokens.rb
@@ -0,0 +1,18 @@
+class CreateTokens < ActiveRecord::Migration
+ def self.up
+ create_table :tokens do |t|
+ t.integer :user_id
+ t.string :type, :limit => 30
+ t.string :key, :limit => 1024 # This has to be huge because of Yahoo's excessively large tokens
+ t.string :secret
+ t.boolean :active # whether or not it's associated with the account
+ t.timestamps
+ end
+
+ add_index :tokens, :key, :unique
+ end
+
+ def self.down
+ drop_table :tokens
+ end
+end
View
30 generators/authlogic_connect_migration/templates/create_users.rb
@@ -0,0 +1,30 @@
+class CreateUsers < ActiveRecord::Migration
+ def self.up
+ create_table :users do |t|
+ # authlogic
+ t.timestamps
+ t.string :login, :null => false
+ t.string :crypted_password, :null => false
+ t.string :password_salt, :null => false
+ t.string :persistence_token, :null => false
+ t.integer :login_count, :default => 0, :null => false
+ t.datetime :last_request_at
+ t.datetime :last_login_at
+ t.datetime :current_login_at
+ t.string :last_login_ip
+ t.string :current_login_ip
+ # authlogic-connect
+ t.string :openid_identifier # should be a token, later...
+ t.integer :active_token_id
+ end
+
+ add_index :users, :login
+ add_index :users, :persistence_token
+ add_index :users, :last_request_at
+ add_index :users, :active_token_id
+ end
+
+ def self.down
+ drop_table :users
+ end
+end
View
1  lib/authlogic_connect/oauth.rb
@@ -1,7 +1,6 @@
module AuthlogicConnect::Oauth
end
-require File.dirname(__FILE__) + "/oauth/version"
require File.dirname(__FILE__) + "/oauth/process"
require File.dirname(__FILE__) + "/oauth/user"
require File.dirname(__FILE__) + "/oauth/session"
View
2  lib/authlogic_connect/oauth/tokens/oauth_token.rb
@@ -1,4 +1,4 @@
-class OauthToken < AuthToken
+class OauthToken < Token
# Main client for interfacing with remote service. Override this to use
# preexisting library eg. Twitter gem.
View
6 lib/authlogic_connect/oauth/user.rb
@@ -11,8 +11,8 @@ module InstanceMethods
# Set up some simple validations
def self.included(base)
base.class_eval do
- has_many :tokens, :class_name => "AuthToken", :dependent => :destroy
- belongs_to :active_token, :class_name => "AuthToken", :dependent => :destroy
+ has_many :tokens, :class_name => "Token", :dependent => :destroy
+ belongs_to :active_token, :class_name => "Token", :dependent => :destroy
accepts_nested_attributes_for :tokens, :active_token
validate :validate_by_oauth, :if => :authenticating_with_oauth?
@@ -68,7 +68,7 @@ def authenticate_with_oauth
# Restore any attributes which were saved before redirecting to the oauth server
self.attributes = auth_session.delete(:authlogic_oauth_attributes)
token = AuthlogicConnect.token(oauth_provider).new(oauth_key_and_secret)
- if AuthToken.find_by_key(token.key)
+ if Token.find_by_key(token.key)
self.errors.add("you have already created an account using your #{oauth_token.service_name} account, so it")
else
self.tokens << token
View
2  lib/authlogic_connect/openid/tokens/openid_token.rb
@@ -1,3 +1,3 @@
-class OpenidToken < AuthToken
+class OpenidToken < Token
end
View
2  lib/auth_token.rb → lib/token.rb
@@ -1,4 +1,4 @@
-class AuthToken < ActiveRecord::Base
+class Token < ActiveRecord::Base
belongs_to :user
validates_presence_of :key, :secret
Please sign in to comment.
Something went wrong with that request. Please try again.