Created
August 30, 2013 16:36
-
-
Save vaughankg/6391775 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
| 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