Created
May 16, 2018 13:33
-
-
Save aguestuser/541ef99a90aa405036da21a7e6fd8092 to your computer and use it in GitHub Desktop.
OAuth Signup Handler sketch for affinity.works
This file contains 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
module OAuthSignupHandlers | |
extend ActiveSupport::Concern | |
def classify_person | |
if @person = Person.find_by_email(@auth.info.email) | |
classify_existing_person | |
elsif @person = Person.build_from_oauth_signup(@auth) | |
NewMember | |
else | |
Invalid | |
end | |
end | |
def classify_existing_person | |
return AlreadyMember if @person.is_member_of? current_group | |
return InfoNeeded if @person.missing_contact_info? | |
return NoInfoNeeded if @person.missing_contact_info? | |
end | |
module NewMember | |
def self.handle | |
# handle new member | |
end | |
end | |
module AlreadyMember | |
def self.handle | |
# handle already member | |
end | |
end | |
module InfoNeeded | |
def self.handle | |
# handle info neeeded | |
end | |
end | |
module NoInfoNeeded | |
def self.handle | |
# handle no info neeeded | |
end | |
end | |
module Invalid | |
def self.handle | |
# handle invalid | |
end | |
end | |
end | |
### USAGE: | |
# omniauth_callbacks_controller.rb | |
class People::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
include OAuthSingupHandlers | |
# lots of stuff omitted | |
def signup | |
classify_person.handle | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment