Skip to content

Instantly share code, notes, and snippets.

@vaughankg
Created August 30, 2013 16:36
Show Gist options
  • Save vaughankg/6391775 to your computer and use it in GitHub Desktop.
Save vaughankg/6391775 to your computer and use it in GitHub Desktop.
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
@identity = Identity.find_with_omniauth(auth)
if @identity.nil?
@identity = Identity.create_with_omniauth(auth)
end
if signed_in?
if @identity.user == current_user
redirect_to root_url, notice: "Already linked that account!"
else # User is attempting to associate another accoutn with this one
@identity.user = current_user
@identity.save
redirect_to root_url, notice: "Successfully linked that account"
end
else # User is not signed in
unless @identity.user.present?
@identity.user = User.create
@identity.save
end
self.current_user = @identity.user
redirect_to root_url, notice: "Signed in"
end
end
def destroy
current_user = nil
redirect_to root_url, notice: "Signed out"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment