Skip to content

Instantly share code, notes, and snippets.

@mokevnin
Created February 4, 2012 07:04
Show Gist options
  • Save mokevnin/1735986 to your computer and use it in GitHub Desktop.
Save mokevnin/1735986 to your computer and use it in GitHub Desktop.
require "errors"
class FacebookService
class << self
def register(data_hash)
data = AuthData.new(data_hash)
auth = User::Facebook.find_by_uid(data.uid)
if auth
raise UserBlockedError if auth.user.blocked?
auth.user.activate! unless auth.user.active?
return auth.user
end
if user = User.find_by_email(data.email)
raise UserBlockedError if user.blocked?
raise ConfirmationRequiredError.new(user) if user.active?
else
user = UserFacebookRegistrationType.new
user.password = SecureApp.generate_password
end
user.build_facebook :uid => data.uid
UserPopulator.via_facebook(user, data)
user.activate!
user
end
def create_link(user, data_hash)
data = AuthData.new(data_hash)
auth = User::Facebook.find_by_uid(data.uid)
if auth
if auth.user.id == user.id
raise AlreadyLinkedError auth.user.id == user.id
else
auth.destroy
end
end
user.build_facebook :uid => data.uid
UserPopulator.via_facebook(user, data)
user.save!
true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment