Permalink
Browse files

Create a user model (subclassed from Omniauth::User) in the applicati…

…on's directory and use that as the model that the LoginAccounts look up. This enables the app developers to customise their users.
  • Loading branch information...
1 parent 94079bf commit 8dc0ce996c78e46bd38d585efb184c1b3a73b1d6 @timriley timriley committed Oct 10, 2010
View
4 app/models/omnisocial/login_account.rb
@@ -1,6 +1,6 @@
module Omnisocial
class LoginAccount < ActiveRecord::Base
- belongs_to :user, :class_name => 'Omnisocial::User'
+ belongs_to :user
def self.find_or_create_from_auth_hash(auth_hash)
if (account = find_by_remote_account_id(auth_hash['uid']))
@@ -21,7 +21,7 @@ def self.create_from_auth_hash(auth_hash)
def find_or_create_user
return self.user if self.user
- Omnisocial::User.create do |user|
+ ::User.create do |user|
user.login_account = self
end
end
View
1 app/models/omnisocial/twitter_account.rb
@@ -1,7 +1,6 @@
module Omnisocial
class TwitterAccount < LoginAccount
def assign_account_info(auth_hash)
- p auth_hash
self.remote_account_id = auth_hash['uid']
self.login = auth_hash['user_info']['nickname']
self.picture_url = auth_hash['user_info']['image']
View
4 lib/extensions/action_controller/base.rb
@@ -32,9 +32,9 @@ def redirect_back_or_default(default)
def current_user
@current_user ||= if session[:user_id]
- Omnisocial::User.find(session[:user_id])
+ User.find(session[:user_id])
elsif cookies[:remember_token]
- Omnisocial::User.find_by_remember_token(cookies[:remember_token])
+ User.find_by_remember_token(cookies[:remember_token])
else
false
end
View
4 lib/generators/omnisocial/omnisocial_generator.rb
@@ -30,6 +30,10 @@ def copy_initializer
template 'omnisocial.rb', 'config/initializers/omnisocial.rb'
end
+ def copy_user_model
+ template 'user.rb', 'app/models/user.rb'
+ end
+
def copy_assets
copy_file 'assets/stylesheets/omnisocial.css', 'public/stylesheets/omnisocial.css'
copy_file 'assets/images/twitter.gif', 'public/images/omnisocial/twitter.gif'
View
3 lib/generators/omnisocial/templates/user.rb
@@ -0,0 +1,3 @@
+class User < Omnisocial::User
+ # Make any customisations here
+end

0 comments on commit 8dc0ce9

Please sign in to comment.