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