Created
February 4, 2012 07:03
-
-
Save mokevnin/1735981 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "errors" | |
| class GoogleService | |
| private_class_method :new | |
| class << self | |
| def register(data_hash) | |
| data = AuthData.new(data_hash) | |
| auth = User::Google.find_by_uid(data.uid) | |
| if auth | |
| raise UserBlockedError if auth.user.blocked? | |
| return auth.user | |
| end | |
| if user = User.find_by_email(data.email) | |
| raise UserBlockedError if user.blocked? | |
| else | |
| user = UserGoogleRegistrationType.new | |
| user.password = SecureApp.generate_password | |
| end | |
| UserPopulator.via_google(user, data) | |
| user.active? ? user.save! : user.activate! | |
| user | |
| end | |
| def create_link(user, data_hash) | |
| data = AuthData.new(data_hash) | |
| auth = User::Google.find_by_uid(data.uid) | |
| raise AlreadyLinkedError if auth && auth.user == user | |
| if auth && auth.user != user | |
| raise UserBlockedError if auth.user.blocked? | |
| auth.destroy | |
| user.google.destroy if user.google | |
| end | |
| UserPopulator.via_google(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